随笔-211  评论-26  文章-8  trackbacks-0

首先先把jspSmartUpload.jar拷贝到C:\Tomcat 5.0\common\lib下,这是总的环境的配置(要是总环境不配置的话,就拷贝到eclipse\workspace\test\.deployables\test\WEB-INF\lib下,记得虚拟目录成功的就是这个,等下上传上来的文件,也是在.deployables目录之下的,到时候可不要说不知道上传到那边呢!!!
upload.html:
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用SMARTUPLOADS组件实现上传</title>
</head>
<body>
<p align="center">用SMARTUPLOADS组件实现上传</p>
<p align="center">选择要上传的文件:</p>
<form action="do_upload.jsp" method="post" ENCTYPE="multipart/form-data">
<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>

</body>
</html>
do_upload.jsp:
<html>
<head>
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@ page import="java.util.*,com.jspsmart.upload.*" %>
<title>文件上传处理页面</title>
</head>
<body>
<p align="center">
<%
SmartUpload su=new SmartUpload();
su.initialize(pageContext);
su.setMaxFileSize(100000);
su.setTotalMaxFileSize(200000);
su.setAllowedFilesList("doc,txt");
su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
su.upload();
int count=su.save("/upload");
out.println(count+"个文件上传成功<br>");
for(int i=0;i<su.getFiles().getCount();i++)
{
 com.jspsmart.upload.File file=su.getFiles().getFile(i);
 if(file.isMissing()) continue;
 out.println("<table border=1>");
 out.println("<tr><td>表单项名(FieldName)</td><td>"+file.getFieldName()+"</td></tr>");
 out.println("<tr><td>文件长度(size)</td><td>"+file.getSize()+"</td></tr>");
 out.println("<tr><td>文件名(filename)</td><td>"+file.getFileName()+"</td></tr>");
 out.println("<tr><td>文件扩展名(fileext)</td><td>"+file.getFileExt()+"</td></tr>");
 out.println("<tr><td>文件全名(Filepathname)</td><td>"+file.getFilePathName()+"</td></tr>");
}   out.println("</table></br>");
%>

</body>
</html>

posted on 2006-07-23 16:27 dragon 阅读(292) 评论(2)  编辑  收藏 所属分类: jsp

评论:
# re: 用jspsmart实现上传功能(用eclipse)[未登录] 2007-04-19 13:06 | 皮皮
大哥有QQ吗 我还有些问题要问你 关于文件上传下载的  回复  更多评论
  
# re: 用jspsmart实现上传功能(用eclipse) 2007-05-30 18:14 | hezhou88
SmartUpload cannot be resolved or is not a type
这个是什么问题啊??真是郁闷  回复  更多评论