JSP Tutorial (vi)-How to jump to another page in a JSP

Source: Internet
Author: User
Tags expression
js| Tutorials | page

Use JSP forward action in JSP to achieve the page's jump function.

Grammar:

<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 move the request to a different page. It has only one attribute, page. The page should consist of a relative URL. This can be a static value or a value that can be computed at the time of the request, as in the following two examples:

<jsp:forward page= "/utils/errorreporter.jsp"/>
<jsp:forward page= "<%= somejavaexpression%>"/>
!supportemptyparas]>

Here's a concrete example: use forward in test1.jsp to jump to the test2.jsp page.

test1.jsp
<title>forward test</title>
!supportemptyparas] >
!supportemptyparas]>
<body bgcolor= "#FFFFFF"
<!--jump to test2.jsp--!
<jsp:forward page= "/test2.jsp"/>
</body>
!supportemptyparas]>
test2.jsp
<TITLE> forward test </title>
!supportemptyparas]>
!supportemptyparas]>
<body bgcolor= "#FFFFFF"
<%out.println ("  This is the output produced by the jsp2.jsp page ");%>
</body>
!supportemptyparas]>
Run test1.jsp, you can see in the browser: "This is the output from the jsp2.jsp page" output information. But what if you have parameters in both the test1.jsp and test2.jsp pages? Get Way bar, not only the total length is limited, the use is now very inconvenient, and sometimes not safe. In fact, we can use the jsp1.1 in the forward to provide the Para properties can be resolved. Now the test3.jsp and test4.jsp to explain.

!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= "Beijing West Street No. 188th"/>
</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 ("addr") + "<br>");
!supportemptyparas]>
%>
</BODY>
</HTML>

Run test3.jsp, visible in the browser:

"This is the output produced by the jsp4.jsp page
Name: Powerman
Address: No. 188th West Street, Beijing

The 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.