Looks like you think it should be doing it conditionally.
The order of operations is.
Request Page A --> Always sets "backUrl" to "/initA.do" in session -->
Render JSP Page to User --> User clicks link --> Requests Page B --> Same
session so "backUrl" is still "/initA.do" --> Render Page B --> User sees
backUrl is NOT NUL
Note that you are always setting the "backUrl" to "/initA.do" whenever you
request page A. If you would visit page B without viewing page A you would
get "backUrl is NULL".
If you want to set it conditionally you'll have to do it in the action class
of /initA.do. In whatever class is mapped to "/initA.do" in your
struts-config.xml file do something like this.
class ActionA extends org.apache.struts.action.Action
{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse
response)
throws java.lang.Exception
{
request.setAttribute("backURL", "/initA.do");
return mapping.getForward("mapping to B");
}
}
-----Original Message-----
From: Gaet [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 11, 2006 10:33 AM
To: Mailing List Struts
Subject: 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
****************************************************************************
This email may contain confidential material.
If you were not an intended recipient,
Please notify the sender and delete all copies.
We may monitor email to and from our network.
****************************************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]