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.
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
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
Author and all-around good cowpoke
Joined: Mar 22, 2000
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
Joined: Jun 22, 2001
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