zoukankan      html  css  js  c++  java
  • 文件的上传和下载

    文件上传和下载功能在日常生活中应用的是比较多的。

    这是界面原型:

      1 <%-- 保全-附件管理--%>
      2 <%@page contentType="text/html;charset=utf-8" %>
      3 <%@include file="../common/jsp/UsrCheck.jsp" %>
      4 
      5 <html>
      6 <%
      7     GlobalInput tG = new GlobalInput();
      8     tG = (GlobalInput) session.getAttribute("GI");
      9     String tEdorAcceptNo = request.getParameter("EdorAcceptNo");
     10     String tEdorNo = request.getParameter("EdorNo");
     11     String tPolicyNo = request.getParameter("PolicyNo");
     12     String tOutPolicyNo = request.getParameter("OutPolicyNo");
     13     String tSubMissionID = request.getParameter("SubMissionID");
     14     String tActivityID = request.getParameter("ActivityID");
     15 
     16 %>
     17 <head>
     18     <SCRIPT src="../common/javascript/Common.js"></SCRIPT>
     19     <SCRIPT src="../common/cvar/CCodeOperate.js"></SCRIPT>
     20     <SCRIPT src="../common/javascript/MulLine.js"></SCRIPT>
     21     <SCRIPT src="../common/easyQueryVer3/EasyQueryVer3.js?version=<%=System.currentTimeMillis()%>"></SCRIPT>
     22     <script type="text/javascript" src="../common/javascript/jquery-1.7.2.min.js"></script>
     23     <SCRIPT src="../common/javascript/VerifyInput.js"></SCRIPT>
     24     <SCRIPT src="../common/Calendar/Calendar.js"></SCRIPT>
     25     <LINK href="../common/css/Project.css" rel=stylesheet type=text/css>
     26     <LINK href="../common/css/Project3.css" rel=stylesheet type=text/css>
     27     <LINK href="../common/css/mulLine.css" rel=stylesheet type=text/css>
     28     <SCRIPT src="BQAppendix.js?version=<%=System.currentTimeMillis()%>"></SCRIPT>
     29     <%@include file="BQAppendixInit.jsp" %>
     30     <script Language="javascript">
     31         function fileclick(){
     32             $("#file1").click();
     33         }
     34         function ImportPathchange(){
     35             fm.ImportPath.value=fm.filename.value;
     36         }
     37     </script>
     38 </head>
     39 <body onload="initForm();initElementtype();">
     40 <%--表单上传的时候必须添加的属性:multipart/form-data--%>
     41 <form action="./BQAppendixSave.jsp" method=post name=fm target="fraSubmit" ENCTYPE="multipart/form-data">
     42     <table>
     43         <td class="common"><IMG src="../common/images/butExpand.gif" style="cursor:hand;"
     44                                 OnClick="showPage(this,divApply);"></td>
     45         <td class=titleImg>附件信息</td>
     46     </table>
     47     <div id="divApply" class=maxbox1>
     48 
     49         <table class="common">
     50             <tr class="common">
     51                 <td class="title">附件类型</td>
     52                 <td class="input"><input class="codeno" name="RiderType" verify="附件类型|NOTNULL"
     53                                          ondblclick="return ShowCodeAction('filetype',[this,RiderTypeDes],[0,1],null,['%'+fm.RiderType.value+'%'],'name');"
     54                                          onkeyup="return ShowCodeAction('filetype',[this,RiderTypeDes],[0,1],null,['%'+fm.RiderType.value+'%'],'name');"
     55                                          verify="附件类型|NOTNULL"><input class="codename" name="RiderTypeDes"
     56                                                                       style="200px"></td>
     57                 <font size=1 color='#ff0000'><b>*</b></font>
     58                 </td>
     59                 <td class="title"></td>
     60                 <td class="input"><input class="common" type="hidden" readonly></td>
     61                 <td class="title"></td>
     62                 <td class="input"><input class="common" type="hidden" readonly></td>
     63             </tr>
     64         </table>
     65     </div>
     66 
     67     <%--  <%@include file="BQAppendixUpload.jsp" %>--%>
     68     <table class=common>
     69         <tr class="common">
     70             <td class="title">文件名</td>
     71             <td class="input" style="white-space: nowrap">
     72                 <input class="common"  readonly name="ImportPath"  verify="文件名|NOTNULL">
     73                 <input value="浏览本地文件" onclick="fileclick()" class="cssButton" type="button" >
     74                 <input class="cssButton"  type="button" id="btnOpenUpload" value="上传文件" onclick="onUpload1();">
     75             </td>
     76             <td class="title"></td><td class="input"></td>
     77             <td class="title"></td><td class="input"></td>
     78         </tr>
     79         <input class=common type=file id="file1" name=file1 style="400px;display: none"  onchange="handleFile(this.value);ImportPathchange();">
     80 
     81     </table>
     82 
     83 
     84     <table class=common>
     85         <tr class=common>
     86             <td class=title colspan=6> 备注</td>
     87         </tr>
     88         <tr class=common>
     89             <td colspan="6" style="padding-left:16px"><textarea name="Remarks" cols="100%" rows="4"
     90                                                                 witdh=100% class="common"></textarea></td>
     91         </tr>
     92     </table>
     93     <input class=cssButton type=button value="保存备注" onclick="saveRemarks();"><br/>
     94 
     95 
     96     <table>
     97         <td class="common"><IMG src="../common/images/butExpand.gif" style="cursor:hand;"
     98                                 OnClick="showPage(this,divApply);"></td>
     99         <td class=titleImg>附件信息列表</td>
    100     </table>
    101     <%--引用mulline--%>
    102     <div id="divAppendix">
    103         <table class=common>
    104             <tr class=common>
    105                 <td style=" text-align: left" colSpan=1>
    106 
    107                     <span id="spanAppendixGrid"></span>
    108                 </td>
    109             </tr>
    110         </table>
    111         <input class=cssButton type=button value="下载文件" onclick="downLoadFile();">
    112         <input class=cssButton type=button value="作废" onclick="deleteFile();">
    113         <input class=cssButton type=button value="关闭" onclick="goback();">
    114 
    115 
    116     </div>
    117     <%--公共信息--%>
    118     <input id="EdorAcceptNo" name="EdorAcceptNo" type="hidden" value="<%=tEdorAcceptNo %>"><%--√--%>
    119     <input id="EdorNo" name="EdorNo" type="hidden" value="<%=tEdorNo %>"><%--√--%>
    120     <input id="PolicyNo" name="PolicyNo" type="hidden" value="<%=tPolicyNo %>"><%--√--%>
    121     <input id="OutPolicyNo" name="OutPolicyNo" type="hidden" value="<%=tOutPolicyNo %>"><%--√--%>
    122     <input id="InsuredID" name="InsuredID" type="hidden">
    123     <input id="FamilyContNo" name="FamilyContNo" type="hidden"><%--家庭单号--%>
    124     <input id="SubMissionID" name="SubMissionID" type="hidden" value="<%=tSubMissionID %>"><%--√--%>
    125     <input id="ActivityID" name="ActivityID" type="hidden" value="<%=tActivityID %>"><%--√--%>
    126     <input type=hidden id="fmtransact" name="fmtransact">
    127 
    128     <%--附件管理信息--%>
    129     <input type=hidden id="FilePath" name="FilePath">
    130     <input type=hidden id="AnnexNo" name="AnnexNo">
    131     <input type=hidden id="AnnexName" name="AnnexName">
    132     <input type=hidden id="AnnexType" name="AnnexType">
    133     <input type=hidden id="AnnexState" name="AnnexState">
    134     <input type=hidden id="Remark" name="Remark">
    135 
    136     <br>
    137     <br>
    138 </form>
    139 <span id="spanCode" style="display: none; position:absolute; slategray"></span>
    140 </body>
    141 </html>
      1 var showInfo;
      2 window.onfocus = myonfocus;
      3 var turnPage = new turnPageClass();//翻页工具
      4 var mySql = new SqlClass();
      5 
      6 
      7 //初始化查询mulline列表信息
      8 function queryAppendixGrid() {
      9     mySql = new SqlClass();
     10     mySql.setResourceName("mgubq.BQAppendixSql");
     11     mySql.setSqlId("BQAppendixSql1");
     12     mySql.addSubPara(fm.EdorAcceptNo.value);
     13     var sqlStr = mySql.getString();
     14     turnPage.queryModal(sqlStr, AppendixGrid, 1);//翻页
     15 }
     16 
     17 //【浏览本地】
     18 function browseLocal() {
     19     $("#ImportPath").click();
     20 
     21 
     22 }
     23 
     24 
     25 //上传文件按钮
     26 function onUpload1() {
     27     var myArray = ['RiderType', 'ImportPath'];
     28     if (!verifyInputgbgElem(myArray)) {
     29         alert("信息录入不完整,请补全信息!")
     30     } else {
     31         if (fm.AnnexNo.value != null && fm.AnnexNo.value != '') {
     32          //   alert("不允许重复上传");
     33         } else {
     34             fm.fmtransact.value = "uploadFile";
     35         }
     36         var showStr = "正在保存数据,请您稍候并且不要修改屏幕上的值或链接其他页面";
     37         var urlStr = "../common/jsp/MessagePage.jsp?picture=C&content=" + showStr;
     38         showInfo = showInfoWindowsDefault(urlStr, '');
     39         fm.submit();
     40     }
     41 }
     42 
     43 //【保存备注】
     44 function saveRemarks() {
     45     var i = AppendixGrid.getSelNo() - 1;
     46     if (i < 0) {
     47         alert("请选中附件信息列表中的一条记录");
     48         return;
     49     }
     50 
     51     if (fm.RiderType.value == null || fm.RiderType.value == "") {
     52         alert("附件类型不能为空");
     53         return;
     54     }
     55     if (fm.RiderTypeDes.value == null || fm.RiderTypeDes.value == "") {
     56         alert("附件类型不能为空");
     57         return;
     58     }
     59     if (fm.Remarks.value == null || fm.Remarks.value == "") {
     60         alert("请填写备注信息");
     61         return;
     62     }
     63     fm.EdorAcceptNo.value = AppendixGrid.getRowColData(i, 10);//保全受理号
     64     fm.AnnexNo.value = AppendixGrid.getRowColData(i, 9);//附件编码
     65 
     66     fm.fmtransact.value = "saveRemark";
     67     submitData();
     68 }
     69 
     70 //下载
     71 function downLoadFile(){
     72     var tSel = "";
     73     tSel= AppendixGrid.getSelNo();
     74     if(tSel<0||tSel==0){
     75         alert("请选择一条附件信息");
     76         return false;
     77     }else{
     78         var tFileName = AppendixGrid.getRowColData(tSel-1,2);
     79         var tFilePath = AppendixGrid.getRowColData(tSel-1,8);
     80         window.location = "../common/jsp/download.jsp?FilePath="+tFilePath+"&FileName="+tFileName+"&FilePathFlag=02";
     81     }
     82     fm.reset();
     83 }
     84 
     85 //【作废】
     86 function deleteFile() {
     87     var i = AppendixGrid.getSelNo() - 1;
     88     if (i < 0) {
     89         alert("请选择需要操作的信息!");
     90         return;
     91     }
     92     fm.fmtransact.value = "delete";
     93     fm.AnnexNo.value = AppendixGrid.getRowColData(i, 9);
     94 
     95     submitData();
     96 
     97 
     98 }
     99 //【关闭】
    100 function goback() {
    101     window.top.close();
    102 }
    103 
    104 
    105 function submitData() {
    106     var showStr = "正在保存数据,请您稍候并且不要修改屏幕上的值或链接其他页面";
    107     var urlStr = "../common/jsp/MessagePage.jsp?picture=C&content=" + showStr;
    108     var name = '提示';
    109     var iWidth = 550;
    110     var iHeight = 250;
    111     var iTop = (window.screen.availHeight - iHeight) / 2;
    112     var iLeft = (window.screen.availWidth - iWidth) / 2;
    113     showInfo = showInfoWindows(urlStr, name, "status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no,height=" + iHeight + ",width=" + iWidth + ",innerHeight=" + iHeight + ",innerWidth=" + iWidth + ",left=" + iLeft + ",top=" + iTop, false);
    114     showInfo.focus();
    115     document.all('fm').action = "BQAppendixSave.jsp";
    116     document.all('fm').submit();
    117 }
    118 //选中mulline中的一条记录
    119 function selectOneRecord() {
    120     var i = AppendixGrid.getSelNo() - 1;
    121     fm.RiderType.value = AppendixGrid.getRowColData(i, 1);//附件类型
    122     fm.RiderTypeDes.value = AppendixGrid.getRowColData(i, 11);//附件类型名称
    123     fm.ImportPath.value = AppendixGrid.getRowColData(i, 2);//文件名
    124     fm.Remarks.value = AppendixGrid.getRowColData(i, 3);//备注
    125 
    126 }
    127 
    128 //判断上载文件格式
    129 function handleFile(filename) {
    130     var fileName = filename;
    131     var fname = fileName.substr(fileName.lastIndexOf('\\') + 1);
    132     fm.ImportPath.value = fname;
    133     var indexFirst = fileName.lastIndexOf("\\");
    134     var indexLast = fileName.lastIndexOf(".");
    135 
    136     if (indexFirst < 0 || indexLast < 0 || indexLast <= indexFirst) {
    137         alert("文件路径不合法或选择的文件格式不正确,请重新选择!");
    138         return false;
    139     }
    140     var index1 = fileName.lastIndexOf(".");
    141     var index2 = fileName.length;
    142     var filetype = fileName.substring(index1, index2);
    143     if (!/\.(pdf|PDF|gif|GIF|PNG|png|jpg|JPG|bmp|BMP|docx|DOCX|dotx|DOTX|doc|DOC|dot|DOT|docm|DOCM|dotm|DOTM|xls|XLS|xlsx|XLSX|xlsb|XLSB|xlsm|XLSM|xlst|XLST)$/.test(filetype)) {
    144         alert("文件类型必须是pdf,gif,word,jpg,excel中的一种");
    145         fm.ImportPath.value = "";
    146         return false;
    147     }
    148 }
    149 
    150 function ImportPathchange() {
    151     $("#FileName")[0].value = fm.ImportPath.value;
    152     //  fm.AnnexName.value=fm.ImportPath.value;使用这种方式不知怎么搞的就是赋不上值,所以采用jquery的方式
    153 
    154 }
    155 //模仿:信息维护-->承保单位管理-->合同维护 不加的话双击下拉出不来
    156 function ShowCodeAction(v1, v2, v3, v4, v5, v6) {
    157     return showCodeList(v1, v2, v3, v4, v5, v6);
    158 }
    159 // 提交完成后所作操作
    160 function afterSubmit(FlagStr, content) {
    161     showInfo.close();
    162     if (FlagStr == "Fail") {
    163         var urlStr = "../common/jsp/MessagePage.jsp?picture=C&content=" + content;
    164         var name = '提示';
    165         var iWidth = 550;
    166         var iHeight = 350;
    167         var iTop = (window.screen.availHeight - iHeight) / 2;
    168         var iLeft = (window.screen.availWidth - iWidth) / 2;
    169         showInfo = window.open(urlStr, name, "status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no,height=" + iHeight + ",width=" + iWidth + ",innerHeight=" + iHeight + ",innerWidth=" + iWidth + ",left=" + iLeft + ",top=" + iTop, false);
    170         showInfo.focus();
    171     } else {
    172         var urlStr = "../common/jsp/MessagePage.jsp?picture=S&content=" + content;
    173         var name = '提示';
    174         var iWidth = 550;
    175         var iHeight = 350;
    176         var iTop = (window.screen.availHeight - iHeight) / 2;
    177         var iLeft = (window.screen.availWidth - iWidth) / 2;
    178         showInfo = window.open(urlStr, name, "status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no,height=" + iHeight + ",width=" + iWidth + ",innerHeight=" + iHeight + ",innerWidth=" + iWidth + ",left=" + iLeft + ",top=" + iTop, false);
    179         showInfo.focus();
    180         //点击完按钮,刷新页面
    181         initAppendixGrid();
    182         queryAppendixGrid();
    183         fm.reset();
    184     }
    185 }
      1 <script language="JavaScript">
      2     function initForm() {
      3         try {
      4 
      5             initAppendixGrid();
      6             //初始化查询mulline列表信息
      7             queryAppendixGrid();
      8         } catch (re) {
      9             alert("BQAppendixInit.jsp-->InitForm函数中发生异常:初始化界面错误!");
     10         }
     11     }
     12 
     13 
     14     //把null的字符串转为空
     15     function nullToEmpty(string) {
     16         if ((string == "null") || (string == "undefined")) {
     17             string = "";
     18         }
     19         return string;
     20     }
     21 
     22     function initAppendixGrid() {
     23         var iArray = new Array();
     24         try {
     25             iArray[0] = new Array();
     26             iArray[0][0] = "序号";
     27             iArray[0][1] = "20px";
     28             iArray[0][2] = 100;
     29             iArray[0][3] = 0;
     30 
     31             iArray[1] = new Array();
     32             iArray[1][0] = "附件类型";
     33             iArray[1][1] = "50px";
     34             iArray[1][2] = 100;
     35             iArray[1][3] = 0;
     36 
     37             iArray[2] = new Array();
     38             iArray[2][0] = "文件名";
     39             iArray[2][1] = "50px";
     40             iArray[2][2] = 100;
     41             iArray[2][3] = 0;
     42 
     43             iArray[3] = new Array();
     44             iArray[3][0] = "备注";
     45             iArray[3][1] = "50px";
     46             iArray[3][2] = 100;
     47             iArray[3][3] = 0;
     48 
     49             iArray[4] = new Array();
     50             iArray[4][0] = "操作人";
     51             iArray[4][1] = "80px";
     52             iArray[4][2] = 100;
     53             iArray[4][3] = 0;
     54 
     55             iArray[5] = new Array();
     56             iArray[5][0] = "操作日期";
     57             iArray[5][1] = "40px";
     58             iArray[5][2] = 100;
     59             iArray[5][3] = 0;
     60 
     61             iArray[6] = new Array();
     62             iArray[6][0] = "操作时间";
     63             iArray[6][1] = "40px";
     64             iArray[6][2] = 100;
     65             iArray[6][3] = 0;
     66 
     67             iArray[7] = new Array();
     68             iArray[7][0] = "附件状态";
     69             iArray[7][1] = "40px";
     70             iArray[7][2] = 100;
     71             iArray[7][3] = 0;
     72 
     73             iArray[8] = new Array();
     74             iArray[8][0] = "文件路径";
     75             iArray[8][1] = "0px";
     76             iArray[8][2] = 100;
     77             iArray[8][3] = 0;
     78 
     79             iArray[9] = new Array();
     80             iArray[9][0] = "附件编码";
     81             iArray[9][1] = "0px";
     82             iArray[9][2] = 100;
     83             iArray[9][3] = 0;
     84 
     85             iArray[10] = new Array();
     86             iArray[10][0] = "保全受理号";
     87             iArray[10][1] = "0px";
     88             iArray[10][2] = 100;
     89             iArray[10][3] = 0;
     90 
     91             iArray[11] = new Array();
     92             iArray[11][0] = "附件类型名称";
     93             iArray[11][1] = "0px";
     94             iArray[11][2] = 100;
     95             iArray[11][3] = 0;
     96 
     97             AppendixGrid = new MulLineEnter("fm", "AppendixGrid");
     98             AppendixGrid.mulLineCount = 1;
     99             AppendixGrid.displayTitle = 1;
    100             AppendixGrid.canSel = 1;
    101             AppendixGrid.canChk = 0;
    102             AppendixGrid.hiddenPlus = 1;
    103             AppendixGrid.hiddenSubtraction = 1;
    104             AppendixGrid.selBoxEventFuncName = "selectOneRecord";
    105             AppendixGrid.loadMulLine(iArray);
    106         } catch (ex) {
    107              alert(ex);
    108         }
    109     }
    110 </script>
      1 <!--用户校验类-->
      2 <%@include file="../common/jsp/UsrCheck.jsp" %>
      3 
      4 <%@page contentType="text/html;charset=utf-8" %>
      5 
      6 <%
      7 
      8     //程序名称:BQAppendixSave.jsp
      9 //程序功能:附件管理
     10 //创建日期:2014/11/11
     11 //创建人  :
     12 //更新记录:  更新人    更新日期     更新原因/内容
     13 %>
     14 
     15 <%--<%@page pageEncoding="UTF-8" contentType="text/html; charset=utf-8"%>--%>
     16 <%@include file="../common/jsp/UsrCheck.jsp" %>
     17 <%@page import="com.sinosoft.utility.*" %>
     18 <%@page import="com.sinosoft.lis.pubfun.PubFun" %>
     19 <%@page import="java.util.*" %>
     20 <%@page import="java.io.File" %>
     21 <%@page import="org.apache.commons.fileupload.*" %>
     22 <%@ page import="org.apache.log4j.Logger" %>
     23 <%@ page import="com.sinosoft.lis.mgubq.BQAppendixUI" %>
     24 
     25 
     26 <%
     27     //输出参数
     28 
     29     String FlagStr = "";
     30     String Content = "";
     31     boolean flag = true;
     32 
     33     GlobalInput tG = new GlobalInput();
     34     tG = (GlobalInput) session.getValue("GI");
     35     if (tG == null) {
     36         FlagStr = "Fail";
     37         Content = "页面失效,请重新登陆";
     38         Logger.getLogger("BQAppendixSave").info("页面失效,请重新登陆");
     39         return;
     40     }
     41 
     42 
     43     //合同文件
     44     String tFileName = "";
     45     String UploadPath = "";
     46     String UploadPath1 = "";
     47     String tSysUploadPath = "";
     48     String tExtenName = "";
     49 
     50 
     51     String mOperator = request.getParameter("fmtransact");//操作符
     52     String mEdorAcceptNo = "";//保全受理号
     53     String mAnnexNo = "";//附件编号
     54     String mAnnexName = "";//附件名称
     55     String mAnnexType = "";//附件类型
     56     String mAnnexState = "";//附件状态
     57     String mRemark = "";//备注
     58     String mFilePath = "";//文件路径
     59     TransferData mTransferData = new TransferData();
     60     //准备传输数据 VData
     61 
     62 
     63     String tCurrentDate = PubFun.getCurrentDate();
     64     String tCurrentTime = PubFun.getCurrentTime();
     65     tCurrentDate = tCurrentDate.replace("-", "");
     66     tCurrentTime = tCurrentTime.replace(":", "");
     67 
     68 
     69     ExeSQL tExeSQL = new ExeSQL();
     70     String tSql = "select sysvarvalue from ldsysvar where sysvar='UploadPath'";
     71     String tSql1 = "select sysvarvalue from ldsysvar where sysvar='uploadPathLI'";
     72     UploadPath = tExeSQL.getOneValue(tSql);
     73     UploadPath1 = tExeSQL.getOneValue(tSql1);
     74     tSysUploadPath = UploadPath + UploadPath1;
     75 
     76     if (tSysUploadPath == null || "".equals(tSysUploadPath)) {
     77         Content = "未配置附件上传路径!";
     78         FlagStr = "Fail";
     79     } else {
     80 
     81         if (!tSysUploadPath.endsWith("/")) {
     82             tSysUploadPath += "/";
     83         }
     84 
     85         File tFile = new File(tSysUploadPath);
     86         if (!tFile.exists()) {
     87             tFile.mkdirs();
     88         }
     89         File tTempFile = new File(tSysUploadPath + "/LIAttachmentFileList/");
     90         if (!tTempFile.exists()) {
     91             tTempFile.mkdirs();
     92         }
     93 
     94         DiskFileUpload tDiskFileUpload = new DiskFileUpload();
     95         //设置允许用户上传文件大小,单位:字节
     96         tDiskFileUpload.setSizeMax(102400000);
     97         //设置最多只允许在内存中存储的数据,单位:字节
     98         tDiskFileUpload.setSizeThreshold(4096);
     99         //设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录
    100         tDiskFileUpload.setRepositoryPath(tSysUploadPath + "/LIAttachmentFileList/");
    101         tDiskFileUpload.setHeaderEncoding("utf-8");
    102 
    103         //开始读取上传信息
    104         List tList = tDiskFileUpload.parseRequest(request);
    105         Iterator tIterator = tList.iterator();
    106 
    107         while (tIterator.hasNext()) {
    108 
    109             FileItem tFileItem = (FileItem) tIterator.next();
    110             //忽略其他不是文件域的所有表单信息
    111             if (tFileItem.isFormField()) {
    112                 String mFieldName = tFileItem.getFieldName();
    113                 if ("EdorAcceptNo".equals(mFieldName)) {
    114                     mEdorAcceptNo = tFileItem.getString("utf-8");
    115                 } else if ("AnnexNo".equals(mFieldName)) {
    116                     mAnnexNo = tFileItem.getString("utf-8");
    117                 } else if ("FileName".equals(mFieldName)) {
    118                     mAnnexName = tFileItem.getString("utf-8");
    119                 } else if ("RiderType".equals(mFieldName)) {//附件类型
    120                     mAnnexType = tFileItem.getString("utf-8");
    121                 } else if ("AnnexState".equals(mFieldName)) {
    122                     mAnnexState = tFileItem.getString("utf-8");
    123                 } else if ("Remarks".equals(mFieldName)) {
    124                     mRemark = tFileItem.getString("utf-8");
    125                 } else if ("FilePath".equals(mFieldName)) {
    126                     mFilePath = tFileItem.getString("utf-8");
    127                 } else if ("fmtransact".equals(mFieldName)) {
    128                     mOperator = tFileItem.getString("utf-8");//操作符
    129                 }
    130 
    131             } else {
    132                 String tItemName = tFileItem.getName();
    133                 long tItemSize = tFileItem.getSize();
    134                 if ((tItemName == null || "".equals(tItemName)) && tItemSize == 0) {
    135                     continue;
    136                 }
    137                 tFileName = tItemName.replace('\\', '/');
    138                 tFileName = tFileName.substring(tFileName.lastIndexOf("/") + 1);
    139                 tExtenName = tFileName.substring(tFileName.lastIndexOf(".") + 1);
    140 
    141                 try {
    142                     tFileItem.write(new File(tSysUploadPath + tCurrentDate + tCurrentTime + "." + tExtenName));
    143                     FlagStr = "Succ";
    144                     Content = "上传文件成功";
    145                 } catch (Exception e) {
    146                     FlagStr = "Fail";
    147                     Content = "上传文件失败";
    148                 }
    149             }
    150         }
    151     }
    152 
    153     mTransferData.setNameAndValue("EdorAcceptNo", mEdorAcceptNo);//保全受理号
    154     mTransferData.setNameAndValue("AnnexType", mAnnexType);//附件类型
    155     mTransferData.setNameAndValue("AnnexName", mAnnexName);//文件名
    156     mTransferData.setNameAndValue("Remarks", mRemark);//备注
    157     mTransferData.setNameAndValue("AnnexNo", mAnnexNo);
    158     mTransferData.setNameAndValue("FileName",tFileName);
    159     mTransferData.setNameAndValue("FilePath",tSysUploadPath+tCurrentDate+tCurrentTime+"."+tExtenName);
    160     try {
    161         VData tVData = new VData();
    162         tVData.add(tG);
    163         tVData.add(mTransferData);
    164         Logger.getLogger("BQAppendixSave").info("-------------------开始提交数据---------------------");
    165         BQAppendixUI tBQAppendixUI = new BQAppendixUI();
    166         if (!tBQAppendixUI.submitData(tVData, mOperator)) {
    167             if (tBQAppendixUI.getErrors() != null && tBQAppendixUI.getErrors().getErrorCount() > 0) {
    168                 Content = "数据保存失败,原因是:" + tBQAppendixUI.getErrors().getError(0).errorMessage;
    169                 FlagStr = "Fail";
    170             } else {
    171                 Content = "数据保存失败";
    172                 FlagStr = "Fail";
    173             }
    174         } else {
    175             Content = " 数据提交成功!";
    176             FlagStr = "Succ";
    177         }
    178         Logger.getLogger("BQAppendixSave").info("-------------------数据提交完毕---------------------");
    179     } catch (Exception ex) {
    180         Content = "数据提交失败,原因是:" + ex.toString();
    181         FlagStr = "Fail";
    182     }
    183 
    184 
    185 %>
    186 <%=Content%>
    187 <html>
    188 <script language="javascript">
    189     parent.fraInterface.afterSubmit("<%=FlagStr%>", "<%=Content%>");
    190 </script>
    191 </html>
     1 package com.sinosoft.lis.mgubq;
     2 
     3 import com.sinosoft.service.BusinessService;
     4 import com.sinosoft.utility.CError;
     5 import com.sinosoft.utility.CErrors;
     6 import com.sinosoft.utility.VData;
     7 
     8 /**
     9  * 保全-附件管理
    10  */
    11 public class BQAppendixUI implements BusinessService {
    12 
    13     /**
    14      * 错误处理类,每个需要错误处理的类中都放置该类
    15      */
    16     public CErrors mErrors = new CErrors();
    17 
    18     private VData mResult = new VData();
    19 
    20     /**
    21      * 数据操作字符串
    22      */
    23     private String mOperate;
    24 
    25     // 业务处理相关变量
    26 
    27     public BQAppendixUI() {
    28     }
    29 
    30     /**
    31      * 传输数据的公共方法
    32      */
    33     public boolean submitData(VData cInputData, String cOperate) {
    34         // 将操作数据拷贝到本类中
    35         this.mOperate = cOperate;
    36         this.mResult.clear();
    37         BQAppendixBL tBQAppendixBL = new BQAppendixBL();
    38         // 如果有需要处理的错误,则返回
    39         if (!tBQAppendixBL.submitData(cInputData, mOperate)) {
    40             // @@错误处理
    41             this.mErrors.copyAllErrors(tBQAppendixBL.mErrors);
    42             CError tError = new CError();
    43             tError.moduleName = "BQAppendixUI";
    44             tError.functionName = "submitData";
    45             tError.errorMessage = "数据提交失败!";
    46             this.mErrors.addOneError(tError);
    47             return false;
    48         }
    49         this.mResult.clear();
    50         this.mResult = tBQAppendixBL.getResult();
    51         return true;
    52     }
    53     @Override
    54     public VData getResult() {
    55         return this.mResult;
    56     }
    57 
    58     @Override
    59     public CErrors getErrors() {
    60         return mErrors;
    61     }
    62 
    63     public static void main(String[] args) {
    64 
    65     }
    66 
    67 }
      1 package com.sinosoft.lis.mgubq;
      2 
      3 import com.sinosoft.lis.db.LPEdorAnnexDB;
      4 import com.sinosoft.lis.pubfun.*;
      5 import com.sinosoft.lis.schema.LPEdorAnnexSchema;
      6 import com.sinosoft.utility.CError;
      7 import com.sinosoft.utility.CErrors;
      8 import com.sinosoft.utility.TransferData;
      9 import com.sinosoft.utility.VData;
     10 import org.apache.log4j.Logger;
     11 
     12 
     13 /**
     14  * 保全-附件管理
     15  */
     16 public class BQAppendixBL {
     17     //日志组件
     18     private Logger mlogger = Logger.getLogger(BQAppendixBL.class);
     19     /**
     20      * 错误处理类,每个需要错误处理的类中都放置该类
     21      */
     22     public CErrors mErrors = new CErrors();
     23     /**
     24      * 往后面传输数据的容器
     25      */
     26     private VData mInputData = new VData();
     27 
     28     /**
     29      * 业务处理相关变量
     30      */
     31     private final MMap mMap = new MMap();
     32     /**
     33      * 业务处理相关变量
     34      */
     35     private final VData mResult = new VData();
     36 
     37     private String mCurrentDate = PubFun.getCurrentDate();
     38     private String mCurrentTime = PubFun.getCurrentTime();
     39 
     40     private GlobalInput mG = new GlobalInput();
     41 
     42     private TransferData mTransferData = new TransferData();
     43 
     44     // 保单信息表
     45     private LPEdorAnnexSchema tLPEdorAnnexSchema = null;
     46 
     47     // 内部保单号
     48     private String mContNo = "";
     49     // 保全编码
     50     private String mEdorCode = "";
     51     private String tEdorAcceptNo = "";
     52     private String tOperator = "";
     53     private String tAnnexNo = "";
     54     private String tAnnexType = "";
     55     private String tAnnexName = "";
     56     private String tRemark = "";
     57     private String tFileName="";
     58     private String tFilePath="";
     59 
     60 
     61     public BQAppendixBL() {
     62     }
     63 
     64     /**
     65      * @param cInputData 输入的数据
     66      * @param cOperate   数据操作
     67      * @return 结果
     68      */
     69     public boolean submitData(VData cInputData, String cOperate) {
     70         this.mInputData = cInputData;
     71         this.tOperator = cOperate;
     72 
     73         if (!getInputData()) {
     74             return false;
     75         }
     76 
     77         if (!checkData()) {
     78             return false;
     79         }
     80 
     81         // 进行业务处理
     82         if (!dealData()) {
     83             return false;
     84         }
     85 
     86         if (!prepareOutputData()) {
     87             return false;
     88         }
     89 
     90         PubSubmit tPubSubmit = new PubSubmit();
     91 
     92         if (!tPubSubmit.submitData(mResult, "")) {
     93             // @@错误处理
     94             this.mErrors.copyAllErrors(tPubSubmit.mErrors);
     95             CError tError = new CError();
     96             tError.moduleName = "BQAcceptApplyPoolBL";
     97             tError.functionName = "submitData";
     98             tError.errorMessage = "数据提交失败!";
     99             this.mErrors.addOneError(tError);
    100             return false;
    101         }
    102         mInputData = null;
    103         return true;
    104     }
    105 
    106     /**
    107      * @return 从输入数据中得到所有对象 输出:如果没有得到足够的业务数据对象,则返回false,否则返回true
    108      */
    109     private boolean getInputData() {
    110         mG = (GlobalInput) mInputData.getObjectByObjectName("GlobalInput", 0); // 按类取值
    111         tLPEdorAnnexSchema = (LPEdorAnnexSchema) mInputData.getObjectByObjectName("LPEdorAnnexSchema", 0); // 按类取值
    112         mTransferData = (TransferData) mInputData.getObjectByObjectName("TransferData", 0);
    113         tEdorAcceptNo = (String) mTransferData.getValueByName("EdorAcceptNo");
    114         tAnnexNo = (String) mTransferData.getValueByName("AnnexNo");
    115         tAnnexType = (String) mTransferData.getValueByName("AnnexType");
    116         tAnnexName = (String) mTransferData.getValueByName("AnnexName");
    117         tRemark = (String) mTransferData.getValueByName("Remarks");
    118         tFileName=(String)mTransferData.getValueByName("FileName");
    119         tFilePath=(String) mTransferData.getValueByName("FilePath");
    120 
    121 
    122         return true;
    123     }
    124 
    125     /**
    126      * @return 从输入数据中得到所有对象 输出:如果没有得到足够的业务数据对象,则返回false,否则返回true
    127      */
    128     private boolean checkData() {
    129         if ("uploadFile".equals(tOperator)) {
    130 
    131         } else {
    132             if ("".equals(tEdorAcceptNo) || tEdorAcceptNo == null) {
    133                 CError tError = new CError();
    134                 tError.moduleName = "BQAppendixBL";
    135                 tError.functionName = "checkData";
    136                 tError.errorMessage = "没有对应的保全受理号";
    137                 this.mErrors.addOneError(tError);
    138                 return false;
    139             }
    140         }
    141 
    142         //如果是操作符是-保存备注-那就不需要校验了,因为下面会自动生成
    143         if ("saveRemark".equals(tOperator) || "uploadFile".equals(tOperator)) {
    144 
    145         } else {
    146             if ("".equals(tAnnexNo) || tAnnexNo == null) {
    147                 CError tError = new CError();
    148                 tError.moduleName = "BQAppendixBL";
    149                 tError.functionName = "checkData";
    150                 tError.errorMessage = "没有对应的附件编码";
    151                 this.mErrors.addOneError(tError);
    152                 return false;
    153             }
    154 
    155         }
    156 
    157 
    158         return true;
    159     }
    160 
    161     /**
    162      * @return 从输入数据中得到所有对象 输出:如果没有得到足够的业务数据对象,则返回false,否则返回true
    163      */
    164     private boolean dealData() {
    165         // 作废-功能
    166         if ("delete".equals(tOperator)) {
    167 
    168             LPEdorAnnexDB tLPEdorAnnexDB = new LPEdorAnnexDB();
    169             tLPEdorAnnexDB.setEdorAcceptNo(tEdorAcceptNo);
    170             tLPEdorAnnexDB.setAnnexNo(tAnnexNo);
    171             if (!tLPEdorAnnexDB.getInfo()) {
    172                 CError tError = new CError();
    173                 tError.moduleName = "BQAppendixBL";
    174                 tError.functionName = "dealData";
    175                 tError.errorMessage = "没有查询到该附件信息";
    176                 this.mErrors.addOneError(tError);
    177                 return false;
    178             }
    179             //因为是通过这张表的两个主键进行查询的,所以只能够查询到一条记录
    180             tLPEdorAnnexSchema = tLPEdorAnnexDB.getSchema();
    181             tLPEdorAnnexSchema.setAnnexState("02");
    182             tLPEdorAnnexSchema.setModifyDate(mCurrentDate);
    183             tLPEdorAnnexSchema.setModifyTime(mCurrentTime);
    184             mMap.put(tLPEdorAnnexSchema, "UPDATE");
    185         }
    186         //保存备注-功能
    187         if ("saveRemark".equals(tOperator)) {
    188             LPEdorAnnexDB tLPEdorAnnexDB=new LPEdorAnnexDB();
    189             tLPEdorAnnexDB.setEdorAcceptNo(tEdorAcceptNo);
    190             tLPEdorAnnexDB.setAnnexNo(tAnnexNo);
    191             if(!tLPEdorAnnexDB.getInfo()){
    192                 CError tError = new CError();
    193                 tError.moduleName = "BQAppendixBL";
    194                 tError.functionName = "checkData";
    195                 tError.errorMessage = "没有对应的附件信息";
    196                 this.mErrors.addOneError(tError);
    197                 return false;
    198             }
    199             tLPEdorAnnexSchema=tLPEdorAnnexDB.getSchema();
    200             tLPEdorAnnexSchema.setRemark(tRemark);//备注信息
    201             mMap.put(tLPEdorAnnexSchema,"UPDATE");
    202 
    203         }
    204         //文件上传
    205         if("uploadFile".equals(tOperator)){
    206             tLPEdorAnnexSchema = new LPEdorAnnexSchema();
    207             tLPEdorAnnexSchema.setEdorAcceptNo(tEdorAcceptNo);
    208             //TODO 先暂定附件编码的生成规则是这样,后期需要改动再进行改动
    209             String tQuestionID = PubFun1.CreateMaxNo("QuestionID", 10);
    210             tLPEdorAnnexSchema.setAnnexNo(tQuestionID);
    211             tLPEdorAnnexSchema.setAnnexType(tAnnexType);
    212             tLPEdorAnnexSchema.setAnnexParth(tFilePath);//文件名
    213 
    214 
    215             tLPEdorAnnexSchema.setAnnexName(tFileName);
    216             tLPEdorAnnexSchema.setRemark(tRemark);
    217             tLPEdorAnnexSchema.setAnnexState("01");//有效
    218             tLPEdorAnnexSchema.setCreator(mG.Operator);
    219             tLPEdorAnnexSchema.setOperator(mG.Operator);
    220             tLPEdorAnnexSchema.setMakeDate(mCurrentDate);
    221             tLPEdorAnnexSchema.setMakeTime(mCurrentTime);
    222             tLPEdorAnnexSchema.setModifyDate(mCurrentDate);
    223             tLPEdorAnnexSchema.setModifyTime(mCurrentTime);
    224             mMap.put(tLPEdorAnnexSchema, "DELETE&INSERT");
    225 
    226         }
    227 
    228         return true;
    229     }
    230 
    231     /**
    232      * @return 从输入数据中得到所有对象 输出:如果没有得到足够的业务数据对象,则返回false,否则返回true
    233      */
    234     private boolean prepareOutputData() {
    235         try {
    236             this.mInputData = new VData();
    237             this.mInputData.add(this.mMap);
    238             mResult.clear();
    239             mResult.add(this.mMap);
    240         } catch (Exception ex) {
    241             // @@错误处理
    242             CError tError = new CError();
    243             tError.moduleName = "BQAppendixBL";
    244             tError.functionName = "prepareOutputData";
    245             tError.errorMessage = "在准备往后层处理所需要的数据时出错。";
    246             this.mErrors.addOneError(tError);
    247             return false;
    248         }
    249         return true;
    250     }
    251 
    252     /**
    253      * @return 结果
    254      */
    255     public VData getResult() {
    256         return this.mResult;
    257     }
    258 
    259     /**
    260      * @param args 参数
    261      */
    262 
    263     public static void main(String[] args) {
    264         String tt = PubFun1.CreateMaxNo("EDORACCEPTNO", PubFun.getCurrentDate());
    265         System.out.println("------------- " + tt);
    266     }
    267 
    268 
    269 }
    1 #保全附件管理
    2 BQAppendixSql1=SELECT l.annextype 附件类型,l.annexname 附件,l.remark 备注说明,l.operator 操作人,l.makedate 入机日期,l.maketime 修改时间,(select codename from ldcode where codetype='filestate' and code=l.annexstate) 附件状态,l.annexParth 文件路径,l.annexNo 附件编码,l.edoracceptNo 保全受理号,(SELECT a.codename FROM LDCODE a WHERE a.CODETYPE=''filetype'' and a.code=l.annextype) 附件类型名称 FROM lpedorannex l where 1=1 AND l.ANNEXSTATE!=''02''  {0}
    3 #保全受理号
    4 BQAppendixSql1_0= and l.edoracceptno=''{0}''
     1 <%
     2 /***************************************************************
     3  * <p>ProName:download.jsp</p>
     4  * <p>Title:下载文件页面</p>
     5  * <p>Description:下载文件页面</p>
     6  * <p>Copyright:Copyright (c) 2012</p>
     7  * <p>Company:Sinosoft</p>
     8  * @author   : sinosoft
     9  * @version  : 8.0
    10  * @date     : 2012-01-01
    11  ****************************************************************/
    12 %>
    13 <%@ page pageEncoding="UTF-8" contentType="text/html; charset=utf-8"%>
    14 <%@page import="java.io.*"%>
    15 <%@page import="java.util.*"%>
    16 <%@page import="com.sinosoft.utility.*"%>
    17 <%@ page import="java.net.URLEncoder" %>
    18 
    19 <%
    20     try {
    21         
    22         //String fileName = java.net.URLDecoder.decode(request.getParameter("FileName"), "UTF-8");
    23         //fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
    24         //String filePath = java.net.URLDecoder.decode(request.getParameter("FilePath"), "UTF-8");
    25         
    26         String fileName = request.getParameter("FileName");
    27         String filePath = request.getParameter("FilePath");
    28         String filePathflag = request.getParameter("FilePathFlag");
    29 
    30         //获取文件名字符集,response.setHeader()文件名字符集必须是ISO8859-1
    31 
    32 //        fileName = new String(fileName.getBytes(), "ISO8859-1");
    33 //        if(request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0){
    34             fileName = URLEncoder.encode(fileName , "UTF-8");
    35 //        }else{
    36 //            fileName = new String(fileName .getBytes(),"ISO8859-1");
    37 //        }
    38         String path = this.getClass().getClassLoader().getResource("").getPath().toString()+"plan/";
    39         path = path.substring(0,path.indexOf("WEB-INF"))+"template/";
    40         if(filePathflag!=null && "01".equals(filePathflag)){
    41             filePath=path+filePath;
    42         }
    43 
    44         response.setContentType("APPLICATION/OCTET-STREAM;");
    45         response.setHeader("Content-Disposition", "attachment;filename="+fileName);
    46         ServletOutputStream sos = response.getOutputStream();
    47         out.clear();
    48         out = pageContext.pushBody();
    49         FileInputStream fis = new FileInputStream(filePath);
    50         
    51         int j;
    52         while ((j=fis.read()) != -1) {    
    53             sos.write(j);   
    54         }
    55         sos.close();     
    56         fis.close();
    57     } catch(Exception e) {
    58         e.printStackTrace();
    59         System.out.println("File download Exception ...");
    60     }
    61 %>

    总结:按理说本地启动tomcat,是不会将文件上传到服务器上面的,但是自己的不知道怎么是可以的。

     正常情况下/var/tomcat这类的路径是是服务器上面的路径,如果你没有启动tomcat的话,你上传的这个文件应该是在你本地的电脑上面的某个路径下面。但是我的不知怎么搞的没有找到。按理说,你本地启动项目上传的那个文件应该是在项目中的,或者是在tomcat的某个路径下面的。

  • 相关阅读:
    jacob根据word模板和书签插入内容,在jacob1.14.3测试成功...
    在.NET上如何根据字符串动态创建控件
    rabbitvcs一款在Linux平台下类似于乌龟的SVN客户端
    平时摘录开发经验
    C#中treeview绑定xml
    ubuntu下SVN服务器安装配置
    网页中的一些常用快捷键
    python 数据类型
    python 删除空文件夹脚本
    删除指定文件的python脚本
  • 原文地址:https://www.cnblogs.com/dongyaotou/p/11718023.html
Copyright © 2011-2022 走看看