Google App Engine: Only local server creates infinite loop when forwarding to JSP

202 Views Asked by At

my Google App Engine project has all requests being handled by a servlet, which at the end forwards to the appropriate JSP:

RequestDispatcher rd = mServletContext.getRequestDispatcher("/views/" + pViewName + ".jsp");
rd.forward(mRequest, mResponse);

This works all fine online on the Google App Engine. But when I use the local server from the Google App Engine SDK (with "dev_appserver.cmd"), an infinite loop is created. I can see that the forward gets handled again by my servlet. This does not happen online.

My web.xml:

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
    <servlet>
        <servlet-name>HtmlStarterServlet</servlet-name>
        <servlet-class>com.kupkik.ui.html.HtmlStarterServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>HtmlStarterServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

My project is a Maven-project (created with using the skeleton-archetype). My project structure looks like this:

  • src
    • main
      • java
        • com.kupkik.ui.html.HtmlStarterServlet
      • webapp
        • views
          • test.jsp
      • WEB-INF
    • test

HtmlStarterServlet:

@SuppressWarnings("serial")
public class HtmlStarterServlet
    extends HttpServlet
{
    @Override
    public void doGet(HttpServletRequest r,HttpServletResponse rs) throws IOException
    {
        String t = r.getRequestURI();
        System.out.println("test: " + t);
        RequestDispatcher rd = getServletContext().getRequestDispatcher("/views/test.jsp");
        try
        {
            rd.forward(r, rs);
        }
            catch( ServletException e )
        {
            System.out.println("ex");
        }
    }
}

Output on console, when running development server in debug mode:

test: /
test: /views/test.jsp
test: /views/test.jsp
test: /views/test.jsp
... (and so on)

So my question is: Why is there a different behavior between the local server from the SDK and the online GAE? And does someone know how to fix the problem, so that it works on both?

I want all requests to be handled by one servlet, which chooses the JSP to show.

1

There are 1 best solutions below

1
On

Use Chrome devtools, network tab to see what URLs are in the infinite loop.

Try creating a hosts entry in %SystemRoot%\system32\drivers\etc\hosts, eg.devserver.example.com 127.0.0.1 and use that in place of "localhost"