After a general effort, I finally wrote the fileupload upload applet with JSP.

xiaoxiao2021-03-06  43

Reference: http://www.7880.com/info/Article-42b729a0.html After a general effort, you can finally write a small upload applet, where the URL above is written, but this program and new Version of Commons-FileUpload-1.0, there is a different place, that is:

New is:

Void Write (java.io.file file) a convetenience method to write, an uploaded item to disk.

And here is String !!!

Thanks to me, there is a little bit of Java, and find the API

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 uri) Creates a new File instance by converting the given file: uRI into an abstract pathname.

I have modified this sentence to two:

File Writefile = New File ("f: // public", name);

FI.WRITE (WRITEFILE);

This way this uploader can finally work! (One will have source code, upload a file)

There is also the "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" " Things can only be written after you refer to your understanding!

Other procedures:

1. Upload of UPLOADB

1) UPLOAD directory:

The directory of the OC4J and Tomcat can be any directory on the server hard disk!

2) Upload method.

Please enter the file you want to upload:

2. Gets read: 1) .Request.getInputStream Perform Analysis Public ServletInputStream GetInputStream () THROWS JAVA.IOEXCEPTION2). Jakarta Universal Library

3. Download

Temp SQL:

CREATE TABLE UPLOAD

Name varchar2 (16) Primary Key Not Null,

Content Clob);

COMMIT;

Server end accepts file upload, download Commons-fileupload-1.0, http://jakarta.apache.org/commons/fileupload/

Description:

Commons is a Java sub-project in Apache Open Source Organization, which mainly involves modules that are commonly used in development, such as file upload, command line processing, database connection pool, XML configuration file processing, etc. These projects have brought about the test of practical applications from software engineers from all over the world. Effectively uses these items will have an obvious effect to the development. FILEUPLOAD is the subcommetled subproject to handle HTTP files. This article mainly describes how to use FileUPload to process the browser to submit file information. PS: General download * .jar files are copied to tomcat 5.5 / circon / lib

In addition, due to the FileUPload sub-project, it is necessary to use another project command-beanutils, so you must download beanUtils and copy the decompressed file commons-beanutils.jar to {$ Tomcat} / common / lib directory

REFERENCE:

Http://www.7880.com/info/Article-42b729a0.html I wrote the reference source code:

//inputupload.jsp

<% @ Page ContentType = "Text / HTML; Charset = BIG5"%> Please enter To upload the file:

//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 ();

// Settings Allow users to upload file size, unit: byte

DFU.SetSizeMax (1000000);

// Maximum Size That Will Be Stored in Memory?

/ / Set up to only the data stored in the memory, unit: byte

Dfu.setsizetHold (4096);

// Setting Once the file size exceeds the value of getsizethreshold (), the data is stored in the directory DFU.SetRepositoryPath ("f: // public") ("f: // public");

// Start reading upload information

Try {

List fileItems = dfu.parsequest (required);

%>

<%

// handle each uploaded file

Iterator i = fileItems.Item ();

String name = NULL;

Long size = 0;

While (I.hasNext ())

{

FileItem Fi = (fileItem) i.next ();

/ / Ignore all form information not not the file domain

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. It is important than any reference book!

2. Anything can only be used as a reference, only what you write is your own!

3. What difficulties encounter, only focuses and perseverance, after all, we have stood on the shoulders of others, and the road that others began to go is more difficult, so we have not attacked!

My reference source, remember, I can only give you a reference, maybe there is bug in the program, welcome to advise :)

If you have any questions, you can discuss it together :)

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

转载请注明原文地址:https://www.9cbs.com/read-53836.html

New Post(0)