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" />
--------------------------------------------------------------------------------------------------------------- ---------------------------------------------
For the sake of aesthetics, also for the convenience of writing code, you can use El expression, that is, the <link href="<%=request.getcontextpath ()%>/css/default.css" rel= "stylesheet" type="text/css"/>
Instead of <link href= " ${pagecontext.request.contextpath}/css/default.css" rel= "stylesheet " type="text/css "/>
Solve the problem of introducing JS, CSS and pictures under the Webroot of JSP page in/web-inf directory