如何修复 Struts DispatchAction 上的 StackOverflowError?
情况是这样的: 我练习创建一个迷你博客应用程序。 我使用 Strut 的 EventDispatchAction 来处理所有与帖子相关的方法,例如更新和列出帖子。
我有一个 update() 方法(http://mywebsite/post?update),它更新数据库,然后如果成功,它会转发到同一个操作类,但我使用了不同的方法来处理它,即 list() 方法(http: //mywebsite/post?list) 列出当前用户的所有帖子。 问题是它不起作用并抛出:
javax.servlet.ServletException:
HTTP 的服务器端组件 监视器检测到 java.lang.StackOverflowError。 这 当存在无限循环时发生 在网络模块中。 纠正原因 运行前的无限循环 再次访问网络模块。
你们知道如何解决这个问题吗? 任何帮助将不胜感激!
编辑:我解决了,伙计们。 我只需要在我的转发参数中添加值,在我的情况下我必须这样做:post?list=list 而不是只是 post?list (正常方式)。 我猜如果该方法没有值,它就会被忽略。 Struts 的行为为何如此,真的很奇怪。 也许有人可以阐明这一点?
Here's the situation:
I practiced creating a mini blog application. I used Strut's EventDispatchAction to handle all post related methods like updating and listing posts.
I have an update() method (http://mywebsite/post?update) that updates the database and then if it's successful it forwards to the same action class but I used a different method to handle it, the list() method (http://mywebsite/post?list) which lists all the posts of the current user. The problem is it doesn't work and throws up a:
javax.servlet.ServletException:
The server side component of the HTTP
Monitor has detected a
java.lang.StackOverflowError. This
happens when there is an infinite loop
in the web module. Correct the cause
of the infinite loop before running
the web module again.
Do you guys have any idea on how to fix this? Any help would be greatly appreciated!
EDIT: I solved it guys. I just need to put value in the parameter of my forward, in my case I have to do: post?list=list instead of just post?list (the normal way). The method is ignored I guess if it doesn't have a value. It's really weird why Struts is behaving like this. Maybe someone can shed some light on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是否没有更多异常信息,例如堆栈跟踪?
您是否有
list()
方法的单元测试? 堆栈溢出几乎总是由递归方法(或方法循环)引起的,但如果没有有关堆栈跟踪的更多信息,则很难进一步诊断它。如果抛出异常后无法获得完整的堆栈跟踪,您可能需要向
list()
及其调用的方法添加更多日志记录,以显示递归发生的位置。编辑:好的,查看堆栈跟踪,看起来您有一个操作转发到其自身,或者转发到另一个操作,该操作转发回第一个操作。 看起来您的代码没有涉及,因为它没有出现在堆栈跟踪中。 检查您的 Struts 配置是否有循环。
堆栈跟踪的另一个有趣的部分是“org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter” - 该应用程序是否在您的 IDE 中运行? 如果您不在 IDE 中运行它,它仍然会失败吗?
Is there no more exception information, like a stack trace?
Do you have unit tests for the
list()
method? A stack overflow is almost always caused by a recursive method (or cycle of methods) but without any more information about the stack trace, it's very hard to diagnose it further.If you can't get a full stack trace after the exception has been thrown, you might want to add more logging into
list()
and the methods it calls, to show you where the recursion is occurring.EDIT: Okay, looking at the stack trace it looks like you've got one action forwarding either to itself, or to another action which forwards back to the first one. It looks like your code isn't involved, given that it doesn't appear in the stack trace. Check your Struts config for cycles.
The other interesting bit of the stack trace is "org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter" - is this application running in your IDE? Does it still fail if you run it not in the IDE?