Reference: http://www.cnblogs.com/xnxqs/archive/2005/07/13/191927.html
After a hundred efforts, finally can write their own upload applet, the above URL for standard writing, but this program and the new version of the commons-fileupload-1.0, there is a different place, is:
New:
VoidWrite(Java. Io. File file)
A convenience method to write an uploaded item to disk.
Here is the string !!!
Thanks to a bit of Java basics
Constructor Summary |
File(File parent, string child) Creates a new file instance from a 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 a parent pathname string and a child pathname string. |
|
File(URI) Creates a new file instance by converting the given file: URI into an abstract pathname. |
|
I modified this sentence into two sentences:
File writefile = new file ("F: \ public", name );
Fi. Write (writefile );
This upload program can finally work! (If the source code is available, upload a file)
There are also "" All "(Input Method Problems) here. If you need to modify them one by one, and you don't know how to do it, the code on the internet is always a bit confusing and cannot be run! Therefore, you can only write online things by yourself after understanding them!
Other processes:
1. Upload
B-end upload
1)Upload directory:
<Form action = "getupload. jsp" enctype = "multipart/form-Data" method = "Post">
In this example, the Directory of the Linux kernel and the directory of Tomcat are actually any directories on the server hard disk!
2) Upload method.
Enter the file to be uploaded: <input type = "file" name = "file"/>
2. Get
S-side reading:
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 (16) primary key not null,
Content clob );
Commit;
Server receives file uploads, downloads commons-fileupload-1.0, http://jakarta.apache.org/commons/fileupload/
Note:
Commons is a Java sub-project in the Apache open source code organization. This project mainly involves some common modules in development, such as file upload, command line processing, database connection pool, and xml configuration file processing. These projects bring together the painstaking efforts of software engineers from all over the world, and their performance and stability have all stood the test of practical applications. Effective use of these projects will bring obvious effects to the development. Fileupload is a sub-project used to process HTTP file uploads. This article describes how to use fileupload to process the file information submitted to the server by the browser.
PS: Generally, the downloaded *. Jar files are copied to Tomcat 5.5 \ common \ Lib.
In addition, because the fileupload sub-project also needs to use another project commons-beanutils, you must download beanutils and copy the extracted file commons-beanutils.jar to the {$ Tomcat}/common/lib directory
Reference: http://www.7880.com/Info/Article-42b729a0.html
Reference source code I wrote:
// Inputupload. jsp
<% @ Page contenttype = "text/html; charset = big5" %>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = big5">
<Title> inputupload </title>
</Head>
<Body>
<%
Request. setcharacterencoding ("big5 ");
%>
<Form action = "getupload. jsp" enctype = "multipart/form-Data" method = "Post">
Import the file to be uploaded: <input type = "file" name = "file"/>
<Input type = "Submit" value = "determining upper limit"/>
</Form>
</Body>
</Html>
// Getupload. jsp
<% @ Page contenttype = "text/html; charset = GBK" %>
<% @ Page import = "Java. util. *" %>
<% @ Page import = "Java. Io. *" %>
<% @ Page import = "org. Apache. commons. fileupload. *" %>
<% @ Page import = "org. Apache. commons. beanutils. *" %>
Getupload. jsp
<%
Diskfileupload DFU = new diskfileupload ();
// Set the size of the file to be uploaded. Unit: bytes.
DFU. setsizemax (1000000 );
// Maximum size that will be stored in memory?
// Set up to only data that can be stored in the memory, in bytes
DFU. setsizethreshold (4096 );
// Set the data stored in the hard disk directory when 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 sequence
Iterator I = fileitems. iterator ();
String name = NULL;
Long size = 0;
While (I. hasnext ())
{
Fileitem Fi = (fileitem) I. Next ();
// Ignore all other forms that are not in the 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. APIs are very important. They are more important than any reference books!
2. Everything can only be used as a reference. Only what you write is yours!
3. What difficulties have we encountered? We have to focus on and persevere. After all, we have stood on the shoulders of others. the way others begin to take is more difficult than ours, so we have not been able to break down!
My reference source code, remember, can only be used for your reference, maybe there are bugs in the program, please advise :)
If you have any questions, you can discuss them together :)