Absolute path referenced by the link in structs2

Source: Internet
Author: User
In the structs2 framework, each jsp performs ahref .. when referenced by a, the addresses in href are relative to the current action. In this way, when the project architecture is changed, the referenced path also needs to be changed, which is inconvenient. therefore, we recommend that you use absolute path when using the path: % Stringpathrequest must be added to the jsp file. getContextPath ()

In the structs2 framework, each jsp performs a href = .. when/a references, the addresses in href are relative to the current action. In this way, when the project architecture is changed, the referenced path also needs to be changed, which is inconvenient. therefore, we recommend that you use absolute path when using the path: % String path = request must be added to the jsp file. getContextPath ()

In the structs2 framework, when each jsp file is referenced, the address in href is relative to the current action. In this way, when the project architecture is changed, the referenced path is also changed, which is inconvenient.

Therefore, we recommend that you use the absolute path when using the path:

Add the following to the jsp file:

<% String path=request.getContextPath();   String basepath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>


This basepath representsCurrent Project.

If you want to access the path. action under the current project path/, you only need the following code:

<% @ Page language = "java" contentType = "text/html; charset = GB18030" pageEncoding = "GB18030" %><% String path = request. getContextPath (); String basepath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; %>
 Insert title here= "<% = Basepath %>Path/path. action "> path Problems

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.