单文件上传
smartupload_demo01.htm
<html>
<head><title>www.mldnjava.cn,MLDN高端Java培训</title></head>
<body>
<form action="smartupload_demo01.jsp" method="post" enctype="multipart/form-data">
请选择要上传的文件:<input type="file" name="pic">
<input type="submit" value="上传">
</form>
</body>
</html>
smartupload_demo01.jsp
<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="org.lxh.smart.*"%>
<html>
<head><title>www.mldnjava.cn,MLDN高端Java培训</title></head>
<body>
<%
SmartUpload smart = new SmartUpload() ;
smart.initialize(pageContext) ; // 初始化上传操作
smart.upload() ; // 上传准备
smart.save("upload") ; // 文件保存
%>
</body>
</html>
批量文件上传
smartupload_demo03.htm
<html>
<head>
<title></title>
</head>
<body>
<form action = "smartupload_demo03.jsp" method = "post" enctype = "multipart/form-data">
照片1:<input type = "file" name = "pic"><br>
照片2:<input type = "file" name = "pic"><br>
照片3:<input type = "file" name = "pic"><br>
<input type = "submit" value = "上传">
<input type = "reset" value = "重置">
</form>
<body>
</html>
smartupload_demo03.jsp
<%@ page contentType = "text/html" pageEncoding = "GBK"%>
<%@ page import = "org.lxh.smart.*"%>
<%@ page import = "cn.mldn.lxh.util.IPTimeStamp"%>
<html>
<head>
<title></title>
</head>
<body>
<%
request.setCharacterEncoding("GBK");//解决乱码
%>
<%
SmartUpload smart = new SmartUpload();//实例化SmartUpload上传组件
smart.initialize(pageContext);//初始化上传操纵
smart.upload(); //上传准备
IPTimeStamp its = new IPTimeStamp(request.getRemoteAddr());//实例化IPTimeStamp对象
for(int x=0;x<smart.getFiles().getCount();x++){
String ext = smart.getFiles().getFile(x).getFileExt();//取得文件后缀
String fileName = its.getIPTimeRand()+"."+ext;//拼凑文件名称
smart.getFiles().getFile(x).saveAs(getServletContext().getRealPath("/")+"upload"+java.io.File.separator+fileName);//保存文件
}
%>
</body>
</html>