Instance: the text box for dynamically adding and deleting uploaded files

Source: Internet
Author: User

Instance: the text box for dynamically adding and deleting uploaded files

<% @ Page Language ="Java"Import ="Java. util .*"Pageencoding =UTF-8"%>

<%

String Path = request. getcontextpath ();

String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";

%>

Upload. jsp

<SCRIPT type ="Text/JavaScript">

FunctionAddFile (){

VaRFiles = Document. getelementbyid ("Files ");

VaRInput = Document. createelement ("input ");

Input. Name = "file ";

Input. type = "file ";

VaRDelbutton = Document. createelement ("input ");

Delbutton. type = "button ";

Delbutton. value = "delete ";

Delbutton. onclick =FunctionDel (){

This. Parentnode. parentnode. removechild (This. Parentnode );

}

VaRDIV = Document. createelement ("Div ");

Div. appendchild (input );

Div. appendchild (delbutton );

Files. appendchild (DIV );

}

</SCRIPT>

</Head>

<Body>

<Form action ="$ {Pagecontext. Request. contextpath}/Servlet/uploadservlet"Enctype ="Multipart/form-Data"Method ="Post">

Upload user <input type ="Text"Name ="Username"/> <Br/>

File 1 <input type ="File"Name ="File1"/> <Br/>

File 2 <input type ="File"Name ="File2"/> <Br/>

<Input type ="Submit"Value ="Submit"/> <Br/>

</Form>

<Br/> <br> <HR/>

CommonsFileuploadDemo: <br/>

<Form action ="$ {Pagecontext. Request. contextpath}/Servlet/uploadservlet2"Enctype ="Multipart/form-Data"Method ="Post">

Upload user <input type ="Text"Name ="Username"/> <Br/>

File 1 <input type ="File"Name ="File1"/> <Br/>

File 2 <input type ="File"Name ="File2"/> <Br/>

<Input type ="Submit"Value ="Submit"/> <Br/>

</Form>

<HR/>

<Form action ="$ {Pagecontext. Request. contextpath}/Servlet/uploadservlet2"Enctype ="Multipart/form-Data"Method ="Post">

<Table>

<Tr>

<TD>

User name:

</TD>

<TD>

<Input type ="Text"Name ="Username">

</TD>

</Tr>

<Tr>

<TD> </TD>

<TD>

<Input type ="Button"Value ="Add file"Onclick = "AddFile ()">

</TD>

</Tr>

<Tr>

<TD> </TD>

<TD>

<Div id ="Files"> </Div>

</TD>

</Tr>

<Tr>

<TD> </TD>

<TD>

<Input type ="Submit"Value ="Upload files">

</TD>

</Tr>

</Table>

</Form>

</Body>

</Html>

Uploadservlet. Java

Public voidDopost (httpservletrequest request, httpservletresponseresponse)

ThrowsServletexception, ioexception {

 

Inputstream is = request. getinputstream ();

Byte[] Buff =New byte[1024];

IntLen = 0;

While(LEN = is. Read (buff)> 0 ){

System.Out. Println (NewString (buff, 0, Len ));

}

}

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.