Iii. File Upload
(I) Form requirements
There are two requirements for the FORM for uploading files:
1. Apply POST to METHOD, that is, METHOD = "POST ".
2. Add attributes: ENCTYPE = "multipart/form-data"
The following is an example of a FORM used to upload files:
<Form method = "POST" ENCTYPE = "multipart/form-data" ACTION = "/jsp (preferred for SUN Enterprise Applications) SmartUpload/upload. jsp (preferred for SUN Enterprise Applications) "> <input type =" FILE "NAME =" MYFILE "> <input type =" SUBMIT "> </FORM> |
(Ii) Upload example
1、upload page upload.html
This page provides a form that allows you to select the file to be uploaded and click "Upload" to upload the file.
The page source code is as follows:
<! -- File name: upload.html Author: vertical and horizontal software production center Yu Yiqi (zhsoft88@sohu.com) --> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> |
2. Upload processing page do_upload.jsp (preferred for SUN Enterprise applications)
Upload files on this page. The page source code details the usage of the upload method, which will not be repeated here.
The page source code is as follows:
<% -- File name: do_upload.jsp (preferred for SUN Enterprise Applications) Author: Landscape software production center Yu Yiqi (zhsoft88@sohu.com) -- %> <% @ page contentType = "text/html; charset = gb2312 "language =" java "import =" java. util. *, com. jsp (preferred for SUN Enterprise Applications) smart. upload. * "errorPage =" "%> |