aspose file tools*
The moose likes Struts and the fly likes Session Lost from JSP to action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Session Lost from JSP to action" Watch "Session Lost from JSP to action" New topic
Author

Session Lost from JSP to action

Dpk arora
Greenhorn

Joined: Feb 17, 2010
Posts: 4
Hi guys.

I am trying to set some values in session in my JSP using
request.getSession().setAttribute(USER_ID_KEY, userId);
request.getSession().setAttribute(COMPANY_ID_KEY, companyId);

Then using anchor tag i am calling my action(Struts 1.2). In my action i am trying to retrieve these values using

HttpSession session =request.getSession(false);
a= (String)session .getAttribute("userId");
b=(String)request.getSession().getAttribute("companyId");

and i am gettign null value for String a & b. I tried to print session id on both places and found that both the IDs are different. It means the new session is getting created in action. But i neither used "session.invalidate()" nor "session.timeout()".

So why this new session is getting created in action?

My struts-config.xml is like

<action path="/abc" scope="request" type="myPkg.struts.action.myAction">
<forward name="FIRSTTIME" path="/firstTime.jsp" />
</action>

I also tried scope="session" but didnt succeed in that also.

I am facing this issue from last 2 days bt i didnt gt any solution. Please help me. Any kind of help is appreciated.

Thanks & Regards,
DPAK.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60975
    
  65

"Dpk arora", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bhagat Singh Rawat
Ranch Hand

Joined: Apr 04, 2009
Posts: 93
Where are you trying to get those values from session? at Action or in firstTime.jsp?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why are you setting any session values in the JSP at all? That kind of behavior should live in Java code, not JSP code.
Bhagat Singh Rawat
Ranch Hand

Joined: Apr 04, 2009
Posts: 93
David Newton wrote:Why are you setting any session values in the JSP at all? That kind of behavior should live in Java code, not JSP code.



Absolutely correct David!!! Whatever scope you will declare there in the struts config file, it will behave like that, you need not to write any extra code to maintain session.
Dpk arora
Greenhorn

Joined: Feb 17, 2010
Posts: 4
Thaks for your replies..

@ Bhagat Singh Rawat
In Action I am trying to retrieve those values.

@ David Newton
Actually this is the part of requirements. I need to use these values across the application. So on the first page i need to set these values and use it anywhere in the application.
So, I think session is the right approach to complete this requirement.right?

If you have any other idea by which i can fulfill this requirement please suggest.

Thanks,
Dpak
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Session is the right approach, putting that code into JSP is not.
Dpk arora
Greenhorn

Joined: Feb 17, 2010
Posts: 4
Bt i am not having any other option.....

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Dpk did you check your private messages??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Lost from JSP to action