aspose file tools*
The moose likes Servlets and the fly likes Uploading an Image File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Uploading an Image File " Watch "Uploading an Image File " New topic
Author

Uploading an Image File

Bipul Bhattacharjee
Greenhorn

Joined: Jul 19, 2001
Posts: 4
Hi,
I am working for uploading an image file.It is uploading on the same machine but not working on net..It is not getting the path of the server while copying and path not found exception occurs.I am not using Orilly's Multi Part Classes.
I am giving my codes for your reference..

Can anyone can guide me?
Thanks in advance.
Bipul Bhattacharjee.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
This code is so loaded with problems it is hard to know where to start. You appear to be trying to create a page that mixes up HTML code characters with binary image data. This is NOT the way HTML pages with images are created. Look at the code of any HTML page that has images in it - you will see an <img> tag for each image. The browser fetches the binary image data as a separate operation. Any servlets book will have material on how to get a servlet to serve up images.
A second problem is that you are using instance variables all over the place. Remember that a servlet object may be handling requests from more than one browser at the same time - you can't use instance variables for data that is unique to a particular request.
Bill

------------------
author of:
Bipul Bhattacharjee
Greenhorn

Joined: Jul 19, 2001
Posts: 4
Thanks a lot Bill.
But my problem is that I am writing servlet code which lets the client to upload an image file from the client's harddisk to my web server.
Any more suggestion.
Thanks a lot.
Bipul
Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
Hi Bill,
I am new to servlets and jsp.when u say that avoid instance variables,do you mean to say that all the variables must be declared inside the doGet() method.
Thanks for your help.
Subbu
Originally posted by William Brogden:
A second problem is that you are using instance variables all over the place. Remember that a servlet object may be handling requests from more than one browser at the same time - you can't use instance variables for data that is unique to a particular request.
Bill



Subbu
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
Bipul -
If you are expecting binary data from the Post, why are you opening a FileInputStream on the servlet side? Jason Hunter's web site has a widely used file-upload package - look at
http://www.servlets.com/
==============
Instance variables like:
FileInputStream fis=null;
FileOutputStream fos=null;;
PrintWriter out;
String sourcefile="";
String source="";
String extn="";
will be visible to every users request so the potential for mixup is incredible. You should be using variables created inside doGet or doPost - these local variables are visible only to the Thread that creates them. If you need to preserve values between request/response cycles, thats what sessions are for.
Bill
Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
Hi Bill,
thanks for ur reply.
i have written a servlet which right now uses 4 instance variables.i cannot declare theses variables inside the doGet or doPost methods because, these variables are accessed by other methods in the servlet.what do i do now?is there a way out?
Subbu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Uploading an Image File