AppEngine Development Server gives StackOverflowError in JSP

你说的曾经没有我的故事 提交于 2019-12-11 02:41:23

问题


I'm using the following code in a JSP file which I serve from an AppEngine serlvet.

<script type="text/javascript" >
    var role = <%= request.getAttribute("role") %>;
</script>

The variable is set from a Servlet using:

req.setAttribute("role", role );
req.getRequestDispatcher("index.jsp").forward(req, resp);

The code runs fine on AppEngine production but in the local development server I get the following straight away:

Problem accessing /. Reason:

INTERNAL_SERVER_ERROR
Caused by:

java.lang.StackOverflowError
at org.mortbay.jetty.servlet.Dispatcher$ForwardAttributes.setAttribute(Dispatcher.java:438)
at org.mortbay.jetty.servlet.Dispatcher$ForwardAttributes.setAttribute(Dispatcher.java:438)
at org.mortbay.jetty.servlet.Dispatcher$ForwardAttributes.setAttribute(Dispatcher.java:438)
at org.mortbay.jetty.servlet.Dispatcher$ForwardAttributes.setAttribute(Dispatcher.java:438)
at org.mortbay.jetty.servlet.Dispatcher$ForwardAttributes.setAttribute(Dispatcher.java:438)
at org.mortbay.jetty.servlet.Dispatcher$ForwardAttributes.setAttribute(Dispatcher.java:438)
at org.mortbay.jetty.servlet.Dispatcher$ForwardAttributes.setAttribute(Dispatcher.java:438)

this goes on like forever. While debugging, I can also see that the Servlet code is called endless times.

I found a few references to a similar problem with AppEngine production but found no workable fix for AppEngine development server.

Any idea ??


回答1:


I ran into a similar issue when forwarding to a JSP from a servlet using Google App Engine without even explicitly setting any variables, all I had was the line:

req.getRequestDispatcher("game.jsp").forward(req, resp);

In my case it turned out to because in web.xml I had the following line (note the catch-all url-pattern:

<servlet-mapping>
    <servlet-name>GameServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

I think this was also catching the JSP path and therefore looping. When I change it too not be a catch-all it works. As in:

<servlet-mapping>
    <servlet-name>GameServlet</servlet-name>
    <url-pattern>/game</url-pattern>
</servlet-mapping>



回答2:


Are you sure you are setting the attribute in the response?

req.setAttribute("role", role );

It seems like you are setting it in the request that has come in to the servlet and not to the response you are sending out.



来源:https://stackoverflow.com/questions/11495170/appengine-development-server-gives-stackoverflowerror-in-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!