Forwards a client request to an HTML file, JSP file, or servlet for processing.
<jsp:forward page="{
relativeURL| <%=
expression%>}" />
or <jsp:forward page="{relativeURL | <%= expression %>}" >
<jsp:param name="parameterName"
value="{parameterValue | <%= expression %>}" />+
</jsp:forward>
<jsp:forward page="/servlet/login" /> <jsp:forward page="/servlet/login">
<jsp:param name="username" value="jsmith" />
</jsp:forward>
The <jsp:forward>
element forwards the request
object containing the client request information from one JSP file to another file. The target file can be an HTML file, another JSP file, or a servlet, as long as it is in the same application context as the forwarding JSP file. The lines in the source JSP file after the <jsp:forward>
element are not processed.
You can pass parameter names and values to the target file by using a <jsp:param>
clause. An example of this would be passing the parameter name username (with name="username"
) and the value scott (with value="scott"
) to a servlet login file as part of the request. If you use <jsp:param>
, the target file should be a dynamic file that can handle the parameters.
Be careful when using <jsp:forward>
with unbuffered output. If you have used the <%@ page %>
directive with buffer="none"
to specify that the output of your JSP file should not be buffered, and if the JSP file has any data in the out object, using <jsp:forward>
will cause an IllegalStateException
.
page="{
relativeURL | <%=
expression %>}"
String
or an expression representing the relative URL of the file to which you are forwarding the request. The file can be another JSP file, a servlet, or any other dynamic file that can handle a request
object.
<jsp:param>
clause if you need to send more than one parameter to the target file. The name
attribute specifies the parameter name and takes a case-sensitive literal string as a value. The value
attribute specifies the parameter value and takes either a case-sensitive literal string or an expression that is evaluated at request time.