码迷,mamicode.com
首页 > 编程语言 > 详细

文件上传和下载的JavaBean组件

时间:2014-09-17 20:30:32      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:文件上传和下载的javabean组件   smartupload   

一.小文件的上传与下载

(1)JspSmartUpload是一个免费的上传与下载文件的JavaBean,比较适合小文件的上传与下载。


smartUpload中常用的类如下:

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣


<%@ 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>

注意的是要用到smartUpload.jar


文件上传和下载的JavaBean组件

标签:文件上传和下载的javabean组件   smartupload   

原文地址:http://blog.csdn.net/xlgen157387/article/details/39346427

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!