Absolute path and relative path problems in JSP and servlet I've been bothering you for days, and after trying to share some of the experience with you.
Premise: Suppose your HTTP address is HTTP://192.168.0.1/your Web application is WebApp, then your Web application URL is http://192.168.0.1/webapp/
directory structure for Web applications:
webapp/
web-inf/
classes/
lib/
web.xml
<servlet-mapping>
<servlet-name>handleservlet</servlet-name>
<url-pattern>/handleservlet</url-pattern>此映射是相对于当前web应用的
</servlet-mapping>
user/
a.jsp
b.jsp
images/
css/
js/
All relative paths are started with "/". For example:/image/a.gif,/user/main.jsp, you know the relative path in HTML is this:
There is an HTML file: a.html, which has the <link href= "One.css" rel= "stylesheet" type= "Text/css", where the href attribute represents the path of the referenced CSS file.
ONE.CSS: Indicates that one.css and A.HMTL are in the same directory
USER/ONE.CSS: Indicates that ONE.CSS is in the subdirectory user of the directory where a.html resides.
.. /ONE.CSS: Indicates that the ONE.CSS is located in the top level of A.HMTL directory,
.. /.. /ONE.CSS: Indicates that the ONE.CSS is located in the upper level of the directory at the A.HMTL level,
./: Represents and A.HMTL the same directory
We call this relative path the HTML relative path
1, server-side address
The relative address on the server side refers to the address of your Web application, which is resolved on the server side (unlike the relative addresses in HTML and JavaScript, They are parsed by the client browser, which means that the relative address in the JSP and servlet at this time should be relative to your Web application, that is, relative to the http://192.168.0.1/webapp/.
The places it uses are:
Forwarder:servlet in Request.getrequestdispatcher (address); This address is resolved on the server side, so You have to forwarder to a.jsp should write this: 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 in JSP ("/rtccp/user/a.jsp");%>