Study java

一个新手学习JavaEE的心得,希望对学习JavaEE的朋友有些帮助。

用jspsmart 进行上传


首先去http://www.jspsmart.com下载jspSmartUpload.zip,解压缩后将文件放在WEB-INF/classes/下(目前这个网站已经被关闭)
本地下载
下面是演示。SmartUpLoad只有一个构造函数。即public SmartUpload在jsp中直接使用javaBean来生成一个SmartUpLoad的对象
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/>
下面是演示。其中方法都是有注释的
------------------------------Jspsmart.html---------------
< html >
< head >
< title > Jspsmart.html </ title >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=GB2312" >
</ head >
< body >

< h2 > 文件上传范例 - jspSmart </ h2 >

< form  name ="Form1"  enctype ="multipart/form-data"  method ="post"  action ="Jspsmart.jsp" >
< p > 上传文件 1: < input  type ="file"  name ="File1"  size ="20" maxlength ="20" ></ p >
< p > 上传文件 2: < input  type ="file"  name ="File2"  size ="20" maxlength ="20" ></ p >
< input  type ="submit"  value ="上传" >
< input  type ="reset"  value ="清除" >
</ form >

</ body >
</ html >



------------------------------------Jspsmart.jsp--------------------



<%@ page import="com.jspsmart.upload.*" %>
<%@ page contentType="text/html;charset=GB2312" %>

<html>
<head>
<title>CH9 - Jspsmart2.jsp</title>
</head>
<body>

<h2>文件上传范例 - jspSmart</h2>

<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/>
<%
//计算文件上传个数
int count=0;

//SmartUpload的初始化,使用这个jspsmart一定要在一开始就这样声明
mySmartUpload.initialize(pageContext);

//依据form的内容上传
mySmartUpload.upload();

//将上传的文件一个一个取出来处理
for (int i=0;i<mySmartUpload.getFiles().getCount();i++)
{
//取出一个文件
com.jspsmart.upload.File myFile 
= mySmartUpload.getFiles().getFile(i);

//如果文件存在,则做存档操作
if (!myFile.isMissing()) {

//将文件存放于绝对路径的位置
myFile.saveAs(
"C:\\upload\\" + myFile.getFileName(),

mySmartUpload.SAVE_PHYSICAL);

//显示此上传文件的详细信息
out.println(
"FieldName = " + myFile.getFieldName() + "<BR>");
out.println(
"Size = " + myFile.getSize() + "<BR>");
out.println(
"FileName = " + myFile.getFileName() + "<BR>");
out.println(
"FileExt = " + myFile.getFileExt() + "<BR>");
out.println(
"FilePathName = " + myFile.getFilePathName() + "<BR>");
out.println(
"ContentType = " + myFile.getContentType() + "<BR>");
out.println(
"ContentDisp = " + myFile.getContentDisp() +"<BR>");
out.println(
"TypeMIME = " + myFile.getTypeMIME() +"<BR>");
out.println(
"SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>");
count 
++;
}
}

// 显示应该上传的文件数目
out.println(
"<BR>" + mySmartUpload.getFiles().getCount() + " files could be uploaded.<BR>");

// 显示成功上传的文件数目
out.println(count 
+ "file(s) uploaded.");
%>

</body>
</html>



posted on 2006-11-10 18:39 ronghai 阅读(4341) 评论(1)  编辑  收藏 所属分类: jsp学习

评论

# re: 用jspsmart 进行上传 2010-05-05 13:46 asdas

编码问题如何解决?  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2006年11月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

统计

常用链接

留言簿(2)

随笔分类

随笔档案

城市流浪者

搜索

最新评论

阅读排行榜

评论排行榜