I have a number of Java Server Pages set up already and I would like to use a Controller/View system by adding a Process Servlet (which extends HttpServlet).
I just want to basically process the requested JSPs as normal after the ProcessServlet has added some attributes.
Say all my JSPs are in a directory called /content/ and my web.xml file has a rule to map /content/*.jsp to my ProcessServlet
I have not been able to find a way short of moving all of my JSPs into a different directory (/content-JSPs/) so that they can be dispatched to without having to go through the ProcessServlet endlessly.
Is there a way to basically dispatch#forward() (some other method?) to the requested JSP without having it go through the ProcessServlet again?
It’s a bit hard to believe that this lack of flexibility exists. Why can’t the Servlet just act as a pass through to the JSP?
My goal here is to set everything up so that the web server does not have to have a separate directory for all JSPs and another directory for everything else i.e. CSS, JavaScript and images. I would like to keep the directory structure (and URL structure) as it is.
Put them in
/WEB-INFfolder. This also effectively hides JSPs away from direct access. You only need to change theRequestDispatcher#forward()call to include/WEB-INFin the path.Please note that the URL pattern of
/content/*.jspis syntactically invalid. It should be/content/*. Perhaps you have also really used that. To skip static resources like images/css/JS, you should just not put them in/content, but in for example/resources,/static, etc.Related: