-Our client has a JSP/Struts based web application. -The screen/page in question has a bunch of links each opening up either a pdf,an excel file or a word doc. -The user could open up any document by simply clicking on it. - The client now wants the documents that are being accessed to be tracked-i.e every time a document is opened,the name of the document should be inserted into the database.Basically what the client needs is a mini document tracker.How do I accomplish this?I guess my challenge is to do tasks simultaneously-Allow the user to open the doc and insert a tracking record into the database without upsetting the previous step.
Please advise.
Thanks RumiHarry [ December 09, 2008: Message edited by: Rumi Harry ]
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
In that case, don't link to the files directly. Instead, link to a servlet that increments the counter, and which then streams the contents of the file to the browser. Here is an example of how to stream a file to the browser.
One thing to keep in mind is that there is positive way to know that someone opened (or even received an entire) document. Internet connections can die or timeout before a document is finished downloading, users may not have the necessary application (Work, Acrobat, etc..) on their machine to open it once they get it. Lastly, none of these applications make any kind of a call back to the web server to verify that the document has been opened.
The best you can do is track requests for the documents (using Ulf's advice).
Hello, I tried using the approach mentioned by Ulf.Although I am able to update the document related information into the database,I am not able to view the documents.I am experiencing two kinds of issues while viewing: a)Sometimes,I get a message that says that the file-either the file format of the .xls or pdf has changed or the file is corrupt thus rendering the file unviewable. b)I sometime get an java.IOException with a ClosedStream problem.
I have updated the web.xml file with the different MIME types for excel,pdf,word etc.The Application server I am using is Weblogic 8.1.
in = new BufferedInputStream(pageContext.getServletContext(). getResourceAsStream("/downloads/materials/"+val));
response.setContentType(contentType); out.println("Is the file displayed"); response.setHeader("Content-Disposition", " inline; filename=" + val); out.println("The new file name being displayed"+"/downloads/materials/" + val);