【问题标题】:how to upload a image file in java如何在java中上传图片文件
【发布时间】:2021-07-15 00:46:54
【问题描述】:

我想在点击图像时上传图像文件,就像我们在 Java 中的 facebook 中看到的那样。 任何人都可以建议我这样做的方法吗?我正在使用 GlassFish Server、Netbeans ide 6.8

【问题讨论】:

    标签: java image-uploading


    【解决方案1】:

    查看 Jakarta Commons FileUpload。

    【讨论】:

      【解决方案2】:

      简单文件上传代码:JSP

      ..........
      <form action="upload.jsp"
        method="post" enctype="multipart/form-data">
      
        Select a file: 
        <input type="file" name="first" />
      
        <br />
        <input type="submit" name="button" value="upload" />
      
      </form>
      ..........
      
      The page processing request with file encoded:
      <%@page contentType="text/html;"%>
      
      <%@page import="java.util.Hashtable"%>
      <%@page import="javazoom.upload.MultipartFormDataRequest" %>
      
      ...........
      
      <%
        try {
          // decode source request:
          MultipartFormDataRequest data = 
             new MultipartFormDataRequest(request);
      
          // get the files uploaded:
          Hashtable files = data.getFiles();
      
          if (! files.isEmpty()) {
            // do something with collection of files uploaded;
            ........
          } else {
            throw new IllegalStateException("No files supplied");
          }
        } catch (RuntimeException error) {
      
          // set error flag in session:
          request.getSession().setAttribute("error", error);
      
          // throw its further to print in error-page:
          throw error;
        }
      %>
      ...........
      
      1. java applet implementation - JumpLoader
      2. 我会推荐:Javascript+Java。这是stackoverflow.com question

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-10-21
        • 2017-10-05
        • 1970-01-01
        • 2020-12-11
        • 2010-11-07
        • 2021-12-25
        相关资源
        最近更新 更多