Reason analysis and solution of jsp response

  • 2020-06-03 08:03:55
  • OfStack

Recently, I encountered a problem when I was working on a project. response. sendRedirect() was clearly added and the system was implemented, but it just didn't jump. Finally, I found the reasons on the Internet as follows:

First of all, we need to understand the principle of using ES4en.sendRedirect to do the steering, it is to send a special Header to the browser, and then the browser to do the steering, go to the specified page, so when using sendRedirect, the browser's address bar can see the change of address.
with < jsp:forward page=""/ > Instead, it's made directly from server, and the browser doesn't know about it and doesn't deal with it, as the address of the browser doesn't change.

So when using ES15en. sendRedirect, you should pay attention to the following two points:

1. When using ES19en. sendRedirect, HTML output cannot be preceded.

It's not absolute, you can't have HTML output but you can't have HTML sent to the browser. The fact that server now has an cache mechanism, usually in 8K (I mean JSPSERVER) means that unless you turn off cache or you use out.flush () to force a refresh, a small amount of HTML output is allowed before using sendRedirect.
If the error says, "1 something has been forgotten by submitted," then you should look to see if there is too much HTML output ahead.

2. After response.sendRedirect, the sentence return should be followed closely.

We already know that response.sendRedirect does the steering through the browser, so there will be no actual action until the page is processed. What's the point of the output after you've done the turn? It is also possible that the subsequent output will cause the turn to fail.

< %@ include file="/page/checkLogin.jsp" % > This is placed in the first sentence of the page to verify.

checkLogin. jsp determines whether a user is logged in or not by looking at the content in session. If not, then jump to the login page:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 
if (session.getAttribute("userinfo") == null) { 



Related articles: