Passing Control from One Page to Another
Before digging
into the modified example pages,
let’s go through the basic mechanisms for satisfying
the two requirements. As shown in Figure 10-1, the
userinfovalidate.jsp page passes control to one
of two other pages based on the result of the input validation. JSP
supports this through the
<jsp:forward>
action, described in Table 10-1:
<jsp:forward page="userinfoinput.jsp" />
Attribute name |
Java type |
Dynamic value accepted |
Description |
page |
String |
Yes |
Mandatory. A page-relative or context-relative path for the target resource. |
The <jsp:forward>
action stops processing of
one page and starts processing the page specified by the
page
attribute instead, called
the
target
page. The control
never returns to the original page.
The target page has access to all information about the request,
including all request parameters. You can also add additional request
parameters when you pass control to another page by using one or more
nested <jsp:param>
action elements (see
Table 10-2):
<jsp:forward page="userinfoinput.jsp" > <jsp:param name="msg" value="Invalid email address" /> </jsp:forward>
Attribute name |
Java type |
Dynamic value accepted |
Description |
name |
String |
No |
Mandatory. The parameter name. |
value |
String |
Yes |
Mandatory. The parameter value. |
Parameters specified with
<jsp:param>
elements are added to the parameters received with the original request. ...
Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.