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 Problem in OutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem in OutputStream" Watch "Problem in OutputStream" New topic
Author

Problem in OutputStream

Arun Somasundaram
Ranch Hand

Joined: Jul 25, 2006
Posts: 63
Hi this from Arun,

The image file is not created when the servlet is executed.
Here is the code for HTML




Here is the code for Servlet



But when the standalone program with the same code is executed , the Image file is created successfully.

And here is the code for standalone program.




I think the problem lies in the follwing part of the code

OutputStream o = new FileOutputStream("hello.gif");

Any one have come across this problem.If so what is the problem and how can it be rectified.


Arun.V.Somasundaram
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The problem is that you are creating the file in the 'current directory', but chances are that the location is not where you think it is. In each case, try printing the value of new File(".");
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

As far as I know, reading in files over a web request is not that straight forward. This is so because the request contains additional information (like content-length, encoding etc) and the entire information (including the actual data stream) is available as one big chunk in the request's input stream. That roughly is what is meant by 'multipart/form-data'.

The servlet api has no direct support for reading in multipart form data. You can consider using apache's file upload package.

ram.
Arun Somasundaram
Ranch Hand

Joined: Jul 25, 2006
Posts: 63
Thanks Mr.David O'Meara for your suggesstion,as you said the file is created in the different directory i.e, in the Tomcat installation directory.One doubt I have i.e, practically the file has to be created in the current directory but why it doesn't happens.Instead it has been created in the Tomcat installation directory.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by ramprasad madathil:
As far as I know, reading in files over a web request is not that straight forward. This is so because the request contains additional information (like content-length, encoding etc) and the entire information (including the actual data stream) is available as one big chunk in the request's input stream. That roughly is what is meant by 'multipart/form-data'.

The servlet api has no direct support for reading in multipart form data. You can consider using apache's file upload package.

ram.

This is correct.
The file is streamed up to the server as part of multi-part message.
That message has to be parse before you can start working with the uploaded file.

See: http://faq.javaranch.com/view?FileUpload


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in OutputStream