Please have a look at he following code
JSP
<%--
Document : index
Created on : Nov 27, 2012, 1:11:48 PM
Author : Yohan
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<div>
<div>Content for New Div Tag Goes Here</div>
<p> </p>
<p> </p>
<p> </p>
<div>
<form method="post" action="FileSelector" enctype="multipart/form-data">
Select File: <input type="file" name="location"/></div>
<br>
<input type="submit" value="Submit"/>
</form>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
</body>
</html>
Servlet
package importWizard;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
public class FileSelector extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException
{
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException
{
PrintWriter pw = response.getWriter();
File location = (File)request.getParameter("location");
pw.write(location);
}
}
As you can see, I am unable to send the file from JSP to Servlet. I don't need to send the file, but at least the complete location of the file (It is only sending the file name). How can I send the file or the complete location of the file from JSP to servlet?