这是我使用servlet和jsp上传文件的java代码:
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。
1条答案
按热度按时间bihw5rsg1#
检查apache的fileupload,更确切地说是fileitem#getname()。