File Upload and download/mail

Source: Internet
Author: User

File Upload and download

Submission Method: Post

The form in which the file is to be uploaded, input type= "file" and must have the Name property

Form type to add Encytype= "Mulitpart/form-data"

How do I get files uploaded by the file?

Use Req.getinputstream in the servlet to get all the request body, after a number of parsing to get the necessary stuff.

FileUpLoad

File: Tian site field

Diskfileitemfactory ();

Servletfileupload

Setfilesizemax (); Set individual file sizes

Setsizemax () set Total file size

SETHEADERENCODINTG (); with req.sercharacterenconding (); a meaning

Ismultipartcontent (req)//Determine if it is a file upload form

Parserequest (req) conversion to list<fileitem> for traversal

Fileitem also have to judge whether it is normal text data Isformfield

GetFileName () Form element name

GetString () the value corresponding to the name of the form element

GetName () file name

getContentType () file type

getInputStream () file stream

Write writes to File

Delete Deletes temporary files

Mailbox

Introducing the Mail.jar Package

Session.getdefaultinstance (Properties file)

The properties file needs to be set

Prop.put ("Mail.transport.protocol", "SMTP"); Specify protocol

Prop.put ("Mail.smtp.host", "localhost"); Host Stmp.qq.com

Prop.put ("Mail.smtp.port", 25); Port

Prop.put ("Mail.smtp.auth", "true"); User Password Authentication

Prop.put ("Mail.debug", "true"); Debug mode

MailMessage (Session)

Setsubject () title

Setsentdate () Send time

Setsender () Send address

Setrecipient () Receiver

SetText () Send content

Settransport ()

Connect () Send

SendMessage ()

Close ();

Multi-User mail

Mimemultipart ("related")

Addbodypart ()

MimeBodyPart ();

Setdatahandler (New DataHandler (New Filedatasource (path)))

Setcontentid (); Set resource Name

SetContent () Setting content text

Message setcontent (related); Add to Message last send

File Upload and download/mail

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.