• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to keep track of time in a JSP page

 
Sankalp Dam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in great trouble and need your help.


I have a JSP page that takes input from the user and when the user presses SAVE the action passes it to a servlet from where it makes a webservice call to oracle CRM server with data and Jsession ID(Jsession id is used to authenticate the user).The JSessionID expiers after 10 mins of inactivity.

Now it can happen that user may press the save button after 10 min.In that case the JSESSIONID would expire and server would throw an exception, which would be visibe to the user.


What i want is to fire dummy query to server form my JSP page after every 9 mins so that the Jsessionid does not expire.If the user presses the SAVE button then the control shud pass to the servlet and if the user does not do anything till 9 mins then JSP should automatically fire a dummy query so as to kee the jsession id ALIVE.Now how do i keep the track of time in my JSP page..

How would i Know that 9 mins have passed.

PLZZ HELPP...I asked in other forum also, ppl suggested tht i shud learn ajax and jquery.....but i dont know and i hav to implement it very soon.There is always an other way..I hope this forum helps me out....
Plzz help...Its a humble request

Regards,
Sankalp

 
Greg Charles
Sheriff
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sankalp, welcome to JavaRanch!

While you should learn about jQuery and Ajax if you're going to be a web developer, you probably can solve this problem with a bit of JavaScript. At least that's what they say here: http://www.coderanch.com/t/293717/JSP/java/JSP-Page-alive
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want the session to expire after 10 minutes, why do you have it set to 10 minutes?
 
Sankalp Dam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:Hi Sankalp, welcome to JavaRanch!

While you should learn about jQuery and Ajax if you're going to be a web developer, you probably can solve this problem with a bit of JavaScript. At least that's what they say here: http://www.coderanch.com/t/293717/JSP/java/JSP-Page-alive


Thanks Greg, This is what I am looking for.
But I did not understand in that code, where is that part where they are sending request to server after every X mins.
Also, I have a 3-4 line code in JAVA which will send dummy query to the server to keep the Jession ID Active....But I dont now how do i put that Java Code in the JavaScript...or if i palce outside the Javascript in the same JSP page how do I refer it to.
KINDLY ADVICE
 
Sankalp Dam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:If you don't want the session to expire after 10 minutes, why do you have it set to 10 minutes?


I did not set It.Oracle set it.My Java Application integrates with Oracle CRM ON Demand.When I supply credential to CRM, it returns me a JSession IDb which has to be use with every request send thereafetr.The JSession ID times out after 10 mins of Inactivity.So I need to fire dummmy query to CRM Server to keep the JSessioid from Expiring.

Kindly provide your valuable input.I am into Oracle CRM and not much into Java, so its little bit difficult for me.I have joined this forum in the hope that simple solution can be provided by someone
 
Greg Charles
Sheriff
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sankalp Dam wrote:
But I did not understand in that code, where is that part where they are sending request to server after every X mins.


I believe it's this part:


That's sending a request for an image file every hour. You'd have to modify it to make it nine minutes.

Sankalp Dam wrote:
Also, I have a 3-4 line code in JAVA which will send dummy query to the server to keep the Jession ID Active....But I dont now how do i put that Java Code in the JavaScript...or if i palce outside the Javascript in the same JSP page how do I refer it to.


If the image src attribute was set to the URL of a servlet, then of course the requests would handled by a servlet, and there you could call your three of four lines of Java. That seems a bit of a kludge to me, but you're looking for a solution you can implement quickly and without a full understanding of the underlying technology ... which is a perfect definition of a kludge.
 
Sankalp Dam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:



If the image src attribute was set to the URL of a servlet, then of course the requests would handled by a servlet, and there you could call your three of four lines of Java. That seems a bit of a kludge to me, but you're looking for a solution you can implement quickly and without a full understanding of the underlying technology ... which is a perfect definition of a kludge.



I have to pass the session id also while invoking the servlet.So i retreived Jsessionid in variable 'var' in the Javascript from the form.Now hoe do i pass in the url

/myservlet?js=var
In this case string var will be passed whereas i want to pass the value contained in the var
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you make a request back to the same web app, the session will be renewed automatically. You don't need to include any session id.
 
Stefan Evans
Bartender
Posts: 1782
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to do that would be to

1 - allow cookies. The JSessionId should be automatically propogated by use of a session cookie
2 - with all urls, use the method response.encodeURL(urlString). That will automatically add the JSessionId parameter if required.
 
Sankalp Dam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:If you make a request back to the same web app, the session will be renewed automatically. You don't need to include any session id.


Well Jsessioind id s used to authenticate the user.So if that is missing with the request, the server wont entertain the request.Oracle says that with every request that you send to us, include your Jsession id so that we can recognize you.As soon as the data along with sessioid hits the CRM Server, the server checks for the valadity of the Jsessionid. If it has `t expied the same Jsessioid is renewed for next 10 mins, so this is how this JSessionid can be used again and again.

I am thinking of using this code in my JSP PAGE:

<script type="text/javascript">
var sessid=document.forms["crm"]["hiddenjss"].value;
// poll interval in ms
var pollInt = 10000;

// setup the interval poll
window.setInterval("jQuery.ajax({url:'/myservlet',data:sessid,type='POST'})", pollInt);

</script>

IS THIS CODE OK???
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, missed the part about cookies being turned off.
 
Greg Charles
Sheriff
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regardless of cookies being on or off, a servlet can retrieve the session through the request, and HttpSession has a getId() method. Wouldn't that work?
 
Sankalp Dam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sankalp Dam wrote:
Bear Bibeault wrote:If you make a request back to the same web app, the session will be renewed automatically. You don't need to include any session id.


Well Jsessioind id s used to authenticate the user.So if that is missing with the request, the server wont entertain the request.Oracle says that with every request that you send to us, include your Jsession id so that we can recognize you.As soon as the data along with sessioid hits the CRM Server, the server checks for the valadity of the Jsessionid. If it has `t expied the same Jsessioid is renewed for next 10 mins, so this is how this JSessionid can be used again and again.

I am thinking of using this code in my JSP PAGE:

<script type="text/javascript">
var sessid=document.forms["crm"]["hiddenjss"].value;
// poll interval in ms
var pollInt = 10000;

// setup the interval poll
window.setInterval("jQuery.ajax({url:'/myservlet',data:sessid,type='POST'})", pollInt);

</script>

IS THIS CODE OK???



Can someone please assist me....I badly want a peice of code....I am so tensed that I cannot think of something else.
I am a CRM admin and i dont have much experties on Java....i never knew that Java would get so complicated at the end......
KINDLY HELP
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic