aspose file tools*
The moose likes JSP and the fly likes Exception raised while uploading excel file in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Exception raised while uploading excel file in jsp" Watch "Exception raised while uploading excel file in jsp" New topic
Author

Exception raised while uploading excel file in jsp

sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
Hi,

I want to upload excel file from jsp. I have used all the basic things in jsp file such as
1) form type as post
2) enctype="multipart/form-data"
3) action redirects to servlet.

While reading excel file using jexcel im getting below exception, but same code is working fine when I pass parameter as file(tested using local java class).
From this I conclude, the inputstream is having some problem.
Please shed some light to solve this problem.





For java examples,ebooks,interview questions,visit this blog
http://periodicupdates.blogspot.com/
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18902
    
    8

sri ramvaithiyanathan wrote:but same code is working fine when I pass parameter as file(tested using local java class).


When you do a file upload that way, the request is not just the contents of the file. It contains other information, such as the name of the file being uploaded and the name of the parameter used for the file upload. So just reading the entire input stream from the response isn't the right thing to do.

Now if you just copy the entire input stream to a file on the server, that will "work" in the sense that it doesn't throw any exceptions. However I think you'll find that the result isn't the same as what you uploaded from the browser. And I suspect that comparison wasn't one of your tests.

So what you have to do is to read the request's input stream and parse out all of the parts which are described by the multipart/form-data specification. However that's too tedious for most programmers, so mostly people use Apache's FileUpload package to take care of all of that. Also it doesn't make sense to do that in a JSP, since the purpose of JSP is to produce HTML to be sent to the browser. You should be doing that in a servlet, or in some other Java class, before forwarding to a JSP to report on the result of the file upload, or whatever the response is supposed to be.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception raised while uploading excel file in jsp