Things to be aware of when using jsp:include tags and <%@ include tags
Recall the difference between the two (there is no difference in usage for this article)
Jsp:include is to compile the included.jsp file first and then include (compile first, then include)
@ include is to include the file first, then unified compilation (first included, later compiled)
I want to integrate jquery into the project this afternoon and find out how it all goes wrong. The reason is the path problem.
In the integration, my idea is to write a public JSP file, which contains some commonly used JS files, of course, I use the jquery plugin.
But after writing to find out that a separate test public JSP is available, but the page containing the public JSP page can never use jquery, the beginning is thought to be the problem of loading order.
After several tests, finally found the problem.
Because there are more project files, the file is not placed under a folder: In the public JSP page, there are
Copy Code code as follows:
<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%>
<script type= "Text/javascript" src= "Js/jquery132min.js" ></script>
<script type= "Text/javascript" >
$ (function () {
Alert (' Hello1 ');
});
</script>
At the time of calling it, there are:
<%@ include file= ". /.. /common_ext.jsp "%>
But this is likely to lead to errors.
The reason is that, after include, the public JSP is loaded into its own JSP, the relative position of the Jqueryr has changed. That is, the public JSP to the relative position of jquery to its own JSP, but its own JSP as a standard, through the path can not find the jquery plug-ins. Simply put, if you use a relative path, the path in the public JSP should be the path relative to your JSP.
But this obviously loses its significance as a public JSP, so here's the absolute path:
Copy Code code as follows:
<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%>
<%
String Tpath = Request.getcontextpath ();
String Tbasepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +tpath+ "/";
%>
<script type= "Text/javascript" src= "<%=tbasepath%>js/jquery132min.js" ></script>
<script type= "Text/javascript" >
$ (function () {
Alert (' Hello1 ');
});
</script>
In this way, as long as in their own JSP page to introduce a public JSP.