2

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 ??

Saad Farooq
  • 13,172
  • 10
  • 68
  • 94

2 Answers2

4

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>
0

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.

user1258245
  • 3,639
  • 2
  • 18
  • 23
  • I've added the line for the way I use requestdispatcher to set the attribute in the JSP. As far as I know, this is correct. And it does work in AppEngine production – Saad Farooq Jul 16 '12 at 05:25
  • 1
    @SaadFarooq Yeah your right. Your code is fine. I'd double check your appengine-web.xml What I've seen is that sometimes the include or exclude definitions resolve differently deployed and locally and maybe the stackoverflow error results from the resource not being found similar to http://stackoverflow.com/questions/7026447/why-does-jspinclude-sometimes-cause-stackoverflowerrors-on-google-app-engine Then again .jsps should not be served as static files. What happens if you take the req.setAttribute("role", role ); out, does the page get served? – user1258245 Jul 16 '12 at 05:51
  • Yeah.. the page gets served if I take it out – Saad Farooq Jul 16 '12 at 05:55