• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session Lost from JSP to action

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Dpk arora", please check your private messages for an important administrative matter.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you trying to get those values from session? at Action or in firstTime.jsp?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Session is the right approach, putting that code into JSP is not.
 
Dpk arora
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bt i am not having any other option.....

 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dpk did you check your private messages??
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic