You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Fisk <af...@speedymail.org> on 2003/09/17 06:02:04 UTC

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
  afisk@speedymail.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: getting redirect to work -- easy one?

Posted by Adam Fisk <af...@speedymail.org>.
Thanks for that suggestion as well, Daniel -- I hadn't noticed that
ActionForward constructor.  I'm unfortunately still running into the same
IllegalStateException.  My code now simply reads:

    public ActionForward execute(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
	throws Exception {
        
        String redirectUrl = request.getContextPath() +
        "/faces/results.jsp";
        
        System.out.println("SearchAction::about to send redirect");
        return new ActionForward(redirectUrl, true);
    }  

It seems there's something in struts-faces, or in my struts-faces
configuration, that's trying to perform a forward after this point. 
Interestingly, I still get the IllegalStateException if I remove the
<forward ...>  element completely from my struts-config file, relying
solely on the hard-coded redirect you suggested.  Any chance there's a
bug in the struts-faces library??  Anyone else had success using
redirects with it?? Thanks so much again for the help.

-Adam


On Wed, 17 Sep 2003 19:56:38 -0700, "Daniel Wang" <dd...@anomaly.net>
said:
> 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" <af...@speedymail.org>
> To: "struts-user" <st...@jakarta.apache.org>
> 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"
> > <pe...@makmal.net> 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" <dd...@anomaly.net>
> > > >said:
> > > >
> > > >
> > > >>Looks like you printed something to the response before you try to do
> the
> > > >>redirect()
> > > >>
> > > >>daniel
> > > >>
> > > >>----- Original Message ----- 
> > > >>From: "Adam Fisk" <af...@speedymail.org>
> > > >>To: <st...@jakarta.apache.org>
> > > >>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
> > > >>>  afisk@speedymail.org
> > > >>>
> > > >>>---------------------------------------------------------------------
> > > >>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > >>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > > >>>
> > > >>>
> > > >>>
> > > >>---------------------------------------------------------------------
> > > >>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > >>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > > >>
> > > >>
> > > >>
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >
> > -- 
> >   Adam Fisk
> >   afisk@speedymail.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
-- 
  Adam Fisk
  afisk@speedymail.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: getting redirect to work -- easy one?

Posted by Daniel Wang <dd...@anomaly.net>.
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" <af...@speedymail.org>
To: "struts-user" <st...@jakarta.apache.org>
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"
> <pe...@makmal.net> 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" <dd...@anomaly.net>
> > >said:
> > >
> > >
> > >>Looks like you printed something to the response before you try to do
the
> > >>redirect()
> > >>
> > >>daniel
> > >>
> > >>----- Original Message ----- 
> > >>From: "Adam Fisk" <af...@speedymail.org>
> > >>To: <st...@jakarta.apache.org>
> > >>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
> > >>>  afisk@speedymail.org
> > >>>
> > >>>---------------------------------------------------------------------
> > >>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >>>
> > >>>
> > >>>
> > >>---------------------------------------------------------------------
> > >>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >>
> > >>
> > >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> -- 
>   Adam Fisk
>   afisk@speedymail.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: getting redirect to work -- easy one?

Posted by Adam Fisk <af...@speedymail.org>.
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"
<pe...@makmal.net> 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" <dd...@anomaly.net>
> >said:
> >  
> >
> >>Looks like you printed something to the response before you try to do the
> >>redirect()
> >>
> >>daniel
> >>
> >>----- Original Message ----- 
> >>From: "Adam Fisk" <af...@speedymail.org>
> >>To: <st...@jakarta.apache.org>
> >>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
> >>>  afisk@speedymail.org
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>>
> >>>      
> >>>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>
> >>    
> >>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
-- 
  Adam Fisk
  afisk@speedymail.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: getting redirect to work -- easy one?

Posted by Kwok Peng Tuck <pe...@makmal.net>.
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" <dd...@anomaly.net>
>said:
>  
>
>>Looks like you printed something to the response before you try to do the
>>redirect()
>>
>>daniel
>>
>>----- Original Message ----- 
>>From: "Adam Fisk" <af...@speedymail.org>
>>To: <st...@jakarta.apache.org>
>>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
>>>  afisk@speedymail.org
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>    
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: getting redirect to work -- easy one?

Posted by Adam Fisk <af...@speedymail.org>.
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" <dd...@anomaly.net>
said:
> Looks like you printed something to the response before you try to do the
> redirect()
> 
> daniel
> 
> ----- Original Message ----- 
> From: "Adam Fisk" <af...@speedymail.org>
> To: <st...@jakarta.apache.org>
> 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
> >   afisk@speedymail.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
-- 
  Adam Fisk
  afisk@speedymail.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: getting redirect to work -- easy one?

Posted by Daniel Wang <dd...@anomaly.net>.
Looks like you printed something to the response before you try to do the
redirect()

daniel

----- Original Message ----- 
From: "Adam Fisk" <af...@speedymail.org>
To: <st...@jakarta.apache.org>
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
>   afisk@speedymail.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org