java中如何上传图片文件

发布于 2024-11-03 01:59:47 字数 105 浏览 1 评论 0原文

我想通过单击图像来上传图像文件,就像我们在 Java 的 facebook 中看到的那样。 谁能建议我如何做到这一点?我正在使用 GlassFish Server,Netbeans ide 6.8

I want to upload an Image File on click of the Image as we see in facebook in Java.
Can anyone suggest me the way to do it? I am using GlassFish Server,Netbeans ide 6.8

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心奴独伤 2024-11-10 01:59:47

查看 Jakarta Commons FileUpload。

Look into Jakarta Commons FileUpload.

独闯女儿国 2024-11-10 01:59:47

简单文件上传代码: 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 问题

Simple file upload code: 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. Pure java applet implementation - JumpLoader
  2. I would recommend: Javascript+Java. Here is a stackoverflow.com question.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文