0
votes

I have a problem and I don't know if it's a bug or I'm doing something wrong.

I have 2 servlets. Both are mapped in the ServletModule in my GuiceServletContextListener:

serve("/", "/index.jsp").with(MainEntryServlet.class);
serve("/foobar.jsp").with(FooBarServlet.class);

In my FooBarServlet I do the following:

String url = "/index.jsp?target=foo.jsp";
request.getRequestDispatcher(url).forward(request, response);

The MainEntryServlet gets called as expected, but the parameter target is missing in the request parameters. This only occurs when forwarding from one servlet to another. If I forward the request to a JSP everything works fine.

When I map the servlets in the web.xml instead of the ServletModule, the target parameter is not missing. So I guess that Guice is causing the problem. I'm using Tomcat 8 as servlet container.

Any idea how to fix this?

1

1 Answers

0
votes

It is probable that I did not get your question, but have you tried this ?

String url = "/index.jsp";
request.setAttribute("target", "foo.jsp")
request.getRequestDispatcher(url).forward(request, response);

To set a parameter to your response, you can use the setAttribute method.