Use Cos to upload files!

Source: Internet
Author: User
Tags cos

Turn from: http://blog.csdn.net/pharaohsprince/

Change it a little bit!

Upload.html

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
"Http://www.w3.org/TR/html4/loose.dtd" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Untitled Document </title>

<body>
<!--enctype value is important, upload.jsp for processing uploaded jsp-->
<form name= "Form1" method= "Post" enctype= "Multipart/form-data" action= "upload.jsp" >
<p>
<input name= "file1" type= "File" >
</p>
<p>
<input name= "file2" type= "File" >
</p>
<p> <input name= "file3" type= "File" >
</p>
<p>
<input type= "Submit" name= "submit" value= "Upload" >
</p>
</form >

</body>

<% @page import= "java.io.*"%>
<% @page import= "java.util.*"%>
<% @page import= "Com.oreilly.servlet.MultipartRequest"%>

<% @page contenttype= "text/html; charset=gb2312 "%>
<%
File upload, save in C://upload
java/lang/string.java.html "target=" _blank ">
String savedirectory = "C://upload";
Maximum 5m per file, up to 3 files, so ...
int maxpostsize = 3 * 5 * 1024 * 1024;
Response is encoded as "gb2312", and the default filename conflict resolution strategy is used to implement the upload
Multipartrequest multi =
New Multipartrequest (Request, Savedirectory, Maxpostsize,
"gb2312");

Output feedback Information
Enumeration files = Multi.getfilenames ();
while (Files.hasmoreelements ()) {
SYSTEM.ERR.PRINTLN ("CCC");
String name = (string) files.nextelement ();
File f = multi.getfile (name);
if (f!=null) {
String fileName = multi.getfilesystemname (name);
String lastfilename= savedirectory+ "//" + fileName;
Out.println ("uploaded file:" +lastfilename);
Out.println ("}
}

%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">

upload.jsp

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.