This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Uploading an Image File

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic