在jsp中使用smartupload组件上传文件,怎么做啊,有例子吗?
1个回答
展开全部
<%@ page language="java" contentType="text/html; charset=GB2312" pageEncoding="GB2312"%>
<%@ page language="java" import="java.io.*"%>
<%@ page language="java" import="com.jspsmart.upload.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>文件上传Bean</title>
</head>
<body>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<FORM METHOD="POST" ACTION="Ex7_7.jsp" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>
<%
//上传文件计数
int count=0;
//初始化,传入pageContext内置变量
mySmartUpload.initialize(pageContext);
//允许上传的文件类型
mySmartUpload.setAllowedFilesList("htm,html,txt,jar,");
//或者设定拒绝上传的文件类型
// mySmartUpload.setDeniedFilesList("exe,bat,jsp");
// 拒绝的物理路径
// mySmartUpload.setDenyPhysicalPath(true);
// 设置文件最大为 50000 bytes
mySmartUpload.setMaxFileSize(50000);
// 允许一次最多上载文件大小不超过 200000 bytes
// mySmartUpload.setTotalMaxFileSize(200000);
try {
// 上传操作
mySmartUpload.upload();
//以原文件名存储在web服务器虚拟路径下
//返回上传的文件数
count = mySmartUpload.save("/Upload", mySmartUpload.SAVE_VIRTUAL);
} catch (Exception e){
//输出意外信息
out.println("<b>Wrong selection : </b>" + e.toString());
}
// 显示文件上载数
out.println(count + " file(s) uploaded.");
%>
</body>
</html>
<%@ page language="java" import="java.io.*"%>
<%@ page language="java" import="com.jspsmart.upload.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>文件上传Bean</title>
</head>
<body>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<FORM METHOD="POST" ACTION="Ex7_7.jsp" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>
<%
//上传文件计数
int count=0;
//初始化,传入pageContext内置变量
mySmartUpload.initialize(pageContext);
//允许上传的文件类型
mySmartUpload.setAllowedFilesList("htm,html,txt,jar,");
//或者设定拒绝上传的文件类型
// mySmartUpload.setDeniedFilesList("exe,bat,jsp");
// 拒绝的物理路径
// mySmartUpload.setDenyPhysicalPath(true);
// 设置文件最大为 50000 bytes
mySmartUpload.setMaxFileSize(50000);
// 允许一次最多上载文件大小不超过 200000 bytes
// mySmartUpload.setTotalMaxFileSize(200000);
try {
// 上传操作
mySmartUpload.upload();
//以原文件名存储在web服务器虚拟路径下
//返回上传的文件数
count = mySmartUpload.save("/Upload", mySmartUpload.SAVE_VIRTUAL);
} catch (Exception e){
//输出意外信息
out.println("<b>Wrong selection : </b>" + e.toString());
}
// 显示文件上载数
out.println(count + " file(s) uploaded.");
%>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询