Currently, my JSP calls an EJB service that returns a File object. I then display the contents of the file in the JSP. The file is just a regular text file generated by a logger. I have a refresh button that calls the same service and re-displays the latest contents of the file.
The specs were changed such that the users wants the refresh to be automatic (every 15 seconds, for example) but they do not want the overhead associated with calling the service, downloading the whole file, and displaying the contents. The display should be dynamic such that the updated portion will dynamically be "tailed" or appended to the existing contents in the JSP, much like the tail option when viewing files in Unix. The file could be several megabytes in size and they do not want to see the view going blank for a long time while the JSP tries to download and open the entire logfile.
My question is, is it possible to achieve this using pure JSP (and how) or should I be looking at something else such as Applets?
Here's one approach you could use:
2) The request would cause the backend to determine and retrieve the new content in the file (you'll need to maintain the file state in either the session or with parameters that get passed back and forth).
First, it sounds like the whole idea of the EJB returning a File object isn't a really great design. A better idea might be to have the EJB completely hide the fact that it is logging to a file. When a new log message comes in, have the EJB log it to a file and save the message to a data structure that saves the last x log messages. Then, have the EJB return the last x log messages from the data structure when asked.
Also keep in mind that using Files and File IO in EJBs goes against the EJB spec. However, using them has worked in all the application servers I have used. Keep in mind that some of the higher facilities provided by the EJB spec can break systems relying on files or file IO (i.e. distributed servers, transaction processing, etc.)
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Sep 17, 2001
Thank you Bear and Nathan.