This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Please excuse me if I am posting this in a wrong forum.
I have a requirement of opening an existing excel sheet at a specific location on my local system on the click of a button on my jsp page.
I have written a onClickSaveExcel() which does the job of creating and writing the excel sheet on a local path using the Apache POI API.
What I really want is to open this excel sheet in a pop-up(with open,save,cancel) on the call of the onClickSaveExcel().
Can someone please guide me with the approach needed to perform the above task.
A JSP page can't open files that are on your local machine. You need to stream the file from the server to the browser. See the "Simple Stream" example in http://faq.javaranch.com/java/CodeBarnServlets for how to do that. Be sure to set the content type correctly for XLS files.
I wouldn't use the above code. But the point is hopefully clear, you need to set the content type and the content disposition. You need to make sure to set the correct content type so that the client knows what kind of file it can expect and thus pick the correct application for it. If you want to serve it as 'save as' or 'open in', then you need to set the content disposition to 'attachment'. If you want to serve it inline in a web page, then you need a HTML <iframe> or <object> pointing to the file(servlet) in question which sets content disposition to 'inline'.
I dont know what Mr.Bauke find terrible here...Its just sample code to get the idea of how to proceed.Its according to my requirment and I have removed some part which was not required.Definitely it needs to alter as per the requirment.It will be great if Bauke suggest some good code.
Joined: Oct 08, 2006
You already posted a topic about that before and I already answered in there.
Under each those if/else blocks are unnecessary, those String200/String10 classes are smells, using the sun.* package is a bad practice, encoding it base64 seems superfluous, not buffering the stream is memory hogging and setting the content length +1000 is asking for trouble in client side.