【问题标题】:How to fix java.lang.StackOverflowError when using s:action in JSP在 JSP 中使用 s:action 时如何修复 java.lang.StackOverflowError
【发布时间】:2014-03-18 10:23:59
【问题描述】:

我从我的数据库中加载城市和州。我在 JSP 中使用了以下代码:

<s:action executeResult="true" name="LoadCities"> </s:action>

它在初始页面加载期间运行良好,但在我更新数据库中的城市时出现问题。更新成功后,我重定向这个相同的页面。

但是这次我遇到了以下异常:

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.

2014-03-18 15:51:02,965 WARN  org.apache.struts2.components.Include.warn:49 -
Exception thrown during include of header.jsp 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.

我该如何解决这个问题?

【问题讨论】:

  • 使用&lt;s:action&gt;标签有什么好的理由吗?
  • 从数据库中加载组合框中的城市
  • 您可以使用&lt;s:action&gt;标签加载您的数据。
  • 您可以在execute() 方法中加载数据,或者,如果您需要在验证失败后填充数据,则在prepare() 方法中。
  • 我在执行方法中加载数据。

标签: java hibernate jsp struts2 stack-overflow


【解决方案1】:

发生这种情况是因为您正在执行一个映射到与s:action 标记一起使用的同一 JSP 的结果。使用s:action 标记时,您应该小心映射JSP。

实际上,您应该重新考虑 JSP 的设计,因为这个标签很少使用,而且在少数情况下可能适用于它。您可以使用唯一的一个操作在服务器端准备 JSP(也可以链接,但此处不推荐),但您可以在其中准备许多片段或切片。

因此,您要么不使用s:action 标记,要么将其与executeResult="false" 一起使用,或者选择上述方法之一来拆分JSP 页面的设计。

现在 Ajax 非常流行,它可以解决在客户端加载数据和更新内容的许多问题。所以你有很多可能做到这一点。

【讨论】:

  • 谢谢先生,我删除了我的jsp中的s:action标签,并使用迭代器在下拉列表中加载城市,现在它工作正常了。
猜你喜欢
  • 2019-09-27
  • 1970-01-01
  • 2019-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-26
  • 1970-01-01
  • 2010-11-03
相关资源
最近更新 更多