You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Gaet <ga...@free.fr> on 2006/01/11 17:32:44 UTC

Session Attribute strange behaviour

Hi the list,

I know this is not a struts question (unless there is a simpler solution
with struts :o))

My goal : Add a back button on each of my pages with the url from where the
user comes (or another url if it comes from a page at a deeper level)

So i code the following simple code :

Page A.jsp
----------

<% session.setAttribute("backUrl","/initA.do"); %>
<html:link href="/B.do">Go to B</html:link>


Page B.jsp
----------

<%
String backUrl = (String)session.getAttribute("backUrl");
if (backUrl != null){
    System.err.println("backUrl is NOT NULL");
} else {
    System.err.println("backUrl is NULL");
}
%>

And it always prints "backUrl is NOT NULL"...
Does somebody can explain me?

Thanks in advance!

Gaet'





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


Re: Session Attribute strange behaviour

Posted by Michael Jouravlev <jm...@gmail.com>.
On 1/13/06, Gaet <ga...@free.fr> wrote:
> Hi,
>
> Thanks Marcelo,
>
> For the back button of the browser I have disabled it because user does "tax declaration" on the web site.
> The problem with the back button of the browser is to handle the values typed by the user 3 pages ago...so if the user go back on this page, the form is empty...

This is what session scope is for. You can either use session-scoped
data and non-cachable pages, so when a user goes back the page is
reloaded with current data. Or if you use request scope, you should
allow for pages to be cached. Then when a user goes back, he would see
data from browser cache.

> so I prefer to forbid this action...(using javascript  : action.history.forward(1))

Prohibiting back button sucks, relying on it is foolish, there always
will be someone who clicks Ctrl+Left Arrow for going back. Javascript?
Can be turned off.

> Moreover I do not know if when the user press the back button, if the browser call back the JSP page or the struts action?

Depends on a browser. Opera prefers not to do this at all, maybe only
in SSL mode (?). They have explanation for this behavior, but I'd
prefer them to reload a page if it is marked non-cached. Technically,
cache and page history are two different things, so I can understand
Opera reasons. MSIE reloads a page if you mark response as either
"no-cache" or "no-store". Firefox does it if page is marked with
"no-store".

> but I would like to be able to redirect the user to the previous page by calling the appropriate struts action.

If redirecting is OK for you, it means that you have valid data
collected in session and your pages can be reloaded with no side
effects. Why would not you utilize redirect-after-post pattern, mark
pages as non-cachable and enable Back button? You will get the same
outcome but with standard means.

Michael.

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


Re: Session Attribute strange behaviour

Posted by Laurie Harper <la...@holoweb.net>.
Regarding what happens when the user presses the back button, you may 
find the info I just added to the wiki helpful:

http://wiki.apache.org/struts/BrowserBackAndSecurity

L.

