Things to note when using jsp:include tags and <%@ include tags
First recall the difference between the two (for this article, there is no difference in usage between the two)
jsp:include It is to compile the included.jsp file first, and then include it (compile first, then include)
@include is to include the file first, and then compile it uniformly (include first, then compile)
I want to use Jquery this afternoon Integrate it into the project and find that there will be problems no matter what. The reason is the path problem.
When integrating, my idea is to write a public JSP file, which contains some commonly used js files. Of course, I use the Jquery plug-in here.
But after writing it, I found that the public JSP can be used when tested alone, but JQuery cannot be used on pages containing public JSP pages. At first, I thought it was a loading order problem.
After several tests, the problem was finally discovered.
Due to the large number of project files, the files are not placed in one folder: in the public JSP page, there are
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
< ;script type="text/javascript" src="js/jquery132min.js">
When calling it, there are:
<%@ include file= "../../common_ext.jsp"%>
But this is likely to cause errors.
The reason is that after include, the public JSP is loaded into its own JSP, and the relative position of JQueryr has changed. That is, the public JSP passes the relative position of JQuery to its own JSP, but its own JSP uses itself as the standard, and the Jquery plug-in cannot be found through the path. Simply put, if you use a relative path, the path in the public JSP should be relative to the path of your own jSP.
But this obviously loses the meaning of it being a public JSP, so use absolute paths here:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String tPath = request.getContextPath();
String tBasePath = request.getScheme() "://" request.getServerName() ":" request.getServerPort() tPath "/";
%>
In this way, as long as it is in your own jSP Just introduce public JSP into the page.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn