"Kommana, Sridhar" wrote:
>
> We are using IBMs WebSphere. I am using RequestDispatcher to redirect the servlet to 
>a different page/servlet. Code I am using in my
> servlet(x.java) is as follows:
>
>         String xyz = request.getParameter("xyz");
>
> if (xyz.equals("one")) {
>                 RequestDispatcher rd1 = 
>getServletContext().getRequestDispatcher(page1.jsp);
>                 rd1.forward(request, response);
> }
>
>                 RequestDispatcher rd2 = 
>getServletContext().getRequestDispatcher(page2.htm);
>                 rd2.forward(request, response);
>
> If "xyz" is not "one" page2.htm is displayed. If "xyz" is "one", then page1.jsp is 
>displayed and "llegalStateException" error is
> thrown below it. I am not sure why it is behaving like this. I believe if "xyz" is 
>"one" then control should be transferred to
> page1.jsp and code after the if loop should not be executed.
>
> I have tried using servlets in place of page1 and page2. The result is same - code 
>upto forward takes the control to the target
> servlet and any code after the forward including forward if any, are also executed. 
>If there is no code after forward(esp another
> forward) then it behaves just fine.
>
> Can anybody throw light on it!

You have to add a "return;" after the forward() call. There's no magic in Java
that
let's it figure out by itself that it should not continue when the forward()
call
returns.

In a JSP page, using <jsp:forward>, there *is* some magic though; the
<jsp:forward>
tag tells the JSP container that the rest of the page should be ignored (using a
special return code, see the JSP 1.1 spec for details). But if you forward with
regular Java code, you have to be your own magician.

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to