Bradley Unwin wrote:

> Hi,
>
> I am currently on a project running weblogic, and I'm having some issues 
>communicating between servlets.
>
> I have a Controlling servlet which dispatches requests to jsp's in order to return 
>output to the browser.  I am doing this by retrieving a requestDispatcher and 
>forwarding the request to the jsp.
>
> Something like this:
>
> summary = getServletContext().getRequestDispatcher( JSPName );
>
> // Forward to the appropriate JSP
> if (summary != null) {
>        summary.forward(req, resp);
> }
>
> My problem is that when the forward method is invoked after the jsp has completed, 
>control is returned to the Controlling Servlet and it continues processing below the 
>forward statement.
>

Although the RequestDispatcher.forward() call logically assigns responsibility for 
creating the output to the servlet or JSP page you forward to, it is still just a Java 
method call -- nothing
magic.  Therefore, the forward() method will eventually return.  Just add a "return" 
statement after the forward() call in your servlet code, since there is nothing more 
you can do to the response.

>
> My understanding of "forward" is that control is handed off to the JSP (which is 
>just a servlet in disguise).  Thus the Controlling servlet is then free to handle new 
>client requests.
>

As long as your servlet does not implement SingleThreadModel, it is available to 
handle multiple requests simultaneously.  The servlet engine will perform each request 
to your servlet on a different
thread.

If you implement SingleThreadModel (not a good idea, but that's another whole 
discussion :-), then any one instance of your servlet will be limited to running one 
request at a time, but the servlet
engine can create multiple instances in an attempt to maintain reasonable response 
time.

> Has anyone else had this problem??
> Why is it happening??
>

It's a requirement of the Java language definition.  Unless the called method throws 
an exception, it will *always* return to the statement following the call.  Even if it 
does throw an exception it
still returns, but goes to your exception handler instead of the next statement.


>
> Thanks,
>
> Brad.
>

Craig McClanahan

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to