Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
15.5 Forwarding Requests From JSP Pages
381
where. For example, a request might go to a JSP page that normally presents
results of a certain type and that forwards the request elsewhere only when it
receives unexpected values.
Sending requests to servlets instead of JSP pages requires no changes
whatsoever in the use of the
RequestDispatcher
. However, there is special
syntactic support for forwarding requests from JSP pages. In JSP, the
jsp:forward
action is simpler and easier to use than wrapping up
Request
Dispatcher
code in a scriptlet. This action takes the following form:
The
page
attribute is allowed to contain JSP expressions so that the desti
nation can be computed at request time. For example, the following sends
about half the visitors to
http://host/examples/page1.jsp
and the oth
ers to
http://host/examples/page2.jsp
.
<% String destination;
if (Math.random() > 0.5) {
destination = "/examples/page1.jsp";
} else {
destination = "/examples/page2.jsp";
}
%>
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved