You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Da...@mhn.com on 2008/06/13 17:40:13 UTC
Response already committed when using ActionTag
I have a JSP that uses an ActionTag <s:action> to call a Struts 2 action
class directly from the JSP. But in the action class, the HTTP response
has already been committed. This makes it impossible for me to set cookies
from my action class.
I tested this by calling HttpServletResponse.isCommitted() is my execute()
method of my action class, and it returns true.
Is this a bug? Why is the response committed if the JSP hasn't finished
rendering?
--somePage.jsp--
<s:action name="someAction" executeResult="true"
ignoreContextParams="false" />
--struts.xml--
<action name="someAction" class="com.dev.MyAction" method="execute">
<result>/page.jsp</result>
</action>
--MyAction.java--
public String execute()
{
System.out.println("response.isCommitted() = " + response.isCommitted());
//this prints true
}
Thanks,
David
---------------------------------------------------------------------
This message, together with any attachments, is
intended only for the use of the individual or entity
to which it is addressed. It may contain information
that is confidential and prohibited from disclosure.
If you are not the intended recipient, you are hereby
notified that any dissemination or copying of this
message or any attachment is strictly prohibited. If
you have received this message in error, please notify
the original sender immediately by telephone or by
return e-mail and delete this message, along with any
attachments, from your computer. Thank you.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Response already committed when using ActionTag
Posted by Dave Newton <ne...@yahoo.com>.
My impression was that ActionComponent executed the action via an action proxy (although I'm looking at trunk).
But the <s:action...> tag is in a JSP page that will have already been writing, at which point I don't think you'd be able to modify the headers (I've never used response.reset, I don't know if that would help or not).
Dave
--- On Sat, 6/14/08, Jeromy Evans <je...@blueskyminds.com.au> wrote:
> From: Jeromy Evans <je...@blueskyminds.com.au>
> Subject: Re: Response already committed when using ActionTag
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Saturday, June 14, 2008, 10:01 PM
> David.W.Larson@mhn.com wrote:
> > Hi Jeromy, thanks for the respose.
> >
> > The response is already committed in the action class
> (before the Result is
> > executed). In the execute() method, the result of
> 'response.isCommitted()'
> > is true. So I think the response is committed even
> before getting to the
> > Result.
> >
> > According to J2EE documentation, when using
> > RequestDispatcher.include(rquest, response), you
> can't set headers in the
> > response, which means you can't set cookies.
> That's the problem I'm having
> > - I can't set a cookie in the action class called
> via s:action. So perhaps
> > that's what s:action does, it does an include.
> >
> >
> > David
> >
> Okay, that makes sense. I didn't think it did an
> include though as that
> was this tag's main distinction from the include tag
> (in that it invokes
> an action directly). But as you're already within a
> result (rendering
> JSP) perhaps the parent result has already prevented you
> from setting
> the headers?
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Response already committed when using ActionTag
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
David.W.Larson@mhn.com wrote:
> Hi Jeromy, thanks for the respose.
>
> The response is already committed in the action class (before the Result is
> executed). In the execute() method, the result of 'response.isCommitted()'
> is true. So I think the response is committed even before getting to the
> Result.
>
> According to J2EE documentation, when using
> RequestDispatcher.include(rquest, response), you can't set headers in the
> response, which means you can't set cookies. That's the problem I'm having
> - I can't set a cookie in the action class called via s:action. So perhaps
> that's what s:action does, it does an include.
>
>
> David
>
Okay, that makes sense. I didn't think it did an include though as that
was this tag's main distinction from the include tag (in that it invokes
an action directly). But as you're already within a result (rendering
JSP) perhaps the parent result has already prevented you from setting
the headers?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Response already committed when using ActionTag
Posted by Da...@mhn.com.
Hi Jeromy, thanks for the respose.
The response is already committed in the action class (before the Result is
executed). In the execute() method, the result of 'response.isCommitted()'
is true. So I think the response is committed even before getting to the
Result.
According to J2EE documentation, when using
RequestDispatcher.include(rquest, response), you can't set headers in the
response, which means you can't set cookies. That's the problem I'm having
- I can't set a cookie in the action class called via s:action. So perhaps
that's what s:action does, it does an include.
David
Jeromy Evans
<jeromy.evans@blu
eskyminds.com.au> To
Struts Users Mailing List
06/13/2008 10:04 <us...@struts.apache.org>
PM cc
Subject
Please respond to Re: Response already committed when
"Struts Users using ActionTag
Mailing List"
<user@struts.apac
he.org>
David.W.Larson@mhn.com wrote:
> I have a JSP that uses an ActionTag <s:action> to call a Struts 2 action
> class directly from the JSP. But in the action class, the HTTP response
> has already been committed. This makes it impossible for me to set
cookies
> from my action class.
>
> I tested this by calling HttpServletResponse.isCommitted() is my
execute()
> method of my action class, and it returns true.
>
> Is this a bug? Why is the response committed if the JSP hasn't finished
> rendering?
>
Struts2 ActionInvocations are not designed to be nested, but the
s:action tag attempts to do this. It works most of the time, but not all
Results can be executed within another page, and not pages can handle
changes to the ActionContext by the nest invocation. The Action tag is
quite dodgy for this reason but there is currently no better alternative
in S2.
The problem is your case is with the Result that was executed. I
presume it has executed a ServletRedirectResult which assumes it can
commit the response (and does). TilesResult also has the same problem.
Try a different Result type.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
This message, together with any attachments, is
intended only for the use of the individual or entity
to which it is addressed. It may contain information
that is confidential and prohibited from disclosure.
If you are not the intended recipient, you are hereby
notified that any dissemination or copying of this
message or any attachment is strictly prohibited. If
you have received this message in error, please notify
the original sender immediately by telephone or by
return e-mail and delete this message, along with any
attachments, from your computer. Thank you.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Response already committed when using ActionTag
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
David.W.Larson@mhn.com wrote:
> I have a JSP that uses an ActionTag <s:action> to call a Struts 2 action
> class directly from the JSP. But in the action class, the HTTP response
> has already been committed. This makes it impossible for me to set cookies
> from my action class.
>
> I tested this by calling HttpServletResponse.isCommitted() is my execute()
> method of my action class, and it returns true.
>
> Is this a bug? Why is the response committed if the JSP hasn't finished
> rendering?
>
Struts2 ActionInvocations are not designed to be nested, but the
s:action tag attempts to do this. It works most of the time, but not all
Results can be executed within another page, and not pages can handle
changes to the ActionContext by the nest invocation. The Action tag is
quite dodgy for this reason but there is currently no better alternative
in S2.
The problem is your case is with the Result that was executed. I
presume it has executed a ServletRedirectResult which assumes it can
commit the response (and does). TilesResult also has the same problem.
Try a different Result type.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org