想要上传一个文件到一个文件夹并上传文件名吗

wtzytmuj  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(407)

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

bihw5rsg

bihw5rsg1#

检查apache的fileupload,更确切地说是fileitem#getname()。

相关问题