Gaet wrote:
> Hi,
> 
> Thanks Marcelo,
> 
> For the back button of the browser I have disabled it because user does "tax declaration" on the web site.
> The problem with the back button of the browser is to handle the values typed by the user 3 pages ago...so if the user go back on this page, the form is empty...so I prefer to forbid this action...(using javascript  : action.history.forward(1))
> 
> Moreover I do not know if when the user press the back button, if the browser call back the JSP page or the struts action?
> 
> but I would like to be able to redirect the user to the previous page by calling the appropriate struts action.
> I would like to know how webmaster usually do this behaviour....
> TIA
> 
>  
>   ----- Original Message ----- 
>   From: Marcelo Morales 
>   To: Struts Users Mailing List 
>   Cc: Gaet 
>   Sent: Thursday, January 12, 2006 10:32 PM
>   Subject: Re: Session Attribute strange behaviour
> 
> 
>   Hello again
> 
>   On Jan 12, 2006, at 4:19 AM, Gaet wrote:
> 
>   > Thanks all for your reply!
>   >
>   > Michael : What are "navigation buttons"? an applet, a dhtml  
>   > framework? Have you a link? thanks
> 
>   He is questioning your requirement. It does not seem reasonable to  
>   put a link to the last page visited when the browser has a built-in  
>   "go back" button. I do press the back button ... a lot.
> 
>   >
>   > Shawn : Sorry but I always get "backUrl is NULL" and not "backUrl  
>   > is NOT NULL"...so as I think like you on the process, I wonder why  
>   > I get "backUrl is NULL"...Thanks
> 
>   Sorry, haven't look closely at his answer
> 
>   >
>   > Marcelo : the refere header will give me back the last visited page  
>   > i think or I want to retrieve the struts action that redirect to  
>   > this page...
> 
>   I used this long long time ago and... frankly ... I don't remember.  
>   Just try it and put your findings here or in the wiki. Also, if you  
>   use the referer remember it is browser-generated and, as a principle,  
>   you can't trust user input...
> 
>   >
>   > If you can help again...it would be great
>   >
>   > Thanks,
>   >
>   > Gaet'
>   >
> 
>   Regards
> 
>   Marcelo Morales
> 
>   ---------------------------------------------------------------------
>   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: Session Attribute strange behaviour

Posted by Gaet <ga...@free.fr>.
Hi,

Thanks Marcelo,

For the back button of the browser I have disabled it because user does "tax declaration" on the web site.
The problem with the back button of the browser is to handle the values typed by the user 3 pages ago...so if the user go back on this page, the form is empty...so I prefer to forbid this action...(using javascript  : action.history.forward(1))

Moreover I do not know if when the user press the back button, if the browser call back the JSP page or the struts action?

but I would like to be able to redirect the user to the previous page by calling the appropriate struts action.
I would like to know how webmaster usually do this behaviour....
TIA

 
  ----- Original Message ----- 
  From: Marcelo Morales 
  To: Struts Users Mailing List 
  Cc: Gaet 
  Sent: Thursday, January 12, 2006 10:32 PM
  Subject: Re: Session Attribute strange behaviour


  Hello again

  On Jan 12, 2006, at 4:19 AM, Gaet wrote:

  > Thanks all for your reply!
  >
  > Michael : What are "navigation buttons"? an applet, a dhtml  
  > framework? Have you a link? thanks

  He is questioning your requirement. It does not seem reasonable to  
  put a link to the last page visited when the browser has a built-in  
  "go back" button. I do press the back button ... a lot.

  >
  > Shawn : Sorry but I always get "backUrl is NULL" and not "backUrl  
  > is NOT NULL"...so as I think like you on the process, I wonder why  
  > I get "backUrl is NULL"...Thanks

  Sorry, haven't look closely at his answer

  >
  > Marcelo : the refere header will give me back the last visited page  
  > i think or I want to retrieve the struts action that redirect to  
  > this page...

  I used this long long time ago and... frankly ... I don't remember.  
  Just try it and put your findings here or in the wiki. Also, if you  
  use the referer remember it is browser-generated and, as a principle,  
  you can't trust user input...

  >
  > If you can help again...it would be great
  >
  > Thanks,
  >
  > Gaet'
  >

  Regards

  Marcelo Morales

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


Re: Session Attribute strange behaviour

Posted by Marcelo Morales <ma...@redcetus.com>.
Hello again

On Jan 12, 2006, at 4:19 AM, Gaet wrote:

> Thanks all for your reply!
>
> Michael : What are "navigation buttons"? an applet, a dhtml  
> framework? Have you a link? thanks

He is questioning your requirement. It does not seem reasonable to  
put a link to the last page visited when the browser has a built-in  
"go back" button. I do press the back button ... a lot.

>
> Shawn : Sorry but I always get "backUrl is NULL" and not "backUrl  
> is NOT NULL"...so as I think like you on the process, I wonder why  
> I get "backUrl is NULL"...Thanks

