Why not just do:

return new ActionForward(redirectUrl, true);

the 2nd parameter (true) indicates this is a redirect, not a forward.

----- Original Message ----- 
From: "Adam Fisk" <[EMAIL PROTECTED]>
To: "struts-user" <[EMAIL PROTECTED]>
Sent: Wednesday, September 17, 2003 7:43 PM
Subject: Re: getting redirect to work -- easy one?


> Thanks for the speedy response.  The Tomcat FAQ link is very related to
> my problem, but I'm not making any of the listed mistakes at least in my
> execute(...) method (I'm only calling sendRedirect once).  It appears
> that there's something I'm unaware of in either struts or faces that
> tries to perform a forward after the redirect since I added a print line,
> making my code now appear:
>
>     public ActionForward execute(ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response)
> throws Exception {
>         System.out.println("SearchAction::about to send redirect");
>         response.sendRedirect(redirectUrl);
>         System.out.println("SearchAction::sent redirect!!!!");
>     }
>
> The second print line appears prior to the IllegalStateException.
> Hmmnn...something I'm missing.  Thanks again.
>
> -Adam
>
> On Thu, 18 Sep 2003 09:35:44 +0800, "Kwok Peng Tuck"
> <[EMAIL PROTECTED]> said:
> > Perhaps this link might help you :
> > http://jakarta.apache.org/tomcat/faq/misc.html#illegalstate
> >
> > Adam Fisk wrote:
> >
> > >Thanks for getting back to me.  I'm unfortunately still at a bit of
loss
> > >here -- I'm right at the beginning of writing my first web app, so I
> > >think there's something I'm missing.  When I posted yesterday, the
> > >execute(...) method of my Action subclass had simply:
> > >
> > >        return (mapping.findForward("results"));
> > >
> > >This caused the error I posted.  After reading your post, I first
changed
> > >this to simply:
> > >
> > >        return null;
> > >
> > >I was wishfully thinking that the redirect would magically happen based
> > >on the struts-config settings, but this simply resulted in nothing
> > >happening at all.  Finally, I tried changing it to:
> > >
> > >        String contextPath = request.getContextPath();
> > >        String redirectUrl = contextPath + "/faces/results.jsp";
> > >        response.sendRedirect(redirectUrl);
> > >        return null;
> > >
> > >This, however, resulted in the same error I posted yesterday.  Sorry
for
> > >my complete lack of experience here, and thanks in advance for anyone's
> > >help.  What seemingly should be obvious continues to elude me =).
> > >
> > >-adam
> > >
> > >
> > >
> > >On Wed, 17 Sep 2003 02:21:53 -0700, "Daniel Wang" <[EMAIL PROTECTED]>
> > >said:
> > >
> > >
> > >>Looks like you printed something to the response before you try to do
the
> > >>redirect()
> > >>
> > >>daniel
> > >>
> > >>----- Original Message ----- 
> > >>From: "Adam Fisk" <[EMAIL PROTECTED]>
> > >>To: <[EMAIL PROTECTED]>
> > >>Sent: Tuesday, September 16, 2003 9:02 PM
> > >>Subject: getting redirect to work -- easy one?
> > >>
> > >>
> > >>
> > >>
> > >>>Hopefully this is an easy one for someone to answer. I'm simply
trying to
> > >>>set up an action-mapping that performs a redirect instead of a
forward.
> > >>>If I use the following xml in struts-config.xml (I'm using
> > >>>**struts-faces**), then everything "works":
> > >>>
> > >>><action
> > >>>  path="/search"
> > >>>  type="com.wheels.struts.SearchAction"
> > >>>  name="searchForm"
> > >>>  scope="request"
> > >>>  input="search">
> > >>>  <forward
> > >>>    name="results"
> > >>>    path="faces/results.jsp"
> > >>>  />
> > >>></action>
> > >>>
> > >>>I get an error if I change the forward to be a redirect, however, as
in:
> > >>>
> > >>>
> > >>><action
> > >>>  path="/search"
> > >>>  type="com.wheels.struts.SearchAction"
> > >>>  name="searchForm"
> > >>>  scope="request"
> > >>>  input="search">
> > >>>  <forward
> > >>>    name="results"
> > >>>    path="faces/results.jsp"
> > >>>    redirect="true"
> > >>>  />
> > >>></action>
> > >>>
> > >>>The error I get is:
> > >>>
> > >>>java.lang.IllegalStateException: Cannot forward after response has
been
> > >>>committed
> > >>>
> > >>>Any thoughts on this one? Is there something I need to change in my
> > >>>Action class to properly redirect instead of forward? Something in
> > >>>struts-config.xml??  I read earlier posts about creating an
> > >>>ActionRedirect subclass of ActionForward, but it seems like this
should
> > >>>not be necessary.  Keep in mind I'm using struts-faces -- not sure if
> > >>>that makes a difference.
> > >>>
> > >>>Thanks very much.
> > >>>
> > >>>-Adam
> > >>>-- 
> > >>>  Adam Fisk
> > >>>  [EMAIL PROTECTED]
> > >>>
> > >>>---------------------------------------------------------------------
> > >>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> > >>>For additional commands, e-mail: [EMAIL PROTECTED]
> > >>>
> > >>>
> > >>>
> > >>---------------------------------------------------------------------
> > >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> > >>For additional commands, e-mail: [EMAIL PROTECTED]
> > >>
> > >>
> > >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> -- 
>   Adam Fisk
>   [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


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

Reply via email to