Use JSP to write the fileupload upload Applet

Source: Internet
Author: User
Reference: http://www.7880.com/Info/Article-42b729a0.html

New:

VoidWrite(Java. Io. File file)
A convenience method to write an uploaded item to disk.

Here is the string !!!

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! (The source code will be available for uploading a file later) and "" all "here (the input method is incorrect). If you paste it and modify it one by one, you don't know how to handle it, 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 upload1)

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, and downloads a Java sub-project in the Apache open source organization, this project mainly involves some common development modules, 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: The downloaded *. Jar files are all 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 :)

 

*************

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.