Transferred from: http://blog.csdn.net/qq_18875541/article/details/69390871
JSP pages are usually placed under Webroot/web-inf to prevent visitors from entering the page directly.
The pages under WebRoot/web-inf are protected and users cannot access them through the form of http://localhost:8080/test/webRoot/WEB-INF/content/xx.jsp, and their visits must be handled through struts.
However, when the page is placed under the/web-inf, the JSP page can not avoid the "external" js,css, the picture "interaction", because the need to introduce some webroot/css, Webroot/js, Webroot/images, and at this time it is easy to introduce failure, In general, the relative path does not work at this time, so absolute paths must be used! The following one by one summarizes.
First, the introduction of WEBROOT/CSS
<link href="<%=request.getcontextpath ()%>/css/default.css" rel="stylesheet" type ="Text/css"/>
This <%=request.getcontextpath ()%> is/hh_test (project name), and <%=request.getcontextpath ()%>/ CSS is equivalent to using an absolute path to directly locate the WEBROOT/CSS.
Ii. introduction of Webroot/js
<script type="Text/javascript" language= "javascript" src="<%= Request.getcontextpath ()%>/js/jquery-1.4.4.min.js "></script>
Iii. introduction of Webroot/images
<img src="<%=request.getcontextpath ()%>/images/4.gif" alt="Loading external pictures" />
Summary: It is best to put the JSP page under/web-inf, and the JSP page into the "external" js,css,images, you must get the root path of the project, plus/CSS (or/js or/images) is the method of using absolute path, rather than the method of relative path, To access the resources placed under the Webroot!
Solve the problem of introducing JS, CSS and pictures under the Webroot of JSP page in/web-inf directory