You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lance <la...@marketpipe.com> on 2007/04/25 09:47:26 UTC

Re: Response already committed

The response is considered committed once you have written to the 
outputstream (perhaps in a jsp).
Once a response has been comitted, you can not redirect or forward etc.

The best solution is to redirect before you write anything to the output 
stream, sometimes this is not possible.
Another slightly dodgy solution (I have used this) is to write a script 
tag to the outputstream.

<script>
    document.location.href = 'loginPage.do';
</script>

You can check if the response has been comitted using response.isComitted()
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletResponse.html 


Gajbhe, Laxman (Contractor) wrote:
> Hi,
>  
>  I've following global result to handle authentication.
>
> <global-results> 
>
> <result name="login" type="chain">
>
> <param name="actionName">login</param>
>
> <param name="namespace">/home</param>
>
> <param name="method">input</param>
>
> </result>
>
> ...
>
> </global-results>
>
> For most part this works fine. The only problem with this is that on
> session timeout, it opens up the login page nested inside the page being
> requested.
>
> For example if there are tabs on the page and if the user clicks on one
> of the tab when the session is timed out, it opens the login page as a
> content of the current tab.
>
> So, I figured changing result type to 'redirect-action' should fix it.
> Now it started complaing about "response already commited" when I am
> logging in first time itself.
>
> Here is the snippets of my interceptor code:
>
> public String intercept(final ActionInvocation invocation) throws
> Exception {
>
> final SessionMap session = (SessionMap)
> ActionContext.getContext().get(ActionContext.SESSION);
>
> final SessionSecureUser user = (SessionSecureUser)
> session.get(Constants.AUTHORIZED_KEY);
>
> if (user == null) {
>
> return Action.LOGIN;
>
> }
>
> Could you please suggest where I could be going wrong with this?
>
> thanks for your help!
>
> Laxman
>
>  
>
>  
>
> This e-mail and its attachments are confidential and solely for the
> intended addressee(s). Do not share or use them without Fannie Mae's
> approval. If received in error, contact the sender and delete them.
>
>  
>
>   


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


Re: Response already committed

Posted by Lance <la...@marketpipe.com>.
I just re-read your email... pls ignore my last reply.
My s2 knowlege is very minimal but chances are that an ajax action is 
triggered by an XmlHttpRequest. In this case, you don't want to redirect 
this request. What you want to do is send something (javascript) back  
to the calling page telling it to redirect itself. I'm sure one of the 
s2 users out there have some suggestions here.

Lance.

Lance wrote:
> It sounds like you are still redirecting after the repsponse is comitted.
> If you attempt to do this on tomcat, an error will be reported then 
> instead of redirecting, the redirect page will be included at the end 
> of the current page.
>
> Gajbhe, Laxman (Contractor) wrote:
>> Lance,
>>
>>  Thanks for your help! I am now able to redirect the page except on
>> timeout it still opens right under the clicked tab instead of as a full
>> login page.
>>
>>  It seems even the redirected page gets displayed as an ajax content if
>> the original request was triggered by the ajax action.
>>
>>  Can you think any way to handle this?
>>
>>
>> Thanks again!
>>
>> Laxman
>>
>>
>> This e-mail and its attachments are confidential and solely for the
>> intended addressee(s). Do not share or use them without Fannie Mae's
>> approval. If received in error, contact the sender and delete them.
>>
>>
>> -----Original Message-----
>> From: Lance [mailto:lance.semmens@marketpipe.com] Sent: Wednesday, 
>> April 25, 2007 3:47 AM
>> To: Struts Users Mailing List
>> Subject: Re: Response already committed
>>
>> The response is considered committed once you have written to the 
>> outputstream (perhaps in a jsp).
>> Once a response has been comitted, you can not redirect or forward etc.
>>
>> The best solution is to redirect before you write anything to the output
>>
>> stream, sometimes this is not possible.
>> Another slightly dodgy solution (I have used this) is to write a 
>> script tag to the outputstream.
>>
>> <script>
>>     document.location.href = 'loginPage.do';
>> </script>
>>
>> You can check if the response has been comitted using
>> response.isComitted()
>> http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRespo
>> nse.html
>>
>> Gajbhe, Laxman (Contractor) wrote:
>>  
>>> Hi,
>>>  
>>>  I've following global result to handle authentication.
>>>
>>> <global-results>
>>> <result name="login" type="chain">
>>>
>>> <param name="actionName">login</param>
>>>
>>> <param name="namespace">/home</param>
>>>
>>> <param name="method">input</param>
>>>
>>> </result>
>>>
>>> ...
>>>
>>> </global-results>
>>>
>>> For most part this works fine. The only problem with this is that on
>>> session timeout, it opens up the login page nested inside the page
>>>     
>> being
>>  
>>> requested.
>>>
>>> For example if there are tabs on the page and if the user clicks on
>>>     
>> one
>>  
>>> of the tab when the session is timed out, it opens the login page as a
>>> content of the current tab.
>>>
>>> So, I figured changing result type to 'redirect-action' should fix it.
>>> Now it started complaing about "response already commited" when I am
>>> logging in first time itself.
>>>
>>> Here is the snippets of my interceptor code:
>>>
>>> public String intercept(final ActionInvocation invocation) throws
>>> Exception {
>>>
>>> final SessionMap session = (SessionMap)
>>> ActionContext.getContext().get(ActionContext.SESSION);
>>>
>>> final SessionSecureUser user = (SessionSecureUser)
>>> session.get(Constants.AUTHORIZED_KEY);
>>>
>>> if (user == null) {
>>>
>>> return Action.LOGIN;
>>>
>>> }
>>>
>>> Could you please suggest where I could be going wrong with this?
>>>
>>> thanks for your help!
>>>
>>> Laxman
>>>
>>>  
>>>
>>>  
>>>
>>> This e-mail and its attachments are confidential and solely for the
>>> intended addressee(s). Do not share or use them without Fannie Mae's
>>> approval. If received in error, contact the sender and delete them.
>>>
>>>  
>>>
>>>       
>>
>>
>> ---------------------------------------------------------------------
>> 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
>>
>>   
>
>
> ---------------------------------------------------------------------
> 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

Posted by Lance <la...@marketpipe.com>.
It sounds like you are still redirecting after the repsponse is comitted.
If you attempt to do this on tomcat, an error will be reported then 
instead of redirecting, the redirect page will be included at the end of 
the current page.

Gajbhe, Laxman (Contractor) wrote:
> Lance,
>
>  Thanks for your help! I am now able to redirect the page except on
> timeout it still opens right under the clicked tab instead of as a full
> login page.
>
>  It seems even the redirected page gets displayed as an ajax content if
> the original request was triggered by the ajax action.
>
>  Can you think any way to handle this?
>
>
> Thanks again!
>
> Laxman
>
>
> This e-mail and its attachments are confidential and solely for the
> intended addressee(s). Do not share or use them without Fannie Mae's
> approval. If received in error, contact the sender and delete them.
>
>
> -----Original Message-----
> From: Lance [mailto:lance.semmens@marketpipe.com] 
> Sent: Wednesday, April 25, 2007 3:47 AM
> To: Struts Users Mailing List
> Subject: Re: Response already committed
>
> The response is considered committed once you have written to the 
> outputstream (perhaps in a jsp).
> Once a response has been comitted, you can not redirect or forward etc.
>
> The best solution is to redirect before you write anything to the output
>
> stream, sometimes this is not possible.
> Another slightly dodgy solution (I have used this) is to write a script 
> tag to the outputstream.
>
> <script>
>     document.location.href = 'loginPage.do';
> </script>
>
> You can check if the response has been comitted using
> response.isComitted()
> http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRespo
> nse.html 
>
>
> Gajbhe, Laxman (Contractor) wrote:
>   
>> Hi,
>>  
>>  I've following global result to handle authentication.
>>
>> <global-results> 
>>
>> <result name="login" type="chain">
>>
>> <param name="actionName">login</param>
>>
>> <param name="namespace">/home</param>
>>
>> <param name="method">input</param>
>>
>> </result>
>>
>> ...
>>
>> </global-results>
>>
>> For most part this works fine. The only problem with this is that on
>> session timeout, it opens up the login page nested inside the page
>>     
> being
>   
>> requested.
>>
>> For example if there are tabs on the page and if the user clicks on
>>     
> one
>   
>> of the tab when the session is timed out, it opens the login page as a
>> content of the current tab.
>>
>> So, I figured changing result type to 'redirect-action' should fix it.
>> Now it started complaing about "response already commited" when I am
>> logging in first time itself.
>>
>> Here is the snippets of my interceptor code:
>>
>> public String intercept(final ActionInvocation invocation) throws
>> Exception {
>>
>> final SessionMap session = (SessionMap)
>> ActionContext.getContext().get(ActionContext.SESSION);
>>
>> final SessionSecureUser user = (SessionSecureUser)
>> session.get(Constants.AUTHORIZED_KEY);
>>
>> if (user == null) {
>>
>> return Action.LOGIN;
>>
>> }
>>
>> Could you please suggest where I could be going wrong with this?
>>
>> thanks for your help!
>>
>> Laxman
>>
>>  
>>
>>  
>>
>> This e-mail and its attachments are confidential and solely for the
>> intended addressee(s). Do not share or use them without Fannie Mae's
>> approval. If received in error, contact the sender and delete them.
>>
>>  
>>
>>   
>>     
>
>
> ---------------------------------------------------------------------
> 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
>
>   


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


RE: Response already committed

Posted by "Gajbhe, Laxman (Contractor)" <la...@fanniemae.com>.
Lance,

 Thanks for your help! I am now able to redirect the page except on
timeout it still opens right under the clicked tab instead of as a full
login page.

 It seems even the redirected page gets displayed as an ajax content if
the original request was triggered by the ajax action.

 Can you think any way to handle this?


Thanks again!

Laxman


This e-mail and its attachments are confidential and solely for the
intended addressee(s). Do not share or use them without Fannie Mae's
approval. If received in error, contact the sender and delete them.


-----Original Message-----
From: Lance [mailto:lance.semmens@marketpipe.com] 
Sent: Wednesday, April 25, 2007 3:47 AM
To: Struts Users Mailing List
Subject: Re: Response already committed

The response is considered committed once you have written to the 
outputstream (perhaps in a jsp).
Once a response has been comitted, you can not redirect or forward etc.

The best solution is to redirect before you write anything to the output

stream, sometimes this is not possible.
Another slightly dodgy solution (I have used this) is to write a script 
tag to the outputstream.

<script>
    document.location.href = 'loginPage.do';
</script>

You can check if the response has been comitted using
response.isComitted()
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRespo
nse.html 


Gajbhe, Laxman (Contractor) wrote:
> Hi,
>  
>  I've following global result to handle authentication.
>
> <global-results> 
>
> <result name="login" type="chain">
>
> <param name="actionName">login</param>
>
> <param name="namespace">/home</param>
>
> <param name="method">input</param>
>
> </result>
>
> ...
>
> </global-results>
>
> For most part this works fine. The only problem with this is that on
> session timeout, it opens up the login page nested inside the page
being
> requested.
>
> For example if there are tabs on the page and if the user clicks on
one
> of the tab when the session is timed out, it opens the login page as a
> content of the current tab.
>
> So, I figured changing result type to 'redirect-action' should fix it.
> Now it started complaing about "response already commited" when I am
> logging in first time itself.
>
> Here is the snippets of my interceptor code:
>
> public String intercept(final ActionInvocation invocation) throws
> Exception {
>
> final SessionMap session = (SessionMap)
> ActionContext.getContext().get(ActionContext.SESSION);
>
> final SessionSecureUser user = (SessionSecureUser)
> session.get(Constants.AUTHORIZED_KEY);
>
> if (user == null) {
>
> return Action.LOGIN;
>
> }
>
> Could you please suggest where I could be going wrong with this?
>
> thanks for your help!
>
> Laxman
>
>  
>
>  
>
> This e-mail and its attachments are confidential and solely for the
> intended addressee(s). Do not share or use them without Fannie Mae's
> approval. If received in error, contact the sender and delete them.
>
>  
>
>   


---------------------------------------------------------------------
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