I am using Jetty. My default servlet is making a simple forward to an HTML file in my WEB-INF
folder that is causing a java.lang.StackOverFlowError
error. The error is fixed if I rename the file I am forwarding from a .html
to .jsp
DefaultServlet.java
public class DefaultServlet extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException{
req.getRequestDispatcher("WEB-INF/home.html").forward(req, resp);
}
}
web.xml
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>Default</servlet-name>
<servlet-class>DefaultServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
My guess is that instead of inserting the html content in the response body, the forward is sending the browser a redirect to /WEB-INF/home.html
. This again calls the DefaultServlet
and gets into an infinity loop. How can I prevent this?
Thanks.