How can I use Servlets to access the HTML uses of having JSP without having to have all my client-facing pages called *.jsp?
I would rather do this than using all the response.write() stuff because I think it is easier to read and maintain when it is all clean “HTML”.
Is this is fair assesment?
EDIT: What I’m going for is having the Servlets output things to the screen without having to redirect to a .jsp file.
In this way, I could write all the JSP stuff, but when it comes time to display it, the page the URL the user sees is essentially, “http://blah.com/posts/post-id” which is the address of the servlet and not “http://blah.com/posts.jsp?pos=post-id“.
But I would still write all presentation logic in an external .jsp.
Just hide the JSP away in
/WEB-INFfolder so that noone can access it directly and create a servlet which forwards the request to this JSP file. Don’t do a redirect, else you will see the new URL being reflected in the address bar. E.g.Map this servlet on an
url-patternof/posts/*.In the
/WEB-INF/posts.jspmake use of taglibs to control page flow and EL to access the data. E.g.Finally just invoke the servlet by
http://example.com/posts/postid. The/postidpart will be available byHttpServletRequest#getPathInfo(). You need to parse the value yourself and do the business thing with it.