Implement page Jump in JSP

Source: Internet
Author: User

Jsp (the preferred choice for SUN Enterprise Applications) uses jsp (the preferred choice for SUN Enterprise Applications) forward Action to redirect pages.

  Syntax:

<Jsp (preferred for SUN Enterprise Applications): forward page = "{relativeURL | <% = expression % >}"/> Or
<Jsp (preferred for SUN Enterprise Applications): forward page = "{relativeURL | <% = expression % >}">
<Jsp (preferred for SUN Enterprise Applications): param name = "parameterName"
Value = "{parameterValue | <% = expression % >}"/> + </jsp (preferred for SUN Enterprise Applications): 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 (preferred for SUN Enterprise Applications): forward page = "/utils/errorReporter. jsp (preferred for SUN Enterprise Applications)"/>
<Jsp (preferred for SUN Enterprise Applications): forward page = "<% = someJavaExpression %>"/>
! SupportEmptyParas]>

Here is an example: Use forward in test1.jsp (preferred for SUN Enterprise applications) to jump to the test2.jsp (preferred for SUN Enterprise Applications) page.

Test1.jsp (preferred for SUN Enterprise applications)

<HTML>
<HEAD>
<TITLE> forward test </TITLE>
! SupportEmptyParas]>
</HEAD>
! SupportEmptyParas]>
<Body bgcolor = "# FFFFFF">
<! -- Jump to test2.jsp (preferred for SUN Enterprise Applications) --!>
<Jsp (preferred for SUN Enterprise Applications): forward page = "/test2.jsp (preferred for SUN Enterprise Applications)"/>
</BODY>
</HTML>
! SupportEmptyParas]>

Test2.jsp (preferred for SUN Enterprise applications)

<HTML>
<HEAD>
<TITLE> forward test </TITLE>
! SupportEmptyParas]>
</HEAD>
! SupportEmptyParas]>
<Body bgcolor = "# FFFFFF">
<% Out. println ("this is the preferred jsp (SUN Enterprise Application preferred) 2.jsp( SUN Enterprise Application preferred) page output"); %>
</BO # @ 62;
</HTML>
! SupportEmptyParas]>

Run test1.jsp (preferred for SUN Enterprise Applications). You can see in the browser: "This is jsp (preferred for SUN Enterprise Applications) 2.jsp( preferred for SUN Enterprise applications) page output "output information. But what if you have parameter transfer on test1.jsp (the preferred choice for SUN Enterprise applications) and test2.jsp (the preferred choice for SUN Enterprise Applications? The get method is not only inconvenient but also insecure. In fact, we can use the para attribute provided to forward in jsp (the preferred choice for SUN Enterprise Applications) 1.1. Test3.jsp (the preferred choice for SUN Enterprise applications) and test4.jsp (the preferred choice for SUN Enterprise Applications) are used to describe.

! SupportEmptyParas]>
Test1.jsp (preferred for SUN Enterprise applications)
<HTML>
<HEAD>
<TITLE> forward test </TITLE>
! SupportEmptyParas]>
</HEAD>
! SupportEmptyParas]>
<Body bgcolor = "# FFFFFF">
<Jsp (preferred for SUN Enterprise Applications): forward page = "/test4.jsp (preferred for SUN Enterprise Applications)">
<Jsp (preferred for SUN Enterprise Applications): param name = "name" value = "powerman"/>
<Jsp (preferred for SUN Enterprise Applications): param name = "address" value = "188 Beijing West Street"/>
</Jsp (preferred for SUN Enterprise Applications): forward>
</BODY>
</HTML>
! SupportEmptyParas]>
Test2.jsp (preferred for SUN Enterprise applications)
<HTML>
<HEAD>
<TITLE> forward test </TITLE>
! SupportEmptyParas]>
</HEAD>
! SupportEmptyParas]>
<Body bgcolor = "# FFFFFF">
<%
Out. println ("This is the first choice for jsp (SUN Enterprise Applications) 4.jsp( the first choice for SUN Enterprise Applications) page output" + "<br> ");
Out. println ("name:" + request. getParameter ("name") + "<br> ");
Out. println ("address:" + request. getParameter ("address") + "<br> ");
! SupportEmptyParas]>
%>
</BODY>
</HTML>

Run test3.jsp (the preferred choice for SUN Enterprise Applications). You can view the output information in the browser:

"This is the output of the jsp (first choice for SUN Enterprise Applications) 4.jsp( first choice for SUN Enterprise Applications) Page
Name: powerman
Address: No. 188, West Beijing street"

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.