0

I am using Glassfish Server.I have seen the apache file upload to solve it...but i want to implement it in glassfish server.

image.html

<form action="" method="post" enctype="multipart/form-data">
    Select a file:
    <input type="file" name="first" id="first" />
    <br />
    <input type="button" name="button" value="upload" id="button" />
    <p id="test"></p>
   <img src='Unknown.png'  id="profile_img" height="200px" width="150px" />
</form>

test.js

$(document).ready(function() {
    var filepath= $("#first");
    $('#button').click(function() {
        $.ajax({
            type:       "post",
            url:        "imageservlet",
            data:       "user="+filepath.val(),
            success:    function(msg) {
                            $("#profile_img").attr('src',msg);
                            $("#test").html(msg).fadeIn("fast");
                        }
        });
    });
});

imageservlet.java

String user=request.getParameter("user");
out.print(user);

the output is file name not full path.

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
Deep
  • 461
  • 5
  • 9
  • 17
  • This is browser specific. Related: [How to get full file path in Firefox?](http://stackoverflow.com/questions/81180/how-to-get-the-file-path-from-html-input-form-in-firefox-3/3374408#3374408) – BalusC Mar 21 '11 at 15:36
  • can to do give me example to do server side coding in jsp.but I am using glassfish not apache server. – Deep Mar 25 '11 at 18:02
  • That link was not for decoration :) Click and read it. It contains in turn another links as well. – BalusC Mar 27 '11 at 05:00

1 Answers1

3

Browsers handle this differently. Not all browsers will let you access the full path name (which makes perfect sense from a security standpoint).

DA.
  • 39,848
  • 49
  • 150
  • 213
  • 1
    It also makes perfect sense from a "This control is designed to upload a file" standpoint. It isn't a tool to describe where a file exists on the client's hard disk. That information is useless in the context of the WWW. – Quentin Mar 16 '11 at 16:19