tags:

views:

40

answers:

1

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.

+3  A: 

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
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
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
Thanks Bozho! I will learn from the given tutorial
LGAP