JSP: Absolute Path Reference file

Source: Internet
Author: User

These two days are modifying the JSP page, because the path problem encountered a variety of confusion, on the internet to find a lot of information about the path, too perfect! But there are too many. I was dizzy without learning my head.

Finally let me find an absolute path to a simple method.

Create a JSP file in MyEclipse, which will add the following code by default:

JSP Code:

<%

String path = Request.getcontextpath ();

String basepath = request.getscheme () +"://"+request.getservername () +":"+  Request.getserverport () +path+"/";

%>           

In

For example, CSS and JS references:

<link rel="stylesheet" href="Style/css/index.css" type = "Text/css"

Media = "Screen" charset="utf-8" />

< Script src="style/js/jquery.js" type="text/ JavaScript></script>

For example, a reference to a picture in images under Webroot: <a href= "Images/xxx.jpg" >

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.