Jspsmart2.jsp %@ page import=com.jspsmart.upload.* % %@ page contentType=text/html;charset=GB2312 % html head titleJspsmart2.jsp/title /head body h2文件上传范例 - jspSmart/h2 jsp:useBean id=mySmartUpload scope=page class=com.jspsmart.uploa
Jspsmart2.jsp
<%@ page import="com.jspsmart.upload.*" %>
<%@ page contentType="text/html;charset=GB2312" %>
<%
//计算文件上传个数
int count=0;
//SmartUpload的初始化,使用这个jspsmart一定要在一开始就这样声明
mySmartUpload.initialize(pageContext);
//依据form的内容上传
mySmartUpload.upload();
//将上传的文件一个一个取出来处理
for (int i=0;i
//取出一个文件
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
//如果文件存在,则做存档操作
if (!myFile.isMissing()) {
//将文件存放于绝对路径的位置
myFile.saveAs("D://totalExample//jsp//UploadFile//" + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL);
//显示此上传文件的详细信息
out.println("FieldName = " + myFile.getFieldName() + "
");
out.println("Size = " + myFile.getSize() + "
");
out.println("FileName = " + myFile.getFileName() + "
");
out.println("FileExt = " + myFile.getFileExt() + "
");
out.println("FilePathName = " + myFile.getFilePathName() + "
");
out.println("ContentType = " + myFile.getContentType() + "
");
out.println("ContentDisp = " + myFile.getContentDisp() +"
");
out.println("TypeMIME = " + myFile.getTypeMIME() +"
");
out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "
");
count ++;
}
}
// 显示应该上传的文件数目
out.println("
" + mySmartUpload.getFiles().getCount() + " files could be uploaded.
");
// 显示成功上传的文件数目
out.println(count + "file(s) uploaded.");
%>
注意事项:
一般输入类型(例如,text、password、select,等等)传送Form到服务器端时,所用的编码方式是application/x-www-form-urlencoded,但是若要传送文件至服务器端时,必须使用mutilpart/form-data的编码方式;