Way1: Embed Java code inside
The JSP page embeds the following code:
<%
String Path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
Test Cases:
<script type= "Text/javascript" src= "<%=basepath%>/js/header.js" ></script>
Way2: via El expression
An explanation of the syntax for El expressions see: http://blog.csdn.net/qwerasdf123/article/details/4189889
Add the following code to the JSP page
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jstl/core_rt"%> <c:set var=
"SC" >${ Pagecontext.request.contextpath}</c:set>
Test Cases:
<script type= "Text/javascript" src= "${sc}/js/header.js" ></script>
Note: The EL expression can only be used in the JSP page, no more JS and CSS and other format files to use. hard to
find a two-hour error, only to find this problem. Hope you can learn the lesson, but also hope to help readers solve problems, save your precious time.