Bookmark Topic Watch Topic
  • New Topic

get full path

 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Report post to moderator
how can we get full path of file that has been uploaded
code written in jsp
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4499
267
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Report post to moderator
If you mean getting the file path on the client's local file system, it's fortunately NOT possible.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Report post to moderator
if it is not possible then what i supply in file object like this
File f=new File("c/ima.doc"); it requir full path

and this object is created while i want to insert image into database
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4499
267
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Report post to moderator
amrita singhal wrote:if it is not possible then what i supply in file object like this
File f=new File("c/ima.doc"); it requir full path

A path like that may represent the file system on where the container is installed - not the file path on the client's file system.
For uploading a file from client, you may use something like Apache Commons Upload.

Moving to Servlets forum.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Report post to moderator
What if you have a hidden variable populated when the submit button is clicked before uploading the details to the server?

Well this again is Browser dependent where the full path is accessible in javascript by doing a .value on the file element. IE gives you complete path where as on executing the script on Firefox you will get the filename only without full path.

Try executing the below code on Internet explorer and on Firefox, you will see the difference


Why are you interested in the path on user's file system? Won't just the file name suffice?
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Report post to moderator
File f= new File()
in this when we supply the file name it shows error
that's why i want to know the full path



Devaka Cooray
"Apache Commons Upload. "
means?
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Report post to moderator
Check this:

Apache commons Upload

Also clearly specify what is your requirement,

Check what Devaka had said earlier in his post about using java.io.File.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Report post to moderator
actually i want to store image file in mysql
for this i used the following code

File imgfile = new File("F:/soft for xp/wall/MOTIVATIONAL/mot40a.jpg"); //line 1

FileInputStream fin = new FileInputStream(imgfile);
pstmt = conn.prepareStatement("update employee_personal set image=? where emp_id=13");
pstmt.setBinaryStream(1,fin,(int)imgfile.length());
pstmt.setInt(2,h);

int m1=pstmt.executeUpdate();


in LINE 1the full path is specified that why i asked for it
if there are any other way except this
then tell me please
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4499
267
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Report post to moderator
amrita singhal wrote:if there are any other way except this
then tell me please

Did you read that what I said about using a File object?
Have you tried using Apache commons Upload ?
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Report post to moderator
F:/soft for xp/wall/MOTIVATIONAL/mot40a.jpg


Where is this location? On the server?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is yet another duplicate post on this subject. Closed.
 
    Bookmark Topic Watch Topic
  • New Topic