File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in OutputStream

 
Arun Somasundaram
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 489
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic