JSP tutorial (6)-How to jump to another page in JSP

Source: Internet
Author: User

Use JSP forward action in JSP 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


forward test
! Supportemptyparas]>

! Supportemptyparas]>





! Supportemptyparas]>
test2.jsp


forward test
! Supportemptyparas]>

! Supportemptyparas]>

<% Out. println ("this is the output from the jsp2.jsp page"); %>


! Supportemptyparas]>
RUN test1.jsp. You can see the output information of "This is the output from the jsp2.jsp page" in the browser. 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
<HTML>
<Head>
<Title> forward test </title>
! Supportemptyparas]>
</Head>
! Supportemptyparas]>
<Body bgcolor = "# ffffff">
<JSP: Forward page = "/test4.jsp">
<JSP: Param name = "name" value = "powerman"/>
<JSP: Param name = "Address" value = "188 Beijing West Street"/>
</Jsp: Forward>
</Body>
</Html>
! Supportemptyparas]>
Test2.jsp
<HTML>
<Head>
<Title> forward test </title>
! Supportemptyparas]>
</Head>
! Supportemptyparas]>
<Body bgcolor = "# ffffff">
<%
Out. println ("this is the output from the jsp4.jsp page" + "<br> ");
Out. println ("name:" + request. getparameter ("name") + "<br> ");
Out. println ("Address:" + request. getparameter ("Address") + "<br> ");
! Supportemptyparas]>
%>
</Body>
</Html>

Run test3.jsp and you can see in the browser:

"This is the output from the jsp4.jsp page.
Name: powerman
Address: No. 188, West Beijing street"

Output Information

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.