Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
    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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

get full path

 
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
 
Sheriff
Posts: 6429
1147
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • 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
Sheriff
Posts: 6429
1147
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • 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.
 
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
Sheriff
Posts: 6429
1147
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • 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?
 
Marshal
Posts: 67293
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is yet another duplicate post on this subject. Closed.
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!