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
Asked
Active
Viewed 5,235 times
2 Answers
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;
}
%>
...........
- Pure java applet implementation - JumpLoader
- I would recommend: Javascript+Java. Here is a stackoverflow.com question.