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
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.
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.
subject: Exception raised while uploading excel file in jsp