0

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

4

2 回答 2

1

查看 Jakarta Commons FileUpload。

于 2011-04-25T07:03:31.653 回答
1

简单文件上传代码: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小程序实现——JumpLoader
  2. 我会推荐:Javascript+Java。这是一个stackoverflow.com 问题
于 2011-04-25T07:06:03.167 回答