Recently I encountered a problem when working on a project. I clearly added () and the system also executed it, but it just didn't jump. Finally, the reasons were found online:
First of all, we need to understand the principle of using it as a steering. It actually sends a special header to the browser, and then transfers it from the browser to the specified page. Therefore, when using sendRedirect, the address changes can be seen on the address bar of the browser.
It is different when using <jsp:forward page=""/>. It is done directly in the server. The browser does not know it and does not deal with the browser. This can be seen from the fact that the browser address does not change.
Therefore, you need to pay attention to the following two points when using:
1. When using it, there is no HTML output before it.
This is not absolute. The inability to have HTML output actually means that HTML cannot be sent to the browser. In fact, servers now have cache mechanisms, generally in 8K (I mean JSP SERVER), which means that unless you turn off cache, or you use() to force refresh, a small amount of HTML output is also allowed before using sendRedirect.
If an error says "some information has been submitted" (forgotten in the original text), then you should pay attention to whether there is too much HTML output in the previous section.
2. After that, you should follow a sentence of return;
We already know that the steering is done through the browser, so there will be actual actions only after the page processing is completed. Since you are already making a turn, what is the point of the subsequent output? And it may cause the steering to fail due to the subsequent output.
<%@ include file="/page/" %>This is placed in the first sentence of the page to be verified.
The content is to determine whether to log in by looking at the content of the logged-in user in the session. If not, then jump to the login page:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
if (("userinfo") == null) {
(url);
return;
}
%>
First of all, we need to understand the principle of using it as a steering. It actually sends a special header to the browser, and then transfers it from the browser to the specified page. Therefore, when using sendRedirect, the address changes can be seen on the address bar of the browser.
It is different when using <jsp:forward page=""/>. It is done directly in the server. The browser does not know it and does not deal with the browser. This can be seen from the fact that the browser address does not change.
Therefore, you need to pay attention to the following two points when using:
1. When using it, there is no HTML output before it.
This is not absolute. The inability to have HTML output actually means that HTML cannot be sent to the browser. In fact, servers now have cache mechanisms, generally in 8K (I mean JSP SERVER), which means that unless you turn off cache, or you use() to force refresh, a small amount of HTML output is also allowed before using sendRedirect.
If an error says "some information has been submitted" (forgotten in the original text), then you should pay attention to whether there is too much HTML output in the previous section.
2. After that, you should follow a sentence of return;
We already know that the steering is done through the browser, so there will be actual actions only after the page processing is completed. Since you are already making a turn, what is the point of the subsequent output? And it may cause the steering to fail due to the subsequent output.
<%@ include file="/page/" %>This is placed in the first sentence of the page to be verified.
The content is to determine whether to log in by looking at the content of the logged-in user in the session. If not, then jump to the login page:
Copy the codeThe code is as follows:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
if (("userinfo") == null) {
(url);
return;
}
%>