jsp文件上传,jspsmart实例

所需的jar文件:jspSmartUpload.jar
upload.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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值