Recently did the project encountered a problem, obviously added Response.sendredirect (), the system also implemented, but it is not jump; finally find the reason on the Internet as follows:
First of all, we need to understand the principle of response.sendredirect, it is actually to the browser to send a special header, and then the browser to do the turn, go to the specified page, so with Sendredirect, the browser's address bar can see changes in address.
With <jsp:forward page= ""/> is different, it is done directly in the server, the browser does not know, also does not deal with the browser, this from the browser address does not change can be seen.
so you need to pay attention to the following two points when using Response.sendredirect:
1, in the use of Response.sendredirect, the front can not have HTML output.
This is not absolute, and the inability to have HTML output actually means that HTML cannot be sent to the browser. In fact, now the SERVER has cache mechanism, generally in 8K (I mean JSP SERVER), which means that unless you close the cache, or you use the Out.flush () force refresh, then before using Sendredirect, there are a small number of The HTML output is also allowed.
If the error says, "Some information has been submitted" (the original forgotten), then you should pay attention to see, the front is not too much HTML output.
2, after the Response.sendredirect, should be followed by a return;
We already know that Response.sendredirect is a browser to do the steering, so only after the page processing is complete, there will be actual action. Now that you've got to turn, what's the point of the output? And it is possible that the subsequent output will cause the steering failure.
<%@ include file= "/page/checklogin.jsp"%> the first sentence on the page to be validated.
Checklogin.jsp content is by looking at the session has not logged in the user's content to determine whether to log in, if not, then jump to the landing page:
Copy Code code as follows:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<%
if (Session.getattribute ("userinfo") = = null) {
response.sendredirect (URL);
return;
}
%>