Analysis on the Problem of introducing external resource relative paths in jsp and css, jspcss

Source: Internet
Author: User

Analysis on the Problem of introducing external resource relative paths in jsp and css, jspcss

Add a base on the jsp page. Available relative paths:

Copy codeThe Code is as follows:
<%
String path = request. getContextPath ();
String basePath = request. getScheme () + "://"
+ Request. getServerName () + ":" + request. getServerPort ()
+ Path + "/";
%>

Then add the base in the

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

When an external file is directly introduced on this page

Copy codeThe Code is as follows:
<Script src = "js/common/jquery-1.11.1.min.js" language = "javascript"
Type = "text/javascript"> </script>
<Script src = "js/common/frame. js" language = "javascript"
Type = "text/javascript"> </script>
<Link href = "css/common/frame.css"
Rel = "stylesheet" type = "text/css"/>
<Link rel = "shortcut icon" href = "images/favicon. ico" type = "image/x-icon"/>

Similarly, the css class on this page

Copy codeThe Code is as follows:
. Top {
Position: absolute;
Left: 0;
Top: 95px;
Right: 0;
Height: 120px;
Background: url (images/common/title.jpg) repeat-x
}

=============================== Exceptions: when external css and js files are introduced, and image files are introduced, ======================== =====

If the relative path is used at this time, because it is no longer in the jsp page, the relative path is relative to the directory where the css file is located:

For example, the css file introduced on the index. jsp page in the new system of zookeeper

<Link href = "css/common/frame.css" rel = "stylesheet" type = "text/css"/> On the jsp page, js/common/frame is introduced. js is searched from the website and directory. No problem.

However, the following css is available in frame. js:

Copy codeThe Code is as follows:
. 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 path from the directory where the css file is located (/css/common/frame.css) + url (images/left_bg.gif ), therefore, you need to configure the image separately,

Change

Copy codeThe Code is as follows:
. Show_menu {
Background-image: url (.../../images/left_bg.gif );
Background-repeat: repeat-y;
Background-position: 285px 51px;
}

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.