标签:文件上传和下载的javabean组件 smartupload
(1)JspSmartUpload是一个免费的上传与下载文件的JavaBean,比较适合小文件的上传与下载。
smartUpload中常用的类如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <%@page import="com.jspsmart.upload.*"%> <body> <% SmartUpload upload=new SmartUpload(); upload.initialize(pageContext); //初始化 upload.upload(); //开始上传 Files collection=upload.getFiles(); //获得上传文件的集合 File file=null; String fileName=null; int fileNumber=0; for(int i=0;i<collection.getCount();i++) { file=collection.getFile(i); fileName=file.getFileName(); if(!file.isMissing()) { file.saveAs("/"+fileName); out.print("<br>=========上传的文件信息========="); out.print("<br>文件名:"+fileName); out.print("<br>文件名后缀:"+file.getFileExt()); out.print("<br>文件大小:"+file.getSize()); fileNumber++; } } out.print("<br>共计上传文件数:"+fileNumber); %> </body> </html>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> <form action="exam506.jsp" method="post" enctype="multipart/form-data" name="form1" id="form1"> <p>请选择文件:</p> <p> <label> <input type="file" name="file" /> </label> </p> <p> <label> <input type="file" name="file2" /> </label> </p> <p> <input type="file" name="file3" /> </p> <p> <label> <input type="submit" name="Submit" value="提交" /> </label> </p> </form> </body> </html>
标签:文件上传和下载的javabean组件 smartupload
原文地址:http://blog.csdn.net/xlgen157387/article/details/39346427