0

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

lobster1234
  • 7,679
  • 26
  • 30
coder
  • 19
  • 1
  • 10

2 Answers2

1

Look into Jakarta Commons FileUpload.

Dave G
  • 9,639
  • 36
  • 41
1

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.
Community
  • 1
  • 1
zengr
  • 38,346
  • 37
  • 130
  • 192