jsp上传XLS

提交页面:

<form name="uploadform" method="post" action="./app/upLoad/saveUpload.jsp" ENCTYPE="multipart/form-data">

<table>
 <thead>
  <tr>
   <th><h2><b><font color='red'>生成考核排名序列</font></b></h2></th>
  </tr>
 </thead>
 <tr>
  <td>
   上月考核成绩:<input name="<%=ComXlpmEnum.lastMonthScore_Key %>" size="40" type="file">
     
  </td>
  <td>
   <input name="upload" type="submit" value="开始上传"/>
  </td>
 </tr>
</table>
</form>

后台上传页面:

String uploadFilePrePath = request.getSession().getServletContext().getRealPath("/")+"uploadFiles\\";
            
com.jspsmart.upload.SmartUpload   smartUpload=new   com.jspsmart.upload.SmartUpload();

smartUpload.initialize(pageContext);
String   fileName= "";
StringBuffer fileNameStr= new StringBuffer();
try{

    smartUpload.setAllowedFilesList( "xls");   //这里可以限制上传类型
 smartUpload.setMaxFileSize(500000); // 限制每个上传文件的最大长度。

    boolean   isfile=true;
    smartUpload.upload();
 
    com.jspsmart.upload.File   myfile=null;
    if(smartUpload.getFiles().getCount()> 0){
    for(int   i=0;i <smartUpload.getFiles().getCount();i++){
     myfile   =   smartUpload.getFiles().getFile(i);
     
     String itemFieldName = myfile.getFieldName();
     if(itemFieldName != null && itemFieldName.equals(ComXlpmEnum.lastMonthScore_Key)){
      java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yy-MM");
      Calendar lastDate = Calendar.getInstance();  
      lastDate.add(Calendar.MONTH,-1);//减一个月,变为下月的1号  
      String preMounth=sdf.format(lastDate.getTime());  
   
   fileName = uploadFilePrePath+preMounth+".xls";
     }else{
      fileName = uploadFilePrePath+myfile.getFieldName()+"."+myfile.getFileExt();
     }
     
     out.println(fileName);
     out.println("<br />");
  
     if(fileNameStr.length() < 1){
      fileNameStr.append(" ' "+fileName+ " ' ");
     }else{
      fileNameStr.append(", ' "+fileName+ " ' ");
     }
     
 
     myfile.saveAs(fileName);
}

%>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值