Sorry, haven't look closely at his answer

>
> Marcelo : the refere header will give me back the last visited page  
> i think or I want to retrieve the struts action that redirect to  
> this page...

I used this long long time ago and... frankly ... I don't remember.  
Just try it and put your findings here or in the wiki. Also, if you  
use the referer remember it is browser-generated and, as a principle,  
you can't trust user input...

>
> If you can help again...it would be great
>
> Thanks,
>
> Gaet'
>

Regards

Marcelo Morales

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


Re: Session Attribute strange behaviour

Posted by Gaet <ga...@free.fr>.
Thanks all for your reply!

Michael : What are "navigation buttons"? an applet, a dhtml framework? Have you a link? thanks

Shawn : Sorry but I always get "backUrl is NULL" and not "backUrl is NOT NULL"...so as I think like you on the process, I wonder why I get "backUrl is NULL"...Thanks

Marcelo : the refere header will give me back the last visited page i think or I want to retrieve the struts action that redirect to this page...

If you can help again...it would be great

Thanks,

Gaet' 
  ----- Original Message ----- 
  From: Michael Jouravlev 
  To: Struts Users Mailing List 
  Sent: Wednesday, January 11, 2006 6:27 PM
  Subject: Re: Session Attribute strange behaviour


  On 1/11/06, Gaet <ga...@free.fr> wrote:
  > Hi the list,
  >
  > I know this is not a struts question (unless there is a simpler solution
  > with struts :o))
  >
  > My goal : Add a back button on each of my pages with the url from where the
  > user comes (or another url if it comes from a page at a deeper level)

  Have you heard about browser navigation buttons?

  > So i code the following simple code :
  >
  > Page A.jsp
  > ----------
  >
  > <% session.setAttribute("backUrl","/initA.do"); %>
  > <html:link href="/B.do">Go to B</html:link>
  >
  >
  > Page B.jsp
  > ----------
  >
  > <%
  > String backUrl = (String)session.getAttribute("backUrl");
  > if (backUrl != null){
  >     System.err.println("backUrl is NOT NULL");
  > } else {
  >     System.err.println("backUrl is NULL");
  > }
  > %>
  >
  > And it always prints "backUrl is NOT NULL"...
  > Does somebody can explain me?

  Isn't it because you just set it on page A ?

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


Re: Session Attribute strange behaviour

Posted by Michael Jouravlev <jm...@gmail.com>.
On 1/11/06, Gaet <ga...@free.fr> wrote:
> Hi the list,
>
> I know this is not a struts question (unless there is a simpler solution
> with struts :o))
>
> My goal : Add a back button on each of my pages with the url from where the
> user comes (or another url if it comes from a page at a deeper level)

Have you heard about browser navigation buttons?

> So i code the following simple code :
>
> Page A.jsp
> ----------
>
> <% session.setAttribute("backUrl","/initA.do"); %>
> <html:link href="/B.do">Go to B</html:link>
>
>
> Page B.jsp
> ----------
>
> <%
> String backUrl = (String)session.getAttribute("backUrl");
> if (backUrl != null){
>     System.err.println("backUrl is NOT NULL");
> } else {
>     System.err.println("backUrl is NULL");
> }
> %>
>
> And it always prints "backUrl is NOT NULL"...
> Does somebody can explain me?

Isn't it because you just set it on page A ?

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


Re: Session Attribute strange behaviour

Posted by Marcelo Morales <ma...@redcetus.com>.
Hello
On Jan 11, 2006, at 12:32 PM, Gaet wrote:

> Hi the list,
>
> I know this is not a struts question (unless there is a simpler  
> solution
> with struts :o))
>
> My goal : Add a back button on each of my pages with the url from  
> where the
> user comes (or another url if it comes from a page at a deeper level)
>

Forget the session and use the referer header on the http request.

Yet, I wonder how that is going to work in redirect-after-post.

Regards

Marcelo Morales


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