After a redirect the servlet that issues the redirect will
continue to run unless you stop the processing with a return
statement directly after the redirect. Now consider this
example:

[...]

This will stop Servlet B from processing doMoreOtherThings()
after the redirect, but Servlet A will still execute
doSomethingMore().

One other thing with sendRedirect() is, that it is a good
practice to do the redirect as early as possible.

[...]

Yes, but this just seems like a weakness in the model really. In our case, the redirect was sent in every case before anything of significance was added to the content of the response, so we never would have run in to a committed response issue. The fact that my JSP page turns in to a servlet behind-the-scenes, and that servlet model doesn't handle redirects in includes because of a code organization problem seems arbitrary and inappropriate. I would expect sendRedirect() to abort the response anyway, although someone may have a good reason to include content in a 302 response. A forward, on the other hand, does abort the response, so it is even more arbitrary that forwards don't work in includes. It seems like this is a case where a weakness in the model at a low level rears its head at the very highest level (JSP), which is, IMO, a bad thing. And the docs don't seem clear on this point at all. We only were able to confirm that redirects and forwards don't work in includes by examining the generated .java files and reading the docs on the servlet stuff. The JSP docs don't seem to mention it (I may be missing it...)


Here's the relevant docs:

sendRedirect
public void sendRedirect (String �location)
throws IOException
Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.


If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters:
location - the redirect location URL
Throws:
IOException - If an input or output exception occurs
IllegalStateException - If the response was committed

and


<jsp:forward>

Forwards a client request to an HTML file, JSP file, or servlet for processing.

JSP Syntax
<jsp:forward page={" relativeURL " | "<%= expression %>"} />
or
<jsp:forward page={" relativeURL " | "<%= expression %>"} >
<jsp:param name=" parameterName "
� � � � � value="{ parameterValue | <%= expression %>}" />+
</jsp:forward>

Examples
<jsp:forward page="/servlet/login" />
<jsp:forward page="/servlet/login">
<jsp:param name="username" value="jsmith" />
</jsp:forward>

Description

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 .

Attributes
page="{ relativeURL | <%= expression %>}"

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

The relative URL looks like a path-it cannot contain a protocol name, port number, or domain name. The URL can be absolute or relative to the current JSP file. If it is absolute (beginning with a /), the path is resolved by your Web or application server.
<jsp:param name=" parameterName " value="{ parameterValue | <%= expression %>}" />+


Sends one or more name/value pairs as parameters to a dynamic file. The target file should be dynamic, that is, a JSP file, servlet, or other file that can process the data that is sent to it as parameters.

You can use more than one <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.

Thanks!


Geoff

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to