user1844505
user1844505

Reputation: 1287

jsp read filename from servlet impossible?

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

Upvotes: 0

Views: 1033

Answers (2)

Manish Nagar
Manish Nagar

Reputation: 1046

use this

request.getParameter("fname")

Upvotes: 1

Yogendra Singh
Yogendra Singh

Reputation: 34367

  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);
    }

Upvotes: 0

Related Questions