如何用java上传图像文件

kuuvgm7e  于 2021-07-09  发布在  Java
关注(0)|答案(2)|浏览(414)

我想上传一个图片文件,点击图片,就像我们在facebook上看到的那样。有人能告诉我怎么做吗?我使用的是glassfish服务器,netbeanside6.8

2o7dmzc5

2o7dmzc51#

简单文件上传代码: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;
  }
%>
...........

纯java小程序实现-jumploader
我推荐:javascript+java。这里有一个stackoverflow.com的问题。

bpzcxfmw

bpzcxfmw2#

查看雅加达公共文件上传。

相关问题