jspsmartupload 下载实现

down.html代码如下:原理就是通过超链接到一个jsp,通过jsp调用下载的代码

<! DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN" >
< html >
< head >
< title > 文件上传 </ title >
< meta http-equiv ="Content-Type" content ="text/html;charset=gb2312" >
</ head >
< body >
< p align ="center" >
上传文件选择
</ p >
< FORM METHOD ="POST" ACTION ="up.jsp" ENCTYPE ="multipart/form-data" >
< input type ="hidden" name ="TEST" value ="good" >
< table width ="75%" border ="1" align ="center" >
< tr >
< td >
< div align ="center" >
1、
< input type ="FILE" name ="FILE1" size ="30" >
</ div >
</ td >
</ tr >
< tr >
< td >
< div align ="center" >
2、
< input type ="FILE" name ="FILE2" size ="30" >
</ div >
</ td >
</ tr >
< tr >
< td >
< div align ="center" >
3、
< input type ="FILE" name ="FILE3" size ="30" >
</ div >
</ td >
</ tr >
< tr >
< td >
< div align ="center" >
4、
< input type ="FILE" name ="FILE4" size ="30" >
</ div >
</ td >
</ tr >
< tr >
< td >
< div align ="center" >
< input type ="submit" name ="Submit" value ="上传它!" >
</ div >
</ td >
</ tr >
</ table >
< br >
< br >
< a href ="down.jsp" > 点击下载 </ a >
</ FORM >
</ body >
</ html >

down.jsp

<% ... @pagecontentType="text/html;charset=gb2312"language="java"import="java.util.*,com.jspsmart.upload.*,java.lang.*"errorPage="" %>

<! DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN" >
< html >
< head >

< title > MyJSP'down.jsp'startingpage </ title >

</ head >

< body >
<% ... SmartUploadsu=newSmartUpload();
su.initialize(pageContext);
su.setContentDisposition(
null);//是否自动打开,null为不自动打开
su.downloadFile(
"c:\jh.cer");
out.clear();
out
=pageContext.pushBody();
%>
</ body >
</ html >

值得主义的是:再<%%>里的后两句

out.clear();
out = pageContext.pushBody();
一定要加上,不然在有些时候会报异常:getOutputStream() has already been called for this response

你可能感兴趣的:(html,jsp,UP)