js| Program | Upload after a great effort, and finally can write a small program of their own upload, which to the above URL for the standard written, but this program and the new version of the commons-fileupload-1.0, there is a different place, is:
The new is:
void Write (Java.io.File File)
A convenience to write A uploaded the item to disk.
And here's a string!!!
Thanks to me, I have a little Java foundation, by looking at the API
Constructor Summary
File (file parent, String child)
Creates a new File instance from the parent abstract pathname and a child pathname string.
File (String pathname)
Creates a new File instance by converting the given pathname string into an abstract pathname.
File (string parent, String child)
Creates a new File instance from the parent pathname string and a child pathname string.
File (URI Uri)
Creates a new File instance by converting the given File:uri to an abstract pathname.
I have amended this sentence to two sentences:
File Writefile=new file ("F:\\public", name);
Fi.write (WriteFile);
So this upload program can finally work! (one will have the source code, upload a file)
And here's "" is "" (Input Method problem), if pasted over to change, do not know how to return to things, the online code is always a little difficult to think of the error and can not run! So the online things can only refer to the understanding after the written!
Other processes:
1. Upload
B-End Upload
1) Upload directory:
<form action= "getupload.jsp" enctype= "Multipart/form-data" method= "POST" >
Here oc4j directories and Tomcat directories are any directories that are real on the server's hard drive!
2) Upload method.
Please enter the file to upload: <input type= "file" name= "file"/>
2. Get
S-end reads:
1). Request.getinputstream for analysis
Public ServletInputStream getInputStream () throws Java.io.IOException
2). Jakarta General Library
3. Download
Temp sql:
CREATE TABLE Upload (
Name VARCHAR2 primary key NOT NULL,
Content Clob);
Commit
Server side accept file upload, download commons-fileupload-1.0, http://jakarta.apache.org/commons/fileupload/
Description
Commons is a Java subproject in the Apache open source organization that involves a number of commonly used modules in development, such as file uploads, command-line processing, database connection pooling, and XML configuration file processing. These projects bring together the efforts of software engineers from around the world, and their performance, stability and so on can withstand the test of practical application. The effective use of these projects will bring obvious results to development. FileUpload is the subproject that is used to process HTTP file uploads. This article mainly describes how to use FileUpload to handle the file information that the browser submits to the server.
PS: Generally downloaded *.jar files are copied to Tomcat 5.5\common\lib
In addition, because the FileUpload child project also uses another project commons-beanutils, you must download the beanutils and copy the extracted file Commons-beanutils.jar to {$TOMCAT}/ The Common/lib directory
Set up to allow users to upload file size, Unit: bytes
Dfu.setsizemax (1000000);
Maximum size that'll be stored in memory?
Set up to allow only data stored in memory, in bytes
Dfu.setsizethreshold (4096);
Set the directory where data is stored on the hard disk once the file size exceeds the value of Getsizethreshold ()
Dfu.setrepositorypath ("F:\\public");
Start reading upload information
try{
List Fileitems = dfu.parserequest (request);
%>
<%
Process each uploaded file in turn
Iterator i = Fileitems.iterator ();
String name =null;
Long size=0;
while (I.hasnext ())
{
Fileitem fi = (Fileitem) i.next ();
Ignore any other form information that is not a file field
if (!fi.isformfield ()) {
Name = Fi.getname ();
Size = Fi.getsize ();
if (name==null| | Name.equals ("")) && size==0)
Continue }
Name=fi.getname ();
Size=fi.getsize ();
Name = Name.replace (': ', ' _ ');
Name = Name.replace (' \ \ ', ' _ ');
File Writefile=new file ("F:\\public", name);
Fi.write (WriteFile);
}
}catch (Fileuploadexception fue)
{Fue.printstacktrace ();}
%>
***************
Experience:
1. The API is very important. More important than any reference book!
2. Anything can only be used as a reference, only to write their own!
3. What difficulties encountered, only focus and perseverance, after all, we have stood on the shoulders of others, others began to walk more difficult than we, so we did not attack!
My reference source, remember, can only give you a reference, perhaps the program has bugs, welcome advice:
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.