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-INF
folder. This also effectively hides JSPs away from direct access. You only need to change the RequestDispatcher#forward()
call to include /WEB-INF
in the path.
request.getRequestDispatcher("/WEB-INF/content" + request.getPathInfo()).forward(request, response);
Please note that the URL pattern of /content/*.jsp
is 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With