The jsp:forward
action calls a JSP page or a Java Servlet in the same application as the current page. A jsp:forward
terminates the execution of the current JSP page.
If the page output is buffered, then the buffer is cleared prior to forwarding. If the page output is unbuffered and anything has been written to it, an attempt to use jsp:forward
results in an IllegalStateException
.
The following example calls one JSP page from another:
<% String whereTo = "/templates/"+someValue; %> <jsp:forward page='<%= whereTo %>' />
The syntax for jsp:forward is shown below:
<jsp:forward page="path" />
or:
<jsp:forward page="path"> <jsp:param name="paramName" value="paramValue" /> ... </jsp:forward>
Specifies the path of the invoked file. If path begins with "/" then the path is relative to the application containing the JSP page. If the path omits a leading "/", the path is considered relative to the path of the JSP page being translated.
For more information on the path, see Specifying a relative URL within a JSP.
The second form of the jsp:forward shows the addition of the jsp:param action. This action lets you add parameters to the HTTP request received by the destination JSP page. For more information, see jsp:param.