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

2 Answers 2

1

Look into Jakarta Commons FileUpload.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.