uploadFile.html...........
< body>
< !-- some codes... -->
< method="post" action="upload.jsp" name="uploadForm" enctype="'multipart/form-data'">
< !-- please notice (ENCTYPE='multipart/form-data').... -->
< input name="uploadfile" type="file">
< p>
< input name="Submit" value="Upload" type="submit">
< input name="Reset" value="Reset" type="reset">
< input name="action" value="upload" type="hidden">
< /p>
< !-- some codes... -->
< /body>
upload.jsp.............
<%@ page import="java.io.*"%>
<% String contentType = request.getContentType(); if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < byteread =" in.read(dataBytes," file =" new" savefile =" file.substring(file.indexOf(" filename="\" savefile =" saveFile.substring(0," savefile =" saveFile.substring(saveFile.lastIndexOf(" lastindex =" contentType.lastIndexOf(" boundary =" contentType.substring(lastIndex" pos =" file.indexOf(" filename="\" pos =" file.indexOf(" pos =" file.indexOf(" pos =" file.indexOf(" boundarylocation =" file.indexOf(boundary," startpos =" ((file.substring(0," endpos =" ((file.substring(0," filepath="session.getServletContext().getRealPath(" fileout =" new">
***important>>notice
request.getContentType()
request.getInputStream()
request.getContentLength()
Wednesday, February 20, 2008
Uploading a file in JSP
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment