Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting junk characters inside the excel sheet created from servlet

 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a ton!

I can open the excel sheet correctly now



Many Thanks again!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic