In a nutshell, I have a servlet that forwards a GET request to a JSP, and I would like to "hide" the target URL from the user.
My setup is as follows:
- A servlet, mapped to URL "www.mydomain.com/pages/page1"
- A JSP, at address "/WEB-INF/pages/page1.jsp", relative to the application root. The JSP resides in the WEB-INF directory, in order to not be accessible directly from the browser.
Upon access from the browser, the servlet pre-processes the incoming GET request, and forwards it to the JSP using the following code-snippet:
request.getRequestDispatcher("/WEB-INF/pages/page1.jsp").forward(request, response);
The desired behaviour is for the browser to maintain the URL "www.mydomain.com/pages/page1", while the user sees the contents of the JSP.
Unfortunately, the browser consistently switches to display the JSP's URL: "www.mydomain.com/WEB-INF/pages/page1.jsp" (Tested in Chrome and Firefox)
Can anyone tell me, what could be causing this behaviour?
Source: This solution is described in this CodeRanch answer, in which they are successful at "hiding" the address to the JSP: http://www.coderanch.com/t/618800/JSP/java/Url-hiding