JSP using components to achieve the full introduction of File Upload

Source: Internet
Author: User
Tags count file size file upload
js| Introduction | Upload A, first download jspsmartupload components
HTTP://DBOY520.51.NET/CGI-BIN/NEWJAVAJIA/DOWNCOUNT.PHP?ID=22 (Site address)
Http://www.jspsmart.com

Second, the contents of the directory jspsmartupload/wib_inf/classes copy to the site in the actual directory in the Web-inf (resin is this directory, the other may be classes, please refer to the jspsmartupload/ help/setup.htm)

Third, if it is resin run JSP, please resin in the conf/resin.conf of the
<web-app> and </web-app> add:
<path-mapping url-pattern= '/upload/* ' real-path= ' f:\jsp\jspsmartupload\upload '/>

Four, upload the interface code as follows: (FileName: insert.htm)
<form method= "POST" action= "uploadfile.jsp" enctype= "Multipart/form-data" >
<input type= "FILE" name= "FILE1" size= "M" ><BR>
<input type= "FILE" name= "FILE2" size= "M" ><BR>
<input type= "FILE" name= "FILE3" size= "M" ><BR>
<input type= "FILE" name= "FILE4" size= "M" ><BR>
Topic: <input type= "text" name= "Text1" ><br>
<input Type=submit Value= finished name=ok>
</form>
Note the Real-path directory above

Five, uploadfile.jsp code is as follows:
<% @page contenttype= "text/html;charset=gb2312"
Language= "Java"
Import= "com.jspsmart.upload.*"%>
<jsp:usebean id= "Mysmartupload"
Scope= "Page"
class= "Com.jspsmart.upload.SmartUpload"/>

<HTML>
<body >
<H1> File Upload jsp<HR>
<%
int count=0;

Define target Directory
String destination= "/upload/";
Mysmartupload.initialize (PageContext);

File Upload
Mysmartupload.upload ();
Get the contents of the text
String content = Mysmartupload.getrequest (). GetParameter ("Text1");
Display the contents of a text
OUT.PRINTLN (content);
Upload Stats
for (int i=0;i<mysmartupload.getfiles (). GetCount (); i++) {
Com.jspsmart.upload.File myFile = Mysmartupload.getfiles (). GetFile (i);
if (!myfile.ismissing ()) {
Myfile.saveas (destination+ myfile.getfilename ());
Out.println ("File name =" + myfile.getfieldname () + "<BR>");
OUT.PRINTLN ("File size =" + myfile.getsize () + "<BR>");
Out.println ("File name =" + myfile.getfilename () + "<BR>");
OUT.PRINTLN ("File size =" + myfile.getfileext () + "<BR>");
Out.println ("File path name =" + myfile.getfilepathname () + "<BR>");
Out.println ("File type =" + myfile.getcontenttype () + "<BR>");
Out.println ("Contentdisp =" + myfile.getcontentdisp () + "<BR>");
Out.println ("MIME type =" + myfile.gettypemime () + "<BR>");
Out.println ("subtypemime =" + myfile.getsubtypemime () + "<BR>");
Count + +;
}
}

Out.println ("<BR> can upload" + mysmartupload.getfiles (). GetCount () + "file <BR>");
OUT.PRINTLN (count + "files have been uploaded");
%>
</BODY>
</HTML>
The above is the whole process of JSP file upload, good luck!
In the case of retaining http://www.javajia.com original source, welcome reprint!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.