I'm using MVC and want to put my JSP pages in WEB-INF to avoid direct access to it. I have an index.jsp page and other pages in jsp folder in Web Content and it works. It looks like this:
-Web Content
-index.jsp
-jsp
--main_read.jsp
--...
By the way, index.jsp is my login page and whether user is logged, in controller I use
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("jsp/main_read.jsp");
dispatcher.forward(request, response);
I works perfect, but when I'm trying to put my JSP in WEB-INF it fails:
-Web Content
-index.jsp
-WEB-INF
--jsp
---jsp
----main_read.jsp
----...
And gives an error like this
HTTP Status 404 - /Libruary/jsp/main_read.jsp
type Status report
message /Libruary/jsp/main_read.jsp
description The requested resource (/Libruary/jsp/main_read.jsp) is not available.
Apache Tomcat/6.0.26
Probably the problem is in the page path, I write in dispatcher.forward
, but anyway, help me please.
You seem to pass the path /jsp/main_read.jsp
, and the JSP is in /WEB-INF/jsp/jsp/main_read.jsp
. Obviously, the paths don't match. Pass the correct path to getRequestDispatcher()
: /WEB-INF/jsp/jsp/main_read.jsp
.
The javadoc says:
The pathname must begin with a / and is interpreted as relative to the current context root