aspose file tools*
The moose likes Servlets and the fly likes Share data between jsp and servlet without using request or session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Share data between jsp and servlet without using request or session" Watch "Share data between jsp and servlet without using request or session" New topic
Author

Share data between jsp and servlet without using request or session

Somesh Chitturi
Greenhorn

Joined: Jan 31, 2009
Posts: 11
I am wondering if there is a way we can pass data between jsp and servlet without using either session, or passing the values as hidden parameters in request.
Michael Cropper
Ranch Hand

Joined: Sep 30, 2009
Posts: 137
Can you give an example of what this would be used for?

It is possible to POST information to a servlet from a HTML/JSP page using AJAX without actually leaving the page the user is on. For example, click on the link "add 1" on a HTML page, and AJAX could intercept this via "onClick()" and send the information to a servlet to process this.

Is that the kind of thing you are looking at?
Somesh Chitturi
Greenhorn

Joined: Jan 31, 2009
Posts: 11
Thanks for the reply. I need to pass an time stamp or some unique id from, jsp to servlet without using session or request. The solution you gave will not work for me, because if the user does view source the id will be visible for him. I don't want any one to see the unique id. I can't use session it makes my application session dependent which I don't want.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Somesh Chitturi wrote:I can't use session it makes my application session dependent which I don't want.

Why?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Michael Cropper
Ranch Hand

Joined: Sep 30, 2009
Posts: 137
For a user to be able to view a unique ID within the source code does not make your application any more vulnerable, nor does it give any sensitive information away to the user. The unique ID is a reference to all of the sensitive data which will be stored in a DB somewhere.

I cannot see any issues with showing a unique ID in the source code....
Somesh Chitturi
Greenhorn

Joined: Jan 31, 2009
Posts: 11
Bear Bibeault wrote:
Somesh Chitturi wrote:I can't use session it makes my application session dependent which I don't want.

Why?


If user opens the same jsp in two tabs and if I use session to pass my unique id to servlet, the id in the first tab will be overwritten which leads to some confusion in the servlet.
Somesh Chitturi
Greenhorn

Joined: Jan 31, 2009
Posts: 11
Michael Cropper wrote:For a user to be able to view a unique ID within the source code does not make your application any more vulnerable, nor does it give any sensitive information away to the user. The unique ID is a reference to all of the sensitive data which will be stored in a DB somewhere.

I cannot see any issues with showing a unique ID in the source code....


The unique id here is not a DB id but something like a timestamp which helps me to retrive some data from the session which I stored with name as sometext+(timestamp/unique id) into session.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Somesh Chitturi wrote:
Bear Bibeault wrote:
Somesh Chitturi wrote:I can't use session it makes my application session dependent which I don't want.

Why?


If user opens the same jsp in two tabs and if I use session to pass my unique id to servlet, the id in the first tab will be overwritten which leads to some confusion in the servlet.

And this is a likely scenario that prevents you from using sessions? I'd say not.
Michael Cropper
Ranch Hand

Joined: Sep 30, 2009
Posts: 137
So what you are actually looking to do is be able to have two unique sessionID's for when a user has the same web app open in two tabs.

Try going on to Hotmail with two tabs open and logging in with different accounts on each tab - it doesn't work. Since the sessions are at the browser level and not the tab level.

There may be a way to create a unique ID and store in a DB / continually running java file on the server, although this seems like a very complex way of accomplishing the task. ie, how would you know when to invalidate the unique ID so it can be used by someone else? (after a certain time?).

This is about where my level of knowledge ends though...
Somesh Chitturi
Greenhorn

Joined: Jan 31, 2009
Posts: 11
Bear Bibeault wrote:
Somesh Chitturi wrote:
Bear Bibeault wrote:
Somesh Chitturi wrote:I can't use session it makes my application session dependent which I don't want.

Why?


If user opens the same jsp in two tabs and if I use session to pass my unique id to servlet, the id in the first tab will be overwritten which leads to some confusion in the servlet.

And this is a likely scenario that prevents you from using sessions? I'd say not.


As I mentioned in my comment above, I need this unique id(value which I want to pass to servlet) to retrieve some data from session, for which this identifier is part of name. If the unique id is overwritten I might retrieve a different object than which I am supposed to.
Somesh Chitturi
Greenhorn

Joined: Jan 31, 2009
Posts: 11
So what you are actually looking to do is be able to have two unique sessionID's for when a user has the same web app open in two tabs.


Not two unique session IDs but something like a timestamp which varies.

Try going on to Hotmail with two tabs open and logging in with different accounts on each tab - it doesn't work. Since the sessions are at the browser level and not the tab level.


Yes, this is the reason I am avoiding session to pass the unique id which will be overwritten if user opens in a tab.

There may be a way to create a unique ID and store in a DB / continually running java file on the server, although this seems like a very complex way of accomplishing the task. ie, how would you know when to invalidate the unique ID so it can be used by someone else? (after a certain time?).

This is about where my level of knowledge ends though...


I will try that route, if I run into a problem you guys are always there . Thanks a lot, I really appreciate your help. Thanks.
Rudy Gireyev
Ranch Hand

Joined: May 03, 2011
Posts: 39
Hi Somesh.

I don't know if this will be of any help or not, but if you use the request.setAttribute(timestamp) in your JSP, then it might work, if I understood your problem. When the user opens a new tab/window it will then be a new request and hence your servlet will get a new timestamp. Since request attributes are one shot deals.

HTH
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1220
    
    1

Hi Somesh

I think you can use application scope to set and use variables in Servlet and JSP

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Share data between jsp and servlet without using request or session