File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Lost from JSP to action

 
Dpk arora
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Dpk arora", please check your private messages for an important administrative matter.
 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you trying to get those values from session? at Action or in firstTime.jsp?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Session is the right approach, putting that code into JSP is not.
 
Dpk arora
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bt i am not having any other option.....

 
Ankit Garg
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dpk did you check your private messages??
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic