LGAP
LGAP

Reputation: 2473

How to pass the location of file to Java code using JSP?

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.

Upvotes: 0

Views: 3049

Answers (1)

Bozho
Bozho

Reputation: 597392

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.

Upvotes: 3

Related Questions