This article analyzes the base tag usage in the JSP paging file. Share to everyone for your reference, specific as follows:
When we use the IDE tool to generate JSP pages, we usually include the following two pieces of code,
<%
String Path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>
They are definitely not useless code, as detailed below:
The base mark is a base link tag and is a single token. The parameter's default value used to change all the link markers in the file. It can only be applied between tags
Important attributes:
HREF---set prefix link address
Target---Set the window displayed by the file, with Target in the a tag
Simple example:
When a link is made, the file that jumps out is http://localhost/x.htm or http://localhost/y.htm, which is the address that the base link points to before the file in the relative path. If the link in the destination file does not specify the target attribute, the target attribute in the base tag is used.
It is often used in frame structures, such as the left and right two frames, and the connections in the files in the left frame are shown in the frame on the right-hand side. As long as the base tag is used to write its target property value as the right frame name, it is no longer necessary to specify the target attribute for each connection in the file in the left frame.
When used, the BASE element must appear in the head of the document before any reference to the external source.
In addition, if the page turns to a servlet, and the servlet is forward to a JSP page, you should find the path to the servlet first if you write a relative path. That is, the path in the Url-pattern configured in Web.xml, such as: Suppose a x.jsp is placed under the WebApplication root directory, While the home page index.jsp is submitted to the servlet, the URL configured by Serlet to distribute forward to X.jsp,servlet is as follows:
Copy Code code as follows:
<url-pattern>/servlet/TestServlet</url-pattern>
After the servlet completes the forward turn, if there is no <base href= "<%=basePath%>" > x.jsp <script type= "Text/javascript" Script/check.js "></script> will fail because the servlet access path is http://localhost/webapp/servlet/ Testservlet then the Web server will go to http://localhost/webapp/servlet/script/ Go down and find check.js. At this time there must be no this file, so, if you encounter such a situation suggested using an absolute path will not be wrong
Copy Code code as follows:
<script type= "Text/javascript" src= "<%=path%>/script/check.js" ></script>
I hope this article will help you with JSP program design.