Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Share data between jsp and servlet without using request or session

 
Somesh Chitturi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somesh Chitturi wrote:I can't use session it makes my application session dependent which I don't want.

Why?
 
Michael Cropper
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Somesh

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

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic