aspose file tools*
The moose likes JSP and the fly likes Database update of opened file(doc or pdf) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Database update of opened file(doc or pdf)" Watch "Database update of opened file(doc or pdf)" New topic
Author

Database update of opened file(doc or pdf)

Rumi Harry
Greenhorn

Joined: Nov 25, 2008
Posts: 13
Hello,
I need to add the following functionality:

-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: 42273
    
  64
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.


Ping & DNS - my free Android networking tools app
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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).


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Rumi Harry
Greenhorn

Joined: Nov 25, 2008
Posts: 13
Thanks for your ideas.I will work on them.

Regards
RumiHarry
Rumi Harry
Greenhorn

Joined: Nov 25, 2008
Posts: 13
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.


Following is the code if that helps:










String val = request.getParameter("f");

//val = "material_6,117.xls";

String contentType = pageContext.getServletContext().getMimeType(val);
out.println("contentType" + contentType );




// Stream the image
BufferedInputStream in = null;
try
{




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);

ServletOutputStream rado = response.getOutputStream();


byte[] buffer = new byte[4 * 1024];

int data;
while((data = in.read(buffer)) != -1)
{


rado.write(buffer, 0, data);
}
rado.flush();
}
catch(Exception e)
{
out.println("Where is the issue"+e);
e.printStackTrace();
return;
}
finally
{
try
{
in.close();
}
catch(Exception ee)
{
ee.printStackTrace();
}
}

%>



Please advise.

Thanks
RumiHarry

[ December 15, 2008: Message edited by: Rumi Harry ]
[ December 15, 2008: Message edited by: Rumi Harry ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database update of opened file(doc or pdf)