uploadify插件与ssh上传文件到数据库

jsp代码:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery EasyUI</title>
 <link rel="stylesheet" type="text/css" href="js/ui/themes/default/easyui.css">
 <link rel="stylesheet" type="text/css" href="js/ui/themes/icon.css">
 <link href="uploadify/uploadify.css" type="text/css" rel="stylesheet" />
 <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
 <script type="text/javascript" src="js/ui/jquery.easyui.min.js"></script>
 <script type="text/javascript" src="uploadify/swfobject.js"></script>
 <script type="text/javascript" src="uploadify/jquery.uploadify.v2.1.4.min.js"></script>
     <script type="text/javascript">
     $(document).ready(function() {
      $('#fileupload').uploadify({
       'uploader'  : 'uploadify/uploadify.swf',
       'script'    : 'upload_file.action',
       'cancelImg' : 'uploadify/cancel.png',
       'auto'      : false,
       'multi'          : true, //是否支持多文件上传
       'buttonText'     : 'brower', //按钮上的文字
       //'simUploadLimit' : 3, //一次同步上传的文件数目
       'sizeLimit'      : 409600000, //设置单个文件大小限制
       //'queueSizeLimit' : 2, //队列中同时存在的文件个数限制
       'queueID'        : 'fileQueue',
       'fileDesc'       : '*.jpg;*.jpeg;*.bmp;*.gif;*.png', //如果配置了以下的'fileExt'属性,那么这个属性是必须的
                'fileExt'        : '*.jpg;*.jpeg;*.bmp;*.gif;*.png',//允许的格式
                'fileDataName'    : 'fileupload',
                'removeCompleted' : false,
                'wmode' : 'transparent',
                'buttonImg' :'uploadify/add.png',
                //'rollover' : true//值为true和false,设置为true时当鼠标移到浏览按钮上时有反转效果。
                //'width' :200 //设置浏览按钮的宽度 ,默认值:110。
                //'height' : 30 //设置浏览按钮的高度 ,默认值:30。
                onComplete: function (event, queueID, fileObj, response, data) {  
     $('<li></li>').appendTo('.files').text(response);          
    },
                onError: function(event, queueID, fileObj) {  
     alert("文件:" + fileObj.name + "上传失败");  
    },  
    onCancel: function(event, queueID, fileObj){  
     alert("取消了" + fileObj.name);  
    }
    });
     });
    </script>
 </head>
 
 <body style="margin-left: 0px; margin-top: 0px; margin-bottom: 0px;">
     
   <table id="test_tables"></table> 
       <div id="add" icon="icon-add" title="添加" closed="true" style="padding:5px;width:500px;height:400px;">
        <div id="fileQueue"></div>
      <input type="file" name="fileupload" id="fileupload" />
         <p>
       <a href="javascript:$('#fileupload').uploadifyUpload()">上传</a>|
       <a href="javascript:$('#fileupload').uploadifyClearQueue()">取消上传</a>
         </p>
         <s:form id="insert">
          <table align="left">
           <tr>
            <td>
             资料编号:
            </td>
            <td>
             <s:select id="addzlbh" list="dmtzllist" listKey="zlbh" listValue="zlbh" ></s:select>
            </td>
           </tr>
       </table>
         </s:form>
      </div> 
  </body>
</html>

action主要方法的代码:

@Action(value="upload_file",results={@Result(name="success",type="json")})
 public String uploadFile() {
  Scwj scwj = new Scwj();
  try {
   String extName = ""; //保存文件拓展名
   String nowTimeStr = ""; //保存当前时间
   
   //获取拓展名
         if (fileuploadFileName.lastIndexOf(".") >= 0){  
             extName = fileuploadFileName.substring(fileuploadFileName.lastIndexOf("."));
             System.err.println(extName);
         }
        
   SimpleDateFormat sDateFormat;
   Random r = new Random();
   
   sDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); //时间格式化的格式
      nowTimeStr = sDateFormat.format(new Date()); //当前时间
      System.out.println(nowTimeStr);
     
   InputStream is = new FileInputStream(fileupload);
   byte[] bt = InputStreamToByte(is);
   scwj.setFilename(fileuploadFileName);
   scwj.setFiles(bt);
   this.baseservice.save(scwj);
  } catch (Exception e) {
   e.printStackTrace();
  }
  return SUCCESS;
 }

你可能感兴趣的:(JavaScript,function,ssh,upload,Random,stylesheet)