Search code examples
javajspservletsguiceguice-servlet

Forwarding request to a JSP


I discovered Guice last week... I'm trying some easy tricks with it. However, I'm currently blocked...

I'm trying to forward a request to a JSP in a Servlet served by an url-pattern which contains a " * ". But I receive "Error 404" all the time :(

Step by Step :


ServletModule :
serve("/test/*").with(TestServlet.class);

TestServlet :
public void doGet(HttpServletRequest req, HttpServletResponse resp)  
{

    System.err.println("Start");
    try 
    {
        req.getRequestDispatcher("/WEB-INF/layout/test.jsp").forward(req, resp);
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }

}

I get this error :

HTTP ERROR 404
Problem accessing /WEB-INF/layout/test.jsp. Reason:
/WEB-INF/layout/test.jsp

I tested with "serve("/test").with(TestServlet.class);" and it worked
I tested without Guice (by defining servlet in the web.xml) and it worked...

  • What did I do wrong?

Thank for reading!


Solution

  • Client can't access resources from Web-INF directly (by url). So forwarding doesn't work in this case. But your servlets can. So just use include instead of forward.