|
3.1.1: 2012-03-29 | ||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
See:
Description
| Class Summary | |
|---|---|
| FileUpload | Objects of this class are used to handle file upload from browsers using the standard mechanism described in RFC1867. |
| FileUpload.SectionHeaders | This class contains information extracted from the section headers for a form field or file upload field. |
| FileUpload.UploadStatus | This class contains information about the read status on the ServletInputStream |
| FileUploadProgress | Objects of this class holds information about the progress of an upload. |
| UploadedFile | Objects of this class can be used to get information about an uploaded file and save the file to a directory in the filesystem. |
| Exception Summary | |
|---|---|
| UploadAbortedException | |
This package contains classes for handling file uploads from a browser using the standard described in RFC1867.
A standard design consists of three JSP pages:
-- index.jsp
<%@ page import="net.sf.basedb.clients.web.fileupload.*" %>
<%
int progress_id = FileUpload.getNextProgressId();
%>
<html>
<head>
<title>Upload file</title>
<script language="JavaScript">
function beginUpload()
{
window.open('progress.jsp?progress_id=<%=progress_id%>');
document.forms['upload'].submit();
}
</script>
</head>
<body>
<form action="upload.jsp?progress_id=<%=progress_id%>"
method=post enctype="multipart/form-data" name="upload">
Select file: <input type=file name="the_file"><br>
Other information: <input type=text name="info" size="30">
<p>
<input type=button value="Upload file" onClick="beginUpload()">
</form>
</body>
</html>
-- progress.jsp
<%@ page import="net.sf.basedb.clients.web.fileupload.*" %>
<%
int progress_id = Integer.parseInt(request.getParameter("progress_id"));
FileUploadProgress progress = FileUpload.getProgress(progress_id);
%>
<html>
<head>
<title>Upload progress</title>
</head>
<body>
<% if (progress == null) {%>
Waiting for transfer...
<%} else {%>
Bytes transferred: <%=progress.getTransferredBytes()%><br>
Total bytes to transfer: <%=progress.getTotalBytes()%><br>
<% if (progress.transferIsComplete()) {%>
Transfer completed!
<%}%>
<%}%>
<%if (progress == null || !progress.transferIsComplete()) {%>
<script language="JavaScript">
setTimeout("location.reload()", 500);
</script>
<%}%>
</body>
</html>
-- upload.jsp
<%@ page import="net.sf.basedb.clients.web.fileupload.*" %>
<%
int progress_id = Integer.parseInt(request.getParameter("progress_id"));
FileUpload fu = new FileUpload(progress_id, request);
UploadedFile fuf = fu.getFile("the_file");
fuf.moveTo("/home/uploads/"+fuf.getOriginalFilename());
%>
<html>
<head>
<title>File uploaded</title>
</head>
<body>
Original filename: <%=fuf.getOriginalFilename()%><br>
Mime type: <%=fuf.getMimeType()%><br>
Size: <%=fuf.getSize()%><br>
Other information: <%=fu.getParameter("info")%><br>
</body>
</html>
|
3.1.1: 2012-03-29 | ||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||