There are several methods for page forwarding: 1 requestdispatcher. Forward () 2 response. sendredirect ()
3 <JSP: Forward page = ""/> 4. Modify the location attribute of the HTTP header to redirect 5 pagecontext. forward () I wrote the code to check whether a user is logged on to a JSP file. The Code is as follows: logincheck. JSP <% IF (Session. getattribute ("flag") = NULL
|! "OK". Equals (session. getattribute ("flag") {// 1 redirect Mode 1
Response. sendredirect ("login. jsp ");
Return; // 2 jump Mode 2
// Pagecontext. Forward ("login. jsp ");
} %>
// Success. jsp
<% @ Page contenttype = "text/html; charset = shift_jis" session = "true"
Iserrorpage = "false" errorpage = "Err. jsp" %>
// Method
<! -- JSP: Include page = "logincheck. jsp" Flush = "true"/---->
// Method B
<% @ Include file = "logincheck. jsp" %>
<HTML>
<Head>
<Title> success. jsp </title>
</Head>
<Body>
This is my JSP page. Success! <Br>
Welcome
<%
Out. Print ("School:" + request. getattribute ("school") + "<br> ");
Out. Print ("Age:" + session. getattribute ("Age") + "<br> ");
Out. Print ("City:" + application. getattribute ("city") + "<br> ");
%>
</Body>
<A href = "logout. jsp"> too many rows have been created </a>
</Html>
I tested the File Inclusion Method and file transfer method in combination.
The result is as follows:
--------------------------------------------------
Includes method | jump Method | result
-------------------------------------------------
A | 1 | Note 1
------------------------------------------------
B | 1 | OK
------------------------------------------------
A | 2 | Note 2
------------------------------------------------
B | 2 | OK
------------------------------------------------
Note 1
No redirection
Note 2
Only
<JSP: Include page = "logincheck. jsp" Flush = "true"/>
Put it in the first line of the Code.
Otherwise
Java. Lang. illegalstateexception: cannot forward after response has been committed at org. Apache. Catalina. Core. applicationdispatcher. doforward
Japanese Environment
Java. lang. illegalstateexception. apache. catalina. core. applicationdispatcher. doforward (applicationdispatcher. java: 324)
This error is often returned before the Forward Command is executed!
Unknown reason! Go online and try again!