jspsmartupload组件实现单个或多个文件上传(上)

实现单个文件上传

------------------ upload.html--------------------

//上传文件页面

< html >
< head >
< title > 文件上传 </ title >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312" >
</ head >
< body >
< align ="center" > 上传文件选择 </ p >
< FORM  method ="POST"  action ="UpLoad.jsp"  enctype ="multipart/form-data" >
< input  type ="hidden"  name ="TEST"  value ="good" >
< table  width ="75%"  border ="1"  align ="center" >
< tr >
< td >< div  align ="center" > 1:
< input  type ="FILE"  name ="FILE1"  size ="30" >
</ div ></ td >
</ tr >
< tr >
< td >< div  align ="center" >
< input  type ="submit"  name ="Submit"  value ="上传它!" >
</ div ></ td >
</ tr >
</ table >
</ FORM >
</ body >
</ html >

 //处理文件,开始上传

 ------------------UpLoad.jsp-----------------

 

 

<% @ page contentType="text/html; charset=gb2312" language="java" errorPage=""  %>
<% @ page import="com.jspsmart.upload.*,com.hs.manageimage.exception.ManageImageException" %>
< jsp:useBean  id ="SU"  scope ="page"  class ="com.jspsmart.upload.SmartUpload"   />  
< html >
< head >
< title > 上载附件  </ title >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312" >
</ head >
< body >
  
< center >
<%
//上载附件
try
{
out.println(request.getContextPath());
    SU.initialize(pageContext); 
//上传初始化。
    
//SU.service(request,response); 
    SU.upload(); 
//上传文件。
    SU.setAllowedFilesList(
"doc,txt,jpg");// 设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。
    SU.setDeniedFilesList(
"exe,bat,jsp,htm,html,,"); //设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat, jsp,htm,html扩展名的文件和没有扩展名的文件。
    SU.setMaxFileSize(
10000); // 限制每个上传文件的最大长度。
    
//SU.setTotalMaxFileSize(20000); // 限制总上传数据的长度。
    
if(!SU.getFiles().getFile(0).isMissing())
    {
    out.println(SU.getFiles().getFile(
0).getFieldName().toString()+SU.getFiles().getFile(0).getFilePathName().toString()+
SU.getFiles().getFile(
0).getFileExt().toString()+
SU.getFiles().getFile(
0).getSize()+
SU.getFiles().getFile(
0).isMissing());
    
String fn=SU.getFiles().getFile(0).getFileName(); //获得上传名称
    SU.save(
"uploadDir/");//文件保存的目录为UploadDir
    out.println(
"<br>成功上传,请查看<a href=/manageImage/uploadDir/"+fn+"> uploadDir/"+fn+"文件</a>,<br>确认文件是否上传成功!");
    
    }
else
    {
    response.sendRedirect(
"./UpLoad.html");
    }
}
catch(Exception ex)
{
  throw 
new ManageImageException("上传图片的类型出现错误");
}

%>
< href =UpLoad.html >< div > 重新上传文件 </ div ></ a >
</ body >
</ html >

 

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值