aspose file tools*
The moose likes Servlets and the fly likes Server side process Statements line by line display in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Server side process Statements line by line display in JSP" Watch "Server side process Statements line by line display in JSP" New topic
Author

Server side process Statements line by line display in JSP

Sreenivas Reddy.T
Greenhorn

Joined: Mar 28, 2011
Posts: 4
Hi All..


I have an requirement is like this, Servlet is processing some data for this it will take some time. For every second or minute i need display servlet process statements in jsp. Using AJAX it will appends total response at a time but i need append line by line message.

Thanks in Advance...

Regards
SreenivasReddy. T
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

the easiest I can think of is that the client has a JavaScript event makes an Ajax call every X seconds and either
1) the server sends the full list every time and the client replaces the local display with the data from the server (easier but problems if the data becomes large)
2) the client sends the timestamp (as determined by the server) of the last message update, the server responds with an updated timestamp and any new messages since the last update. The client appends the updated info to the page.
Sreenivas Reddy.T
Greenhorn

Joined: Mar 28, 2011
Posts: 4
Hi All,


When client side JavaScript event makes an Ajax call every X seconds to the same servlet, the same task should be executed repeatedly. But What i need exactly,,, call servlet only once,for this call servlet take few minutes.mean while i need to display message to user what ever process which is going in the servlet dynamically to jsp.

Example message in jsp:

File1 is processed successfully..........
File2 is processed successfully..........
File3 is processed successfully..........
..........................

..........................

File1000 is processed successfully..........


Thanks in Advance

Regards
Sreenivas Reddy. T
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

That's not going to happen easily. A single servlet invocation is not going to be able to have that sort of back-and-foth interaction.

What you can do is to have the first servlet kick off a back-ground thread to perform the lengthy operation, and then have Ajax kick off "progress check" requests that can synchronize with the working thread to determine what to report as done.

Otherwise, you'll have to make each "line" a separate serial request.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sreenivas Reddy.T
Greenhorn

Joined: Mar 28, 2011
Posts: 4
Hi


Can you write a sample code for your explanation. In my program am calling Servlet once Servlet is internally calling Thread class many times based on the files we are passed. Again this Thread class is calling another Thread class for dividing the records in the file.


Thanks in Advance

Regards
Sreenivas Reddy.T
 
 
subject: Server side process Statements line by line display in JSP