aspose file tools*
The moose likes Servlets and the fly likes get full path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

get full path

deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
how can we get full path of file that has been uploaded
code written in jsp
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3216
    
  49

If you mean getting the file path on the client's local file system, it's fortunately NOT possible.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
deep raj
Ranch Hand

Joined: Dec 11, 2009
Posts: 186
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
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3216
    
  49

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

Joined: Oct 26, 2006
Posts: 218
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

Joined: Dec 11, 2009
Posts: 186
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

Joined: Oct 26, 2006
Posts: 218
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

Joined: Dec 11, 2009
Posts: 186
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
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3216
    
  49

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

Joined: Oct 26, 2006
Posts: 218
F:/soft for xp/wall/MOTIVATIONAL/mot40a.jpg


Where is this location? On the server?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61624
    
  67

This is yet another duplicate post on this subject. Closed.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get full path