Jsp/servlet page Jump loss style problem __js

Source: Internet
Author: User

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.