relative and absolute paths in JSPsExcerpt from: http://blog.csdn.net/bluishglc/article/details/5346876
1. First identify two concepts:
Server path: Shape:http://192.168.0.1/ Path
Web application path: The path of Http://192.168.0.1/yourwebapp :
2. A description of the relative path and the absolute path:
In a servlet, "/" represents a directory of Web apps. and the relative representation of the physical path. For example : "./" represents the current directory, ". /"represents the parent directory. This similar representation also belongs to the relative path. This is consistent with how paths are expressed in Linux!
3. About the relative path and absolute path in Jsp/servlet.
3.1 Server-side address
The relative address of the server side refers to the address that is relative to your Web application, which is resolved on the server side (different from the relative addresses in HTML and JavaScript, which are parsed by the client browser), that is, the relative addresses in the JSP and servlet should be phase- For your web app, that is, relative to http://192.168.0.1/webapp/.
Where they are used are:
Request.getrequestdispatcher (address) in Forward:servlet, this address is parsed on the server side, so you forward to a.jsp should write: Request.getrequestdispatcher ("/user/a.jsp") this/relative to the current Web application WebApp, its absolute address is:http://192.168.0.1/webapp/user/a.jsp. Sendredirect: <%response.sendredirect ("/rtccp/user/a.jsp") in the JSP;%>
3.2 Address of the client
The relative addresses in all the HTML pages are relative to the root of the server (HTTP://192.168.0.1/), not http://192.168.0.1/webapp/(with the directory of the Web app under the directory). The address of the Action property of the form form in HTML should be relative to the server root directory (http://192.168.0.1/), so if committed to a.jsp: action= "/webapp/ User/a.jsp "or action=" <%=request.getcontextpath ()% > "/user/a.jsp;
The actiom= "/webapp/handleservlet" JavaScript that is submitted to the servlet is also parsed on the client, so its relative path is the same as the form form.
Therefore, in general, in the Jsp/html page and other references such as css,javascript.action attributes are best added
<%=request.getcontextpath ()%> To ensure that the referenced files belong to a directory in the Web App. In addition, you should try to avoid the use of similar ".", "./", ". /.. /"Similar relative path relative to the location of the file, so that when the file is moved, it is prone to problems.
To put it simply:
All paths are requests for resources from the server. The difference is that this path is on the server side also client parsing!
If you want to write down this path is to be resolved on the server side, then the root of this path should be like http://192.168.0.1/webapp/in this form, that is, the path of WebApp is the root path. For example, in the Struts2 formulation of the Oobbs system (the name of the Web application is: Oobbs):
<action name= "Getforumbyid" class= "forumaction" method= "Getforumbyid" >
<result name= "Input" >/</result>
<result name= "Success" >/site/forumlist.jsp</result>
</action>
The path above is:/site/forumlist.jsp instead of /oobbs/site/forumlist.jsp
And if we write this path in the clinet end to parse, then the path root becomes http://192.168.0.1/, that is, the path of the server is the root path. At this point, if you want to request some resources in the background, such as jsp,action, then you must start from WebApp, write your path!
Like what:
The form in our landing page:
<form action= "/Oobbs/site/j_spring_security_check" method= "POST" >
This path must start with/oobbs!
4. About <c:url>
Relative and absolute paths in JSPs