0

The following is the JSP code.

How the code can be modified such that the location of the file that is selected using "Browse" option must be passed to a java program named new.java

Please advise.

<form action="abc.jsp" method="post" enctype="multipart/form-data" name="form1" id="form1"> 

        Upload File:
       <input name="file" type="file" id="file"><br><br>
       <input type="submit" name="Submit" value="Submit"/><br><br>
       <input type="reset" name="Reset" value="Reset"/>   
 </form>

The html code above shows only the name of the file and not the location. And I dont even know how to pass the name of the file to java code itself.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
LGAP
  • 2,365
  • 17
  • 50
  • 71
  • 1
    See also [How to upload file in JSP/Servlet?](http://stackoverflow.com/questions/2422468/how-to-upload-files-in-jsp-servlet/2424824#2424824) – BalusC Sep 06 '10 at 15:57

1 Answers1

3

In your action you must specify a servlet/jsp that handles the multipart request. It better be a Servlet (JSP is meant for presentation, not processing).

So, we have a Servlet (public class NewServlet extends HttpServlet), with a doPost(request, response) method. At that point you can use commons-fileupload to handle the incoming file. Here is the user guide with a lot of code to just copy-paste.

The servlet tutorial is a good place to start.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • am a beginner in Java... and not familiar with servlet and doPost methods. Kindly let me know any other way to solve the issue. – LGAP Sep 06 '10 at 14:08
  • if you want to work with servlets and JSPs (they are two sides of the same coin) (and it seems you need to), you'd need to read about them. I updated my answer with the tutorial. – Bozho Sep 06 '10 at 14:14