I encountered a problem when I was working on the project recently. I added response. sendRedirect () and the system also executed it, but it just didn't jump. Finally, I found the reasons on the Internet:
First, we need to understand how to use response. sendRedirect is the principle of redirection. It actually sends a special Header to the browser and then redirects it to the specified page. Therefore, when sendRedirect is used, you can see the address changes in the address bar of the browser.
The difference between using <jsp: forward page = ""/> is that it is directly done on the server, and the browser does not know or deal with the browser, the address of the browser does not change.
Therefore, when using response. sendRedirect, pay attention to the following two points:
1. When response. sendRedirect is used, no HTML output is available.
This is not absolute. The absence of HTML output means that HTML cannot be sent to a browser. In fact, the current server has a cache mechanism, generally at 8 K (I mean JSP SERVER), which means that unless you disable the cache or you use out. flush () force refresh. A small amount of HTML output is allowed before sendRedirect is used.
If an error is reported, "Some information has been submitted" (the original text has been forgotten), you should check whether there are too many HTML outputs.
2. After response. sendRedirect, follow the return statement;
We already know that response. sendRedirect is switched through a browser, so there will be actual actions only after page processing is complete. Now that you have to turn, what is the significance of the subsequent output? In addition, the redirection may fail due to the subsequent output.
<% @ Include file = "/page/checkLogin. jsp" %> the first sentence on the page to be verified.
The content of checkLogin. jsp is determined by checking whether the user has logged on to the session. If not, it is redirected to the logon page:
Copy codeThe Code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %>
<%
If (session. getAttribute ("userinfo") = null ){
Response. sendRedirect (url );
Return;
}
%>