Reputation: 51
I'm working on a small web application that contains some JSPs, Servlets and static HTML pages. There are also some filters to implement a small authentication/authorization mechanism. My questions are:
How can I map an entire directory of JSPs to another? Here's an example: I want to map all the URLs like localhost:8080/WebAppName/pages/*.jsp
to localhost:8080/WebAppName/*.jsp
. How can I do that without writing an entry in the web.xml for each JSPs page in the directory 'pages'?
After having mapped these URLs to new ones, what do I have to write in the tag of in the web.xml? The mapped URL (WebAppName/*.jsp
) or the real one (WebAppName/pages/*.jsp
)?
Thanks in advance.
Upvotes: 0
Views: 114
Reputation: 109547
You could make a servlet - or JSP - that has a mapping *.xhtml
(other extension). Using the request URI it can do a dynamic include of the corresponding JSP from pages
.
In servlet:
String pagesPath = "pages/" + ...;
request.getServletContext(pagesPath).getRequestDispatcher().include(request,
response);
I doubt it is a good idea, as it does not add something: you might even need to adapt all JSPs (other extension). Or rename the JSPs to .jspf
.
In general I use JSPs under WEB-INF/jsp or so; so they are not publicly accessible. And use a similar technique: creating a model in the servlet, and then to the view as JSP.
Upvotes: 2