struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Fisk" <af...@speedymail.org>
Subject Re: getting redirect to work -- easy one?
Date Thu, 18 Sep 2003 02:43:53 GMT
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"
<pengtuck@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" <ddwang@anomaly.net>
> >said:
> >  
> >
> >>Looks like you printed something to the response before you try to do the
> >>redirect()
> >>
> >>daniel
> >>
> >>----- Original Message ----- 
> >>From: "Adam Fisk" <afisk@speedymail.org>
> >>To: <struts-user@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


Mime
View raw message