Question: Using the servlet, how to handle a servlet forwarding page style loss problem in a multipath page jump. (For example, when you visit http://localhost/project/listUser.action and go to http://localhost/project/user/listUser.jsp, the browser stays in http:// Localhost/project/adduser.action. At this time JSP original image positioning may be wrong.
and solve the JSP path problem, I think the following way is basically perfect (there are questions, please predecessors pointed out):
First recommend a more natural way, you can make the original with relative path positioning JSP continue to be available, do not have to modify the link individually (personal recommendation):
The first step: add base tags and a section of Java to the head of the JSP, but change the Getcontextpath to Getrequesturi help
JSP file
1 2 3 4 5 6 7 |
<% String Path = Request.getrequesturi (); String basepath = request.getscheme () + "://" + request.getservername () + ":" + request.getserverport () + path; %> < base href= "<%=basePath%>" > |
Note is Request.getrequesturi, so get out of exactly is the absolute path of the JSP.
For example, the browser address bar is: http://localhost:8084/project/listUser.action
Base is
Step two: Within the JSP page, all use relative path access.
In the third step, you don't have to manage the path of the action.
This method can be compatible with action and does not use action two of cases. The second method:
Step One: Add base tags and a section of Java Help in the head of the JSP
jsp file
1 2 3 4 5 6 7 |
<% String path = reques T.getcontextpath (); String basepath = request.getscheme () + "://" + request.getservername () + ":" + request.getserverport () + path + "/"; %> < base |