I am trying to achieve URL-Rewriting for my Application. I am using java,servlet, JSP, tomcat 7 as part of the technologies.
BackGround: The reason for URL-Rewriting is that when my browser cookies are disabled the connection between the client and the server is not established and session on being lost and for each request that comes from the browser the server thinks as a new request.
By reading through the internet found that URL-Rewriting is one solution.
My application has just one JSP page called root.jsp
This is how i am loading the jsp page from my servlet. I have only one servlet that handles all the request.
getServletContext().getRequestDispatcher("/view/root.jsp").forward(
request, response);
In root.jsp
includes another jsp pages as a part of root.jsp
it shown below. Based on the programming logic the respective JSP page that needs to be included get added.
<div class="grey_container">
<jsp:include page="${requestScope.jspPage.pageFileUrl}" flush="false" />
</div>
I read that the URL-rewriting is possible using HttpServletResponse encodeURL() and encodeRedirectURL()
. For the JSP pages this encodeURL is achievied using <c:url>
WHat i have tried
In my servlet show below, I did not see any Jsession ID being appended to the URL.
getServletContext().getRequestDispatcher(response.encodeURL("/view/root.jsp")).forward(
request, response);
getServletContext().getRequestDispatcher(response.encodeRedirectURL("/view/root.jsp")).forward(
request, response);
Next thought that i might need to configure something similar in JSP using <c:url>
tag. So tried to configure in the <jsp: include>
but it is throwing some compilation exception. so at this point of time i tried different approaches to make that JSP compilation error go away but was not successful. So thought that is it possible configure to <jsp: include>
to have <c:url>
was not sure. configuring in JSP with <c:url>
is needed?
Below is the exception when i try to configure the
<jsp:include page="<c:url value="${requestScope.jspPage.pageFileUrl}"/>" flush="false" />
org.apache.jasper.JasperException: /view/root.jsp (line: 97, column: 38) Unterminated <jsp:include tag
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:133)
at org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:992)
at org.apache.jasper.compiler.Parser.parseInclude(Parser.java:854)
at org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1116)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1451)
at org.apache.jasper.compiler.Parser.parse(Parser.java:138)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
How should i configure my servlet/JSP page for the URL rewriting?