How to get the full path of the filename from html using the java servlet


This question already has an answer here:

  • How to upload files to server using JSP/Servlet? 12 answers

I want to get full path of file name from html.


 <form action="test" method="post">
  <p>Enter Name : <input type="text" name="name"></p>
  <p>Choose file : <input type="file" name="fName"></p>
  <p><input type="submit" value="Enter"></p>

I wrote above code in html and I retrieved file name from servlet.

 String fName = request.getParameter("fName");

but it got only file name, didn't get full path of file name. I found some site that show to get full path of file name. It's code as follow.

   <form action="test" method="post" enctype="multipart/form-data">

when using above code, name and fName are null value return.

How to get full path of file name? Please explain me! Thanks.

It depend on the browser. Some browsers send the full path but this is considered a security risk because it might tell thing about the client system, so most modern browsers just send the filename. Why do you need the full path??