0

I've got a really simple problem.

I'm not able to read the file name from the (jsp) file-chooser in servlet. Normally I can get any input data with request.getParameter("name");

Can anybody tell me the shortest way please? this is my code:

<form method="post" enctype="multipart/form-data" action="ImportServlet"> 
<td> <input type="file" size=20 name="fname"> </td> 
<td> <input type="Submit" value="Upload"> </td> </form> 

thanks

user1844505
  • 1,259
  • 2
  • 10
  • 14

2 Answers2

1

use this

request.getParameter("fname")
Manish Nagar
  • 1,038
  • 7
  • 12
0
  MultipartRequest multiPartFile =new MultipartRequest(request,"targetDirectory");
  Enumeration files = multiPartFile.getFileNames();
  while(files.hasMoreElements() ){
      String fileName = (String)files.nextElement();
      System.out.println(fileName);
      String fileSystemName= multiPartFile.getFilesystemName(fileName );
      System.out.println(fileSystemName);
    }
Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
  • No, my problem is to get this f...ing target directory. The User want to upload a file and gives the filename (path) of the file and I want to get the Path of the filename with the full path. I dont have a target directory because I will save the data in a mysql database. This all will be on localhost. – user1844505 Dec 26 '12 at 19:38
  • @user1844505 target directory is the directory name on the server side where you want to upload the file. I you want to upload in current directory then use `.`. – Yogendra Singh Dec 26 '12 at 19:41
  • the is not a really "upload", all things are on localhost. – user1844505 Dec 26 '12 at 19:46
  • @user1844505 Doesn't matter. You are uploading the file from your local browser to your localhost server. – Yogendra Singh Dec 26 '12 at 19:49
  • So, I will describe my problem again. I want to save From File To Database, there it is neccessary to get the full path, so I can not give a "targetDirectory" hardcoded. I hope you understand me – user1844505 Dec 26 '12 at 20:02
  • the problem is I've no access to the file/path, which was choosen with the filechooser. – user1844505 Dec 26 '12 at 20:06
  • @user1844505 Just try: `MultipartRequest multiPartFile =new MultipartRequest(request,".");` – Yogendra Singh Dec 26 '12 at 21:10