File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes getting junk characters inside the excel sheet created from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getting junk characters inside the excel sheet created from servlet" Watch "getting junk characters inside the excel sheet created from servlet" New topic
Author

getting junk characters inside the excel sheet created from servlet

Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Hi,

I have created a submit button,on the click of which an excel report is created with the business data at a location on local hard drive.On click of submit,the file generated at hard disk location is proper with correct data.However,the requirement is to open that excel sheet on click of submit.The file when it opens on click of submit has junk characters inside it.

The servlet code is below:




The Jsp to which the request is dispatched is below:




The code that I am using to generate the submit button in servlet is :






How can I print the correct report like the one in the d:// location on click of Export Data button which opens the excel program?

Thanks in advance!

Regards
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41817
    
  62
JSPs are meant for textual output (like HTML); you can't use them for streaming binary data like XLS files. You'll need to use a servlet instead. (Also note that the code is streaming the file one byte at a time - which is very inefficient.)


Ping & DNS - my free Android networking tools app
Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Thanks for the reply!
I have replaced the jsp with servlet .






The servlet which replaced the jsp:






Now on click of submit I cannot open the xls.It gives error on loading error message:

Missing file: C:\Documents and setting\...\Desktop\css\style.css

Please help! I don't where I am going wrong

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41817
    
  62

This can't really be the code you're using, can it? You'd get a NullPointerException. It should be something like
Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Thanks a ton!

I can open the excel sheet correctly now



Many Thanks again!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting junk characters inside the excel sheet created from servlet