JSP uses JSP forward action to redirect pages.
Syntax:
<JSP: Forward page = "{relativeurl | <% = expression % >}"/> or <JSP: Forward page = "{relativeurl | <% = expression % >}"> <JSP: Param name = "parametername" Value = "{parametervalue | <% = expression % >}"/>+ </jsp: Forward> |
This action allows you to forward the request to another page. It has only one attribute, page. Page should contain a relative URL. This can be a static value or a value that can be calculated when it is requested, as shown in the following two examples:
<JSP: Forward page = "/utils/errorreporter. jsp"/> <JSP: Forward page = "<% = somejavaexpression %>"/> ! Supportemptyparas]> |
Here is a specific example: Use forward in test1.jsp to jump to the test2.jsp page.
Test1.jsp
<HTML> <Head> <Title> forward test </title> ! Supportemptyparas]> </Head> ! Supportemptyparas]> <Body bgcolor = "# ffffff"> <! -- Jump to test2.jsp --!> <JSP: Forward page = "/test2.jsp"/> </Body> </Html> ! Supportemptyparas]> |
Test2.jsp
<HTML> <Head> <Title> forward test </title> ! Supportemptyparas]> </Head> ! Supportemptyparas]> <Body bgcolor = "# ffffff"> <% Out. println ("this is the output on the jsp2.jsp page"); %> </Bo # @ 62; </Html> ! Supportemptyparas]> |
Run test1.jsp and you can see the output information in the browser: "This is the output from the jsp2.jsp page. But what if you pass parameters on the test1.jsp and test2.jsp pages? The get method is not only inconvenient but also insecure. In fact, we can use the Para attribute provided for forward in jsp1.1 to solve this problem. Test3.jsp and test4.jsp are used to describe.
! Supportemptyparas]> test1.jsp forward test ! Supportemptyparas]> ! Supportemptyparas]> ! Supportemptyparas]> test2.jsp forward test ! Supportemptyparas]> ! Supportemptyparas]> <% out. println ("this is the output from the jsp4.jsp page" + " "); out. println ("name:" + request. getparameter ("name") + " "); out. println ("Address:" + request. getparameter ("Address") + " "); ! Supportemptyparas]> %> |
Run test3.jsp to view the output information in the browser.:
"This is the output from the jsp4.jsp page.
Name: powerman
Address: No. 188, West Beijing street"