• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please suggest how to display partial output from time to time using JSP.

 
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am calling a unix script from Java.Now this script runs for around 10 minutes and returns messages(echo statements). I am able to read these messages as soon as they are sent using a Buffered Reader using Java Class.
The problem is when is doing the same in JSP.Because I want to display the response as soon as a line is displayed and then the next response when next line is read(say after few seconds or minutes). But my JSP page will render only when the entire script runs. How can this be done using JSP.Please advice.

Since this Unix script runs for long time say 10 minutes, I want user to be displayed messages in between indicating the progress so far.(as messages recieved line by line from Unix script). But how to display partial output using JSP and then after period of time display the next output. I do not know AJAX.Is there a way of doing it using JSP?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. You will need to use Ajax.
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.but before AJAX technology came, how were developers doing this?
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually since i dont know ajax, and i have to do this in limited time, i wanted to do this without AJAX.I read on internet that setting partial output as session variable and refeshing the page every second can help.but how exactly to do this i am confused.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, before Ajax, one needed to refresh the whole page in order to effect any changes. If you want to use no JavaScript or Ajax, that's the approach you will have to use. You cannot just add parts the to page incrementally -- you need to redo the whole thing.

Not the best user experience, be warned.
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please tell about this approach too? I still have some confusion.

->My JSP page will have buffered Reader reading line by line and displaying this Variable.
--> JSP page will have auto refresh. for every second.

But still the JSP page will be rendered after the entire buffer reader is read? suppose from buffer reader i am reading line by line 1 to 10 at intervals of 1 sec, despite the auto refresh, the JSP page will be rendered at once only after completion of 10 seconds.

Then how to make this approach work.Please suggest if this is possible and i am misssing out something above?
thanks


 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Possibly you might find pushlets applicable in this use case.
Its quite an old article, and I never used them myself, but I think it fits your scenario.

 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks all.even Flush serves the purpose.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica. Shiralkar wrote:thanks all.even Flush serves the purpose.



Can you tell me how did you achieved this? I have been trying it since long. Please help me. Thanks in advance.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really, the correct way to do this is with Ajax. Refreshing the whole JSP page -- or screwing around with flushing on the server -- is an outdated, fragile, and unnecessarily complicated approach. Why not use modern technology as it is supposed to be used?
 
kunal kabi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Really, the correct way to do this is with Ajax. Refreshing the whole JSP page -- or screwing around with flushing on the server -- is an outdated, fragile, and unnecessarily complicated approach. Why not use modern technology as it is supposed to be used?



It seems like AJAX is the best way. Can you tell me how do we need to publish the output from servlet and display it line by line in sync with the console output using AJAX.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is the servlet getting the text that needs to be displayed?

With HTTP, you get a text response for every request. If the display needs to continually be updated, you can fire off a request at intervals to get the latest text to display.


 
kunal kabi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet is getting the data using inputstream. and data need to be displayed as soon as it arrives to servlet in div section in jsp continuously. Please Suggest me.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not going to be possible unless you limit your audience to modern browsers where technologies like web sockets or Meteor or other constant-connection technologies can be used.

If you are supporting legacy browsers, polling is as good as it's going to get.
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Servlet is getting the data using inputstream. and data need to be displayed as soon as it arrives to servlet in div section in jsp continuously. Please Suggest me.



Please try to do this using AJAX. That is the proper way.
reply
    Bookmark Topic Watch Topic
  • New Topic