It's not a secret anymore!
The moose likes Servlets and the fly likes Get typed text in textarea on autorefresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Get typed text in textarea on autorefresh " Watch "Get typed text in textarea on autorefresh " New topic

Get typed text in textarea on autorefresh

robin singal
Ranch Hand

Joined: Jul 18, 2007
Posts: 102

I have used setHeader to set the refresh header. What happens is: i have a page with textarea when the user is typing in it and if the refresh happens i want the text to retain itself in text area. I am using only Servlets for the webapp.How can i achieve that.I have thought about partial page refresh

Is there any other solution. or if this is the solution how can i achieve that.


Life is short play hard.
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

Yeah, this is the problem with auto-refreshes on a page where the user is expected to interact.

You will have to use JavaScript. You could do away with the refresh header and use JavaScript's timout() function to schedule an event. When triggered the event would read the contents of the text field, re-query the URL, adding any data if got from the text field as a parameter. The response would then take the URL parameter, put it into the text box and display the rest of the page.

The user would still see an interruption in his writing and would get annoyed. This was popular in the 90s, before it got replaced with pre-cursors of AJAX that used frames to do auto-refreshes and JavaScript to transport data across frames.

The alternative is to use AJAX, which is also JavaScript based, to asynchronously poll the server for information, and when it gets an update, change the portions of the page that need to be changed. AJAX is the most popular way of doing things like this recently.

It is sorta covered in the JavaRanch Style Guide.
subject: Get typed text in textarea on autorefresh
It's not a secret anymore!