Walter Lee

Do not use ".." in jsp include in Sun Java Web Server

Thursday Jun 26, 2008

This can often lead to errors in Sun Java Web server 6.1 and 7.0, so do not use ".." in jsp include.


Instead use e.g. ServletContext context-relative paths , as mentioned in JSP spec.


 e.g. Avoid below:



1. <jsp:include page="./../result1.jsp"> , 
2. <%@ include file="./../result2.jsp" %> ,
3. <%@ page errorPage="./../result3.jsp" %> ,

becasuse above will often lead to server errors in 6.1SPx and 7.0ux (only #2 above will run ok in 7.0u2 , but it  does not mean this is  a  good idea to do so).


One reason is ".." may not mean the same thing in all OSs. So, this type of war file may work in one OS , but not in another OS later.


 It is better to use ServletContext context-relative paths, e.g. when I deployed my war file as /simple,


my file structure is

apple:/export/home/iws6.1sp9/https-jsp/webapps/https-jsp/simple/jsp> ls
SMPL        checkbox    error       index.html  num         sessions    source.jsp
SMPLorg     colors      forward     jsptoserv   plugin      simpletag
cal         dates       include     mail        security    snp



apple:/export/home/iws6.1sp9/https-jsp/webapps/https-jsp/simple/jsp> ls -R SMPL
SMPL:
SMPL2        result1.jsp  result2.jsp  result3.jsp

SMPL/SMPL2:
sample01.jsp  sample02.jsp  sample03.jsp


 apple:/export/home/iws6.1sp9/https-jsp/webapps/https-jsp/simple/jsp/SMPL/SMPL2> vi sample01.jsp

<HTML>
    <BODY>
        <%@ page contentType="text/html; charset=Windows-31J" %>
        <jsp:include page="/jsp/SMPL/result1.jsp" flush="true" />
    </BODY>
</HTML>


same for


      <%@ include file="/jsp/SMPL/result2.jsp" %>


and


        <%@ page contentType="text/html; charset=Windows-31J"
        errorPage="/jsp/SMPL/result3.jsp"%>


then they will all run ok in my web server 6.1SP9 and 7.0u2 properly when I deploy this war file in different OS 

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg