The problem of introducing the relative path of external resources in JSP and CSS

Source: Internet
Author: User

To add a base to a JSP page, you can use a relative path:

<%    StringPath=Request.getcontextpath (); StringBasePath=Request.getscheme ()+ "://"            +Request.getservername ()+ ":" +Request.getserverport ()+Path+ "/";%>

Then add base to the

<href= "<%=basePath%>"></base>

When you introduce an external file "directly" on this page, you can directly

<Scriptsrc= "Js/common/jquery-1.11.1.min.js"language= "JavaScript"type= "Text/javascript"></Script><Scriptsrc= "Js/common/frame.js"language= "JavaScript"type= "Text/javascript"></Script><Linkhref= "Css/common/frame.css"rel= "stylesheet"type= "Text/css" /><Linkrel= "shortcut icon"href= "Images/favicon.ico"type= "Image/x-icon" />

Similarly, the CSS classes in this page

{    position: absolute;     Left: 0;     top: 95px;     Right: 0;     height: 120px;     background: url (images/common/title.jpg) repeat-x}

==================== Exception: The introduction of external CSS, JS files introduced in image and so on =================================

In this case, if you also use a relative path, because it is not in the JSP page, the relative path is relative to this CSS file in the same directory:

For example: Tang di new system, CSS file introduced in index.jsp page

<href= "Css/common/frame.css"  rel= "stylesheet"  type = "Text/css" />

at this point in the JSP page, the introduction of the Js/common/frame.js is from the site and directory to start looking for, no problem.

However, the following CSS is available in Frame.js

. Show_menu {    background-image: url (images/left_bg.gif);     background-repeat: repeat-y;     background-position:285px 51px;}

In this case the direct URL (images/left_bg.gif) is the default from the directory where this CSS file is located (/css/common/frame.css) +url (images/left_bg.gif), So the image needed here needs to be configured separately,

Change into

. Show_menu {    background-image: url (.. /.. /images/left_bg.gif);     background-repeat: repeat-y;     background-position:285px 51px;}

Problems with the introduction of relative paths to external resources in JSP, CSS

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.