Results 1 to 13 of 13
  1. #1
    schenker is offline Member
    Join Date
    Apr 2010
    Posts
    9
    Rep Power
    0

    Default uploaded image wont display if i change filename

    I wrote a servlet to upload and display an image file. That is, from the jsp page, i select and upload a file. This file will be be processed (checked for correct file format, size and then copied to a new location) by my servlet and then displayed on the browser. It works fine.

    But the peculiar problem is that while im selecting, if i were to change the file name, say file1.jpg to file_1.jpg or some other, the file will not be displayed on the browser anymore.

    I find that the renamed file is available, yet it wont display. I will have to quit my browser, re-run the jsp and select the renamed file for it to display.

    Pls point me in the right direction, im terribly frustrated. Thanks!

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Do you get any exceptions/error messages?

  3. #3
    schenker is offline Member
    Join Date
    Apr 2010
    Posts
    9
    Rep Power
    0

    Default

    No errors at all. That's the frustrating factor. One of my guesses is image file name shouldn't contain space character. Currently I'm testing this out.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Did you check your server logs and console?

  5. #5
    schenker is offline Member
    Join Date
    Apr 2010
    Posts
    9
    Rep Power
    0

    Default

    Yes, very thoroughly. None gave the slightest clue. I'm trying to isolate this problem to find the root cause. I will update when i find out the problem.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default

    I'm not entirely clear on the sequence of events here.
    What is the selection you're doing (what is it on)?
    Where is it?
    Where do you change the filename?

  7. #7
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    Quote Originally Posted by schenker View Post
    But the peculiar problem is that while im selecting, if i were to change the file name, say file1.jpg to file_1.jpg or some other,
    You shouldn't change the file name untill it is uploaded. It is all because the OS local file system rules...

    Quote Originally Posted by schenker View Post
    the file will not be displayed on the browser anymore
    just disappears or what? Look more closely maybe you just overwrite it?
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  8. #8
    schenker is offline Member
    Join Date
    Apr 2010
    Posts
    9
    Rep Power
    0

    Default

    This is the sequence of events:

    Basically, im trying to upload an image file.

    I have a jsp page, say page1.jsp and a servlet.
    1. from page1.jsp i have a button which if i clicked on, it will have the regular window's dialog box for me to select a file.
    2. While selecting any file, if you were to right-click on the file name, you will be given the option to delete, rename, open etc. This is where i rename the file, say from 'pic1.gif' to 'upload image.gif'.
    3. After renaming the file and selecting the file for upload, my servlet performs the background actions.
    4. The servlet attemps to read the file and copies to a new destination folder.
    5. The file will then be read from its new location and displayed.
    ---

    The sequence of events roll out well, except if i were to change the filename (as stated in 2 above) then the image will not displayed.
    Its puzzling, 'cos when i check the destination folder, the file (with the renamed filename) is copied there. I can even double-click on the file and view the image, but its just not showing up.

    Currently what im doing is, instead of making the servlet display the image, im sending the filename as a value to my jsp page and let the javascript take over from there. Still testing out...

  9. #9
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Looks like the wrong file name is being used at some point.
    What does not display mean? Do you get a blank page?
    Perhaps your code is swallowing exceptions so they don't get logged in the server logs?
    Perhaps you aren't checking the correct log files to see if there is an exception?

  10. #10
    schenker is offline Member
    Join Date
    Apr 2010
    Posts
    9
    Rep Power
    0

    Default

    I got the page right, but its showing the icon of a missing image. I combed thru' the log files; no exception thrown.

    Still trying to find the answers to some questions...
    I hope my findings will serve to be useful to all others who are working with servlets and image file uploads.

  11. #11
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Check the source of the page and see what url it's using to try and locate the image.

  12. #12
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    Quote Originally Posted by schenker View Post
    But the peculiar problem is that while im selecting, if i were to change the file name, say file1.jpg to file_1.jpg or some other, the file will not be displayed on the browser anymore.

    I find that the renamed file is available, yet it wont display. I will have to quit my browser, re-run the jsp and select the renamed file for it to display.
    How do you test your upload? Is it a local HDD volume? Maybe the problem is totally logical error... Maybe your jsp just overwrites your previous image with a null one (a non existing image you try to upload with its manual name input)... Check out all file paths your app uses... If problem stays report it...
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  13. #13
    schenker is offline Member
    Join Date
    Apr 2010
    Posts
    9
    Rep Power
    0

    Default

    After several tests, i figured out the problem. The file upload is actually working well. I even checked on the copied file, its perfectly copied to its destination BUT the problem is, the servlet will have to built and run again so that the copied file gets placed into the Build folder within netbeans. Lost? Ok this is what happens:

    Initial directory structure, (other folders are not shown for simplicity):

    1.web/images/somefile.gif <----somefile.gif is the copied file from client's PC
    2. Build/web/images/

    client uploads somefile.gif. The servlet successfully copies it into destination folder, however if i were to type, "http:\\localhost\images\somefile.gif" browser will report 404 error.
    Only upon build and run, the copied files will be placed into Build folder, ie;

    Build/web/images/somefile.gif

    Once the copied file is placed in the build folder by the building process, this file will be available.

    At least the problem has been identified now.

    Thanks everyone for your help.

Similar Threads

  1. Replies: 0
    Last Post: 04-19-2009, 06:38 PM
  2. how to display uploaded jpeg in jsp(its urgent)
    By shaktish in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 02-17-2009, 02:52 PM
  3. uploaded image not shown
    By java_srinivasan in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-05-2008, 12:40 PM
  4. Replies: 5
    Last Post: 06-06-2008, 09:31 AM
  5. [SOLVED] Last line in JTextArea wont display
    By Chris.Brown.SPE in forum Advanced Java
    Replies: 5
    Last Post: 04-11-2008, 01:52 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •