MyTitle MyTitle - 1 month ago 20
Java Question

Servlet getRequestDispatcher.forward() work's unclear

I have 2 servlets, there they mapping inside

web.xml
:

<url-pattern>/archiving/archive</url-pattern>
<url-pattern>/archiving/reportgenerator</url-pattern>


From servlet
archive
I call second servlet:

request.getRequestDispatcher("/reportgenerator").forward(request, response);


But there error:

NOT_FOUND
RequestURI=/reportgenerator


It seems like in URL we lost "/archiving" before "/reportgenerator".

But if I add "/archiving" in
reaquestDispatcher
:

request.getRequestDispatcher("/archiving/reportgenerator").forward(request, response);


Then I get this error:

NOT_FOUND
RequestURI=/archiving/archiving/reportgenerator


Why servlet duplicate "/archiving" path in 2nd case, but don't paste it in first?

Answer

change this line

request.getRequestDispatcher("/archiving/reportgenerator").forward(request, response);

to

request.getRequestDispatcher("../archiving/reportgenerator").forward(request, response);

and see if this helps.