这是我用来使用servlet&上传文件的java代码。 JSP:
public class Upload extends HttpServlet {
private static final long serialVersionUID = 1L;
public void init() throws ServletException {
System.out.println(this.getClass().getName());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//boolean MultipartRequest;
//String PrintWriter;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
MultipartRequest multipartRequest = new MultipartRequest(request, "/home/hadoop/Desktop");
out.println("succcesfully uploaded");
copyFromLocal("/home/hadoop/Desktop/", "/vamsi/Desktop");
}
public void destroy() {
System.out.println(this.getClass().getName());
}
}
Jsp代码:
<html>
<body>
<form action="UploadFile" method="post" enctype="multipart/form-data">
Selectfile:
<input type="file" name="filename">
<br/>
<input type="submit" value="Upload">
</form>
</body>
</html>
如何获取我上传的文件的名称...我想使用该文件名将该文件复制到HDFS。