想要将文件上传到一个文件夹并获取上传的文件名

时间:2015-06-16 13:38:53

标签: java jsp hadoop file-upload hdfs

这是我用来使用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。

1 个答案:

答案 0 :(得分:0)

从Apache检查FileUpload,更确切地说FileItem#getName()