File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Problem accessing inputstream in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem accessing inputstream in servlet" Watch "Problem accessing inputstream in servlet" New topic

Problem accessing inputstream in servlet

Kalai Selvi
Ranch Hand

Joined: Jan 08, 2007
Posts: 45
I use a jsp to prompt the user to upload a file

Once this form is submitted, control goes to servlet, which does some manipulation and calls a java program passing the input stream.

In that java program, i try to read the file thus uploaded using the inputstream. It says file not found.

Is there any possibility of the stream getting lost at the point when i try to open the uploaded file?

Note: I am trying to upload an excel file and open the same, using jexcel api. When i call that last java program from a jsp it is working fine. When i changed my program flow and added a servlet, it is not working now.

Pleass help.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

You'd be much better off using an upload library.
We list some in the FileUpload FAQ

If, for some reason, you really want to implement this yourself, you'll want to keep in mind that you can either call getInputStream OR one of the methods that return parameters but not both. Once you call one of the latter methods, the servlet parses the input stream to get the parameters. Once parsed, it's no longer available to the getInputStream method.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
li bei

Joined: Jul 22, 2007
Posts: 20
See the jarkata common-fileupload lib.

I am sorry that my English is poor.If there is something wrong with my words,please tell me .Thank you very much.
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

How do you open an uploaded file? Do you use something like:


Verify that your file didn't get deleted or reminded in write in condition.

Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
I agree. Here's the link:
subject: Problem accessing inputstream in servlet
It's not a secret anymore!