jspsmartupload 下载实现

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

<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<html>
<head>
<title>文件上传</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</head>
<body>
<palign="center">
上传文件选择
</p>
<FORMMETHOD="POST"ACTION="up.jsp"ENCTYPE="multipart/form-data">
<inputtype="hidden"name="TEST"value="good">
<tablewidth="75%"border="1"align="center">
<tr>
<td>
<divalign="center">
1、
<inputtype="FILE"name="FILE1"size="30">
</div>
</td>
</tr>
<tr>
<td>
<divalign="center">
2、
<inputtype="FILE"name="FILE2"size="30">
</div>
</td>
</tr>
<tr>
<td>
<divalign="center">
3、
<inputtype="FILE"name="FILE3"size="30">
</div>
</td>
</tr>
<tr>
<td>
<divalign="center">
4、
<inputtype="FILE"name="FILE4"size="30">
</div>
</td>
</tr>
<tr>
<td>
<divalign="center">
<inputtype="submit"name="Submit"value="上传它!">
</div>
</td>
</tr>
</table>
<br>
<br>
<ahref="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

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页