File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes cannot get session variables
Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "cannot get session variables
" Watch "cannot get session variables
" New topic
Author

cannot get session variables

rajshkhr pandey
Ranch Hand

Joined: Oct 14, 2009
Posts: 35
Hello to all.

I am developing a shopping cart application in which I use to store some session variables in session object.
The problem arise when I integrate paypal with my application.
I use following code to redirect to the paypal's site

When I return from the paypal's site my all session variables are nulled.
I read somewhere that "response.sendRedirect()" method kills the session.
So, please somebody suggest me the alternatives of this method so that I cannot lose my session.

Thank You
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

rajshkhr pandey wrote:When I return from the paypal's site my all session variables are nulled.


session cant be share between two different applications

rajshkhr pandey wrote:
I read somewhere that "response.sendRedirect()" method kills the session.

No. with in an application,you can access the session
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

The JSESSIONID which is your session identifier is normally transmitted back and forth from the browser to the server using a cookie. If cookies are turned off at the browser, this (the JSESSIONID) needs to be transmitted via the url (this technique is called url rewriting). To achieve this, there are 2 methods in the HttpServletResponse api - encodeURL and encodeRedirectURL. You should treat all urls (links and form posts urls) with these methods and it would determine if url rewriting is needed and encode the url appropriately.

You can use a FF plugin like Live HTTP Headers which will show you all the artifacts that goes in a request (and all that comes back in a response) - cookies, headers etc.

Does your application work normally otherwise without any need for url rewriting? I believe sites like paypal redirect the user back to your website after processing payments. Examine the difference between normal requests and the redirect that comes from the payment site (using the tool I mentioned earlier). You should be able to figure it out yourself from there.

cheers,
ram.

rajshkhr pandey
Ranch Hand

Joined: Oct 14, 2009
Posts: 35
Thanks for you reply,

seetharaman venkatasamy wrote:
session cant be share between two different applications

I am not sharing session between my application and paypal
I am only doing
1. storing my required session variables at my side in session object (eg. Item Name,Item Number, User Id etc).
2. Redirecting to the paypal's website.
3. Logs in payapl's website, it returns me a token
4. I use that token for further check out.

The problem arise between step three and four, where when I want to retrieve my session variable it shows null value.


seetharaman venkatasamy wrote:
No. with in an application,you can access the session

but I cannot access it and I think because of response.sendRedirect()
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

rajshkhr pandey wrote:
seetharaman venkatasamy wrote:
No. with in an application,you can access the session

but I cannot access it and I think because of response.sendRedirect()


did you test?write a small program to test
rajshkhr pandey
Ranch Hand

Joined: Oct 14, 2009
Posts: 35
seetharaman venkatasamy wrote:
did you test?write a small program to test

Yes I have made a small program and used response.sendRedirect() method and surprisingly I am getting my session variables.

So it might be problem in setting session variable in my application
I will search it out.
Thanks.
rajshkhr pandey
Ranch Hand

Joined: Oct 14, 2009
Posts: 35
Thanks for your efforts to solve my problem.

I have solved my problem. It was session which gets expires between I return from the paypal's site so I set its max time to expire by the function setMaxInactiveInterval() in javax.servlet.http.HttpSession object and I get all my session varaibles that I have stored.

Thanks Again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot get session variables