Js|servlet PS: Here is how to paste HTML, so I have to format the text!
Path State test
Objective
Test JSP jumps to each other, servlet jumps the state of the absolute path and relative path under the JSP environment
To find a common solution
Process description
1. Jump directly from a.jsp to b.jsp
Or
Submitted by a.jsp to Testservlet,testservlet Select the corresponding jump method according to A's submission (Forward/sendredirect)
Then jump to b.jsp
2. b.jsp contains a series of hyperlinks, to show the different ways of the jump after the situation of the hyper-chain
/a.jsp
.. /a.jsp
.. /.. /a.jsp
.. /.. /.. /a.jsp
Jump way directly jump <a. > Servlet/forward servlet/sendredirect
Requestdispatcher.forward Response.sendredirect
---------------------+---------------------+----------------------------------+------------------------
Path to jump in servlet x/b/b.jsp/war/b/b.jsp
---------------------+---------------------+----------------------------------+------------------------
After the Jump browser's address bar ip/war/b/b.jsp Ip/war/layer1/layer2/testservlet ip/war/b/b.jsp
---------------------+---------------------+----------------------------------+------------------------
Link List Browser status bar link address in b.jsp
<a href= "Here's the description"
---------------------+---------------------+----------------------------------+------------------------
/a.jsp ip/a.jsp ip/a.jsp ip/a.jsp
.. /a.jsp ip/war/a.jsp ip/war/layer1/a.jsp ip/war/a.jsp
.. /.. /a.jsp ip/a.jsp ip/war/a.jsp ip/a.jsp
.. /.. /.. /a.jsp ip/a.jsp ip/a.jsp ip/a.jsp
As you can see from the list above, only the bottom row is meaningful and it is correct to jump the link address in any way
1. The root of "/" in the JSP is "IP" and does not contain a war path
2. The root of the "/" represented in forward in the servlet is "ip/war/", including the war path
3. The root of the "/" used in Sendredirect in the servlet is IP and does not contain a war path
4. Jump in forward in the servlet, the browser's address bar is still the servlet and does not change
5. In the servlet to jump Sendredirect, the browser's address bar changes to the destination path
6. Relative path determination is based on the path shown in the browser's address bar, rather than the specific directory structure, so
Jump to a page in the same directory using <a href= "filename" >link</a> this way is not permanent
(Do not be surprised to be an ASP, the JSP and servlet mentioned here:))
7. In order to avoid the JSP jumps Jsp,servlet jumps Jsp,forward the way jumps, the sendredirect jumps produces the path question,
For JSP and servlet using Sendredirect jump, use the direct-band
The absolute path of the container path [String request.getcontextpath ()] can be completely resolved, namely:
1) <%
String ContextPath = Request.getcontextpath ();
String url = contextpath + "/user/login.jsp";
%>
For a servlet that uses forward jumps, do not add a container path, otherwise the container path is repeated, for reasons see 2
8. If the use of ".. /"Too much will not be a serious problem," ... /"link up to up to" ip/"
9. In addition, in the use
<jsp:include page = "url" flush= "true"/>
<%@ include file= "url"%>
<%@ page errorpage = "url"%>,
Here the URL uses the "/" to represent the root of "ip/war/", including the war path
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.