struts上传多附件及修改

 
update.jsp
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2.     pageEncoding="UTF-8" import="java.util.*"%>
  3. <%@ taglib uri="/WEB-INF/taglib/struts-bean.tld" prefix="bean"%>
  4. <%@ taglib uri="/WEB-INF/taglib/struts-html.tld" prefix="html"%>
  5. <%@ taglib uri="/WEB-INF/taglib/struts-logic.tld" prefix="logic"%>
  6. <%
  7.     String path = request.getContextPath();
  8.     String basePath = request.getScheme() + "://"
  9.             + request.getServerName() + ":" + request.getServerPort()
  10.             + path;
  11.     String message = (String) request.getAttribute("msg");
  12.     List list = (List) request.getAttribute("attachmentList");
  13.     int size = 0;
  14.     if (list != null) {
  15.         size = list.size();
  16.     }
  17.     int currentpage = ((Integer) request.getAttribute("oldPage"))
  18.             .intValue();
  19. %>
  20. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  21. <html>
  22. <head>
  23. <title>修改公告</title>
  24. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  25. <meta http-equiv="pragma" content="no-cache" />
  26. <link href="<%=basePath%>/css/common.css" rel="stylesheet"
  27.     type="text/css" />
  28. <script src="<%=basePath%>/js/prototype.js"></script>
  29. <script src="<%=basePath%>/js/common.js"></script>
  30. <script src="<%=basePath%>/js/WebCalendar.js"></script>
  31. <script src="../js/credit/credit.js"></script>
  32. <script src="../js/AjaxBean.js"></script>
  33. <style>     
  34. a.addfile {     
  35. background-image:url(../image/all_toolbar.gif);     
  36. color: #375771;
  37. font-weight: bold;
  38. text-align: center;
  39. font-size: 12px;
  40. display:block;     
  41. float:left;     
  42. height:28px;     
  43. margin-top:-1px;    
  44. position:relative;    
  45. text-decoration:none;     
  46. top:0pt;     
  47. width:38px;     
  48. }    
  49. input.addfile {   
  50. /*left:-18px;*/    
  51. }     
  52. input.addfile {     
  53. cursor:pointer !important;     
  54. height:28px;     
  55. left:-10px;     
  56. filter:alpha(opacity=0);     
  57. position:absolute;     
  58. top:2px;     
  59. width:1px;
  60.   
  61. }
  62. </style>
  63. <script type="text/javascript">
  64. function doUpdate(type) {
  65.     //获取标题
  66.     var title = $F("title");
  67.     var length = getStringLength(title);
  68.     if (length == 0) {
  69.         alert("标题不能为空");
  70.         $("title").focus();
  71.         return;
  72.     }
  73.     if (length > 90) {
  74.         alert("标题只能输入90个字符(30个汉字),当前长度为:" + length);
  75.         $("title").focus();
  76.         return;
  77.     }
  78.     //获取内容  
  79.     if(!check('content','公告内容')){ $('content').focus();return;}
  80.     if(get('content') != "")
  81.     {
  82.        var length = getStringLength($F('content'));
  83.        if (length > 1500) {
  84.             alert("公告内容最多只能输入1500个字符(500个汉字)");
  85.             $('content').focus();
  86.             return;
  87.        }
  88.     }  
  89.     
  90.     //获取选取的产品ID
  91.     var checkProductArr = checkedCheckBox("checkProductType");
  92.     if (checkProductArr.length == 0) {
  93.         alert("请勾选产品类别");
  94.         return;
  95.     }
  96.     //获取选取的级别ID
  97.     var checkGradeArr = checkedCheckBox("checkDistributeGrade");
  98.     if (checkGradeArr.length == 0) {
  99.         alert("请勾选分销商级别");
  100.         return;
  101.     }
  102.     //获取选取的省份ID
  103.     var checkProvinceArr = checkedCheckBox("checkProvince");
  104.     if (checkProvinceArr.length == 0) {
  105.         alert("请勾选省份");
  106.         return;
  107.     }
  108.     //用json封装参数
  109.     var productTypeArr = new Array();
  110.     if (checkProductArr != null) {
  111.         for (var i = 0;i < checkProductArr.length; i++) {
  112.             var hash = $H();
  113.             hash.set("id",checkProductArr[i]);
  114.             productTypeArr[i]= hash.toJSON();
  115.         }
  116.     }
  117.     var jsonProduct = "[" + productTypeArr + "]";
  118.     
  119.     var gradeArr = new Array();
  120.     if (checkGradeArr != null) {
  121.         for (var i = 0;i < checkGradeArr.length; i++) {
  122.             var hash = $H();
  123.             hash.set("id",checkGradeArr[i]);
  124.             gradeArr[i]= hash.toJSON();
  125.         }
  126.     }
  127.     var jsonGrade = "[" + gradeArr + "]";
  128.     
  129.     var provinceArr = new Array();
  130.     if (checkProvinceArr != null) {
  131.         for (var i = 0;i < checkProvinceArr.length; i++) {
  132.             var hash = $H();
  133.             hash.set("id",checkProvinceArr[i]);
  134.             provinceArr[i]= hash.toJSON();
  135.         }
  136.     }
  137.     var jsonProvince = "[" + provinceArr + "]";
  138.     
  139.     var totalJson = new Array();
  140.     //构造JSON字符串
  141.     totalJson[0] ="{/"product/":"+jsonProduct+",/"grade/":"+jsonGrade+",/"province/":"+jsonProvince+"}";
  142.     
  143.     $("parameter").value = totalJson;
  144.     
  145.     if (type == "update") {
  146.         $("type").value = "update";
  147.     } else {
  148.         $("type").value = "publish";
  149.     }
  150.     document.forms[0].submit();
  151. }
  152. var i = <%=size%>;
  153. var maxSize=5;
  154. function MultiSelector(list_target, max)   
  155.     this.list_target = list_target;
  156.     this.count = 0;
  157.     this.id = 0;
  158.     this.oldElement=null;  
  159.     if (max)   
  160.     {   
  161.         this.max = max;  
  162.     }    
  163.     else   
  164.     {     
  165.         this.max = -1;     
  166.     }  
  167.     
  168.     /**  
  169.      * Add a new file input element  
  170.      */  
  171.     this.addElement = function(element)   
  172.     {
  173.       
  174.           if (element.tagName == 'INPUT' && element.type == 'file')   
  175.           {
  176.               this.max = max-i;      
  177.               this.oldElement=element;
  178.               element.name = 'file_' + this.id++;
  179.               element.multi_selector = this;
  180.               element.onchange = function()   
  181.               { 
  182.                   var new_element = document.createElement('input');   
  183.                   new_element.type = 'file';
  184.                   new_element.size = 1;   
  185.                   new_element.className = "addfile";               
  186.                   this.parentNode.insertBefore(new_element, this);                 
  187.                   this.multi_selector.addElement(new_element); 
  188.                   this.multi_selector.addListRow(this); 
  189.                   this.style.position = 'absolute';     
  190.                   this.style.left = '-1000px';    
  191.             };   
  192.                 
  193.             if (this.max != -1 && this.count >= this.max)   
  194.             {                             
  195.                 element.disabled = true;                
  196.             };   
  197.            
  198.             this.count++;     
  199.             
  200.             this.current_element = element;
  201.         }     
  202.         else     
  203.         {  
  204.             alert('Error: not a file input element');     
  205.         };     
  206.     };   
  207.   
  208.     /**   
  209.      * Add a new row to the list of files   
  210.      */    
  211.     this.addListRow = function(element)     
  212.     {
  213.         if(this.list_target.innerText.indexOf(element.value) !=-1)
  214.         {
  215.            alert("列表中已包含此文件,无须重复提交!");
  216.            this.count--;
  217.            this.oldElement.disabled = false;
  218.            thisthis.current_element = this.oldElement;       
  219.            return;
  220.         }    
  221.         var new_col = document.createElement('div');        
  222.         new_col.align="left";      
  223.         var new_row_button = document.createElement('input');   
  224.         new_row_button.type = 'button'
  225.         new_row_button.value = '删 除';
  226.         new_row_button.className="tbutton";
  227.         new_col.element = element; 
  228.         new_row_button.onclick = function()   
  229.         {     
  230.          
  231.             this.parentNode.element.parentNode.removeChild(this.parentNode.element);   
  232.            
  233.             this.parentNode.parentNode.removeChild(this.parentNode);   
  234.           
  235.             this.parentNode.element.multi_selector.count--;
  236.             this.parentNode.element.multi_selector.current_element.disabled = false;
  237.             if($('files_list').innerText==''){
  238.                $('fileStr').style.display="none";
  239.             }  
  240.             return false;    
  241.         }; 
  242.          
  243.         new_col.innerHTML = element.value + " ";        
  244.         new_col.appendChild(new_row_button);     
  245.         
  246.         this.list_target.appendChild(new_col);
  247.         
  248.         if($('files_list').innerText!=''){
  249.            $('fileStr').style.display="block";
  250.         }    
  251.     };     
  252. }
  253. function del(attch)
  254. {   
  255.    i--;  
  256.    var att = $F('attachment');
  257.    if(att.indexOf(attch) != -1)
  258.    {    
  259.       attatt = att.replace(attch+";","");    
  260.       $('attachment').value=att;     
  261.       $(attch).style.display="none";
  262.       if(att=="" && $('files_list').innerText=='')
  263.       {
  264.         $('fileStr').style.display="none";
  265.       }
  266.    }
  267. }
  268. function openAttach(name){  
  269.   $('subAttachment').value = name;
  270.   $('mainForm').submit();
  271. }
  272. function showMe()
  273.     var j ='<%=size%>';
  274.     if(j !='null' && j !='0')
  275.     {
  276.         $('fileStr').style.display="block"
  277.     }
  278.     var message = '<%=message%>'
  279.            
  280.     if(message =="exceedThan5M")
  281.     {
  282.         alert("您上传的单个文件大小超过5M,请重新选择附件!");
  283.         return;
  284.     }
  285.     if(message=="fileExist")
  286.     {
  287.         alert("您上传的文件已在服务器上存在,请更改文件名后再上传!");
  288.         return;
  289.     }
  290.     if(message=="pathError")
  291.     {
  292.         alert("您上传的文件名或路径不正确,请重新上传!");
  293.         return;
  294.     }
  295. }
  296. function doBack()
  297. {
  298.    location.href="notice.do?method=listSingle¤tPage="+<%=currentpage%>;  
  299. }
  300. </script>
  301. </head>
  302. <body onload='showMe()'>
  303. <!-- Part I: page title -->
  304. <table width="100%" height="32">
  305.     <tr>
  306.         <td class="page_title">公告管理 >>修改公告</td>
  307.     </tr>
  308. </table>
  309. <br />
  310. <!-- Part II: search bar -->
  311. <html:form action="/notice.do" enctype="multipart/form-data">
  312.     <html:hidden property="method" value="doUpdate" />
  313.     <html:hidden property="id" />
  314.     <html:hidden property="type" />
  315.     <html:hidden property="isPublished" />
  316.     <html:hidden property="attachment" />
  317.     <html:hidden property="parameter" />
  318.     <input type="hidden" name="num" value="0">
  319.     <table width="78%" align=center class="tablecss" cellpadding="0"
  320.         cellspacing="1">
  321.         <tbody class="tbodycss">
  322.             <tr>
  323.                 <td width="10%">标题:</td>
  324.                 <td align="left"><html:text property="title" size="60"
  325.                     styleId="title" styleClass="textcss"></html:text><font
  326.                     color="#FF0000">*</font></td>
  327.                 <td width="30%"><a href="javascript:void(1==1);"
  328.                     class="addfile" style="cursor: default;"><input
  329.                     id="my_file_element" class="addfile" type="file" name="file_1"
  330.                     size="1" title="点击选择附件"> </a> <font color="#FF0000">(附件单个文件大小不能超过5M)</font></td>
  331.             </tr>
  332.             <tr id="fileStr" style="display:none">
  333.                 <td>附件列表:</td>
  334.                 <td colspan="2"><logic:notEmpty name="attachmentList">
  335.                     <logic:iterate name="attachmentList" id="attachments">
  336.                         <div align="left"
  337.                             id="<bean:write name="attachments" property="label"/>"> 
  338.                         <a
  339.                             onclick="openAttach('<bean:write name="attachments" property="label"/>');"
  340.                             style="cursor:hand"> <u><bean:write name="attachments"
  341.                             property="label" /></u> </a> <input type="button" value="删 除"
  342.                             onclick="del('<bean:write name="attachments" property="label"/>')"
  343.                             class="tbutton" /> <br />
  344.                         </div>
  345.                     </logic:iterate>
  346.                 </logic:notEmpty>
  347.                 <div id="files_list"></div>
  348.                 </td>
  349.             </tr>
  350.             <tr>
  351.                 <td colspan=3 align="center">公 告 内 容</td>
  352.             </tr>
  353.             <tr>
  354.                 <td colspan=3><html:textarea property="content" cols="100"
  355.                     rows="20" /></td>
  356.             </tr>
  357.         </tbody>
  358.     </table>
  359.     <br />
  360.     <table width="78%" align=center class="tablecss" cellpadding="0"
  361.         cellspacing="1">
  362.         <tr>
  363.             <td colspan="3" class="tdBagcolor_td_header_unSetFont"><font
  364.                 color="#FF0000"></font>选择发布的产品类别,分销商级别和发布的区域</td>
  365.         </tr>
  366.         <thead class="theadcss">
  367.             <tr>
  368.                 <td width="31%">产品类别</td>
  369.                 <td width="31%">分销商级别</td>
  370.                 <td width="38%">发布区域</td>
  371.             </tr>
  372.         </thead>
  373.         <tbody class="tbodycss">
  374.             <tr>
  375.                 <td align="left"><input type="checkBox" id="allGrade"
  376.                     onclick="checkAll(this,'checkProductType')" />全选</td>
  377.                 <td align="left"><input type="checkBox" id="allGrade"
  378.                     onclick="checkAll(this,'checkDistributeGrade')" />全选</td>
  379.                 <td align="left"><input type="checkBox" id="allProvince"
  380.                     onclick="checkAll(this,'checkProvince')" />全选</td>
  381.             </tr>
  382.             <tr>
  383.                 <td align="left" valign="top"><logic:iterate
  384.                     name="listProductType" id="productType">
  385.                     <html:multibox property="checkProductType">
  386.                         <bean:write name="productType" property="id" />
  387.                     </html:multibox>
  388.                     <bean:write name="productType" property="name" />
  389.                     <br>
  390.                 </logic:iterate></td>
  391.                 <td align="left" valign="top"><logic:iterate
  392.                     name="listDistributeGrade" id="distributeGrade">
  393.                     <html:multibox property="checkDistributeGrade">
  394.                         <bean:write name="distributeGrade" property="id" />
  395.                     </html:multibox>
  396.                     <bean:write name="distributeGrade" property="name" />
  397.                     <br>
  398.                 </logic:iterate></td>
  399.                 <td align="left"><logic:iterate name="listProvince"
  400.                     id="province">
  401.                     <html:multibox property="checkProvince">
  402.                         <bean:write name="province" property="id" />
  403.                     </html:multibox>
  404.                     <bean:write name="province" property="name" />
  405.                 </logic:iterate></td>
  406.             </tr>
  407.             <tr align="left">
  408.                 <td colspan="3"><font color="#0000FF">注意:</font><font
  409.                     color="#FF0000"></font><font color="#0000FF">为必填项</font></td>
  410.             </tr>
  411.         </tbody>
  412.     </table>
  413.     <div align="center"><br />
  414.     <span class="search_button"> <input name="Submit" type="button"
  415.         class="tbutton" value="保 存" onClick="doUpdate('update')" /> <input
  416.         name="Submit" type="button" class="tbutton" value="发 布"
  417.         onclick="doUpdate('publish')" /> <input name="Submit2" type="button"
  418.         class="tbutton" onClick="doBack();" value="返 回" /> </span></div>
  419.     <div align="center"><br />
  420.     </div>
  421. </html:form>
  422. <html:form action="notice.do" method="post" styleId="mainForm">
  423.     <html:hidden property="method" value="downLoad" />
  424.     <html:hidden property="subAttachment" />
  425. </html:form>
  426. <script>     
  427. var multi_selector = new MultiSelector(document.getElementById('files_list'),maxSize);    
  428. multi_selector.addElement(document.getElementById('my_file_element'));    
  429. </script>
  430. </body>
  431. </html>

 

 

 

 add.jsp

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2.     pageEncoding="UTF-8"%>
  3. <%@ taglib uri="/WEB-INF/taglib/struts-bean.tld" prefix="bean"%>
  4. <%@ taglib uri="/WEB-INF/taglib/struts-html.tld" prefix="html"%>
  5. <%@ taglib uri="/WEB-INF/taglib/struts-logic.tld" prefix="logic"%>
  6. <%
  7.     String path = request.getContextPath();
  8.     String basePath = request.getScheme() + "://"
  9.             + request.getServerName() + ":" + request.getServerPort()
  10.             + path;
  11.     String message = (String) request.getAttribute("msg");
  12. %>
  13. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  14. <html>
  15. <head>
  16. <title>新增公告</title>
  17. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  18. <meta http-equiv="pragma" content="no-cache" />
  19. <link href="<%=basePath%>/css/common.css" rel="stylesheet"
  20.     type="text/css" />
  21. <script src="<%=basePath%>/js/prototype.js"></script>
  22. <script src="<%=basePath%>/js/common.js"></script>
  23. <script src="<%=basePath%>/js/WebCalendar.js"></script>
  24. <script src="../js/credit/credit.js"></script>
  25. <script src="../js/AjaxBean.js"></script>
  26. <style>     
  27. a.addfile {     
  28. background-image:url(../image/all_toolbar.gif);     
  29. color: #375771;
  30. font-weight: bold;
  31. text-align: center;
  32. font-size: 12px;
  33. display:block;     
  34. float:left;     
  35. height:28px;     
  36. margin-top:-1px;    
  37. position:relative;    
  38. text-decoration:none;     
  39. top:0pt;     
  40. width:38px;     
  41. }    
  42. input.addfile {   
  43. /*left:-18px;*/    
  44. }     
  45. input.addfile {     
  46. cursor:pointer !important;     
  47. height:28px;     
  48. left:-10px;     
  49. filter:alpha(opacity=0);     
  50. position:absolute;     
  51. top:2px;     
  52. width:1px;
  53.   
  54. }  
  55. </style>
  56. <script type="text/javascript">
  57. function doAdd(type) {
  58.     //获取标题
  59.     var title = $F("title");
  60.     var length = getStringLength(title);
  61.     if (length == 0) {
  62.         alert("标题不能为空");
  63.         $("title").focus();
  64.         return;
  65.     }
  66.     if (length > 90) {
  67.         alert("标题只能输入90个字符(30个汉字),当前长度为:" + length);
  68.         $("title").focus();
  69.         return;
  70.     }
  71.     //获取内容
  72.     if(!check('content','公告内容')){$('content').focus();return;}
  73.     if(get('content') != "")
  74.     {
  75.        var length = getStringLength($F('content'));
  76.        if (length > 1500) {
  77.             alert("公告内容最多只能输入1500个字符(500个汉字)");
  78.             $('content').focus();
  79.             return;
  80.        }
  81.     }  
  82.     
  83.     
  84.     //获取选取的产品ID
  85.     var checkProductArr = checkedCheckBox("checkProductType");
  86.     if (checkProductArr.length == 0) {
  87.         alert("请勾选产品类别");
  88.         return;
  89.     }
  90.     //获取选取的级别ID
  91.     var checkGradeArr = checkedCheckBox("checkDistributeGrade");
  92.     if (checkGradeArr.length == 0) {
  93.         alert("请勾选分销商级别");
  94.         return;
  95.     }
  96.     //获取选取的省份ID
  97.     var checkProvinceArr = checkedCheckBox("checkProvince");
  98.     if (checkProvinceArr.length == 0) {
  99.         alert("请勾选省份");
  100.         return;
  101.     }
  102.     //用json封装参数
  103.     var productTypeArr = new Array();
  104.     if (checkProductArr != null) {
  105.         for (var i = 0;i < checkProductArr.length; i++) {
  106.             var hash = $H();
  107.             hash.set("id",checkProductArr[i]);
  108.             productTypeArr[i]= hash.toJSON();
  109.         }
  110.     }
  111.     var jsonProduct = "[" + productTypeArr + "]";
  112.     
  113.     var gradeArr = new Array();
  114.     if (checkGradeArr != null) {
  115.         for (var i = 0;i < checkGradeArr.length; i++) {
  116.             var hash = $H();
  117.             hash.set("id",checkGradeArr[i]);
  118.             gradeArr[i]= hash.toJSON();
  119.         }
  120.     }
  121.     var jsonGrade = "[" + gradeArr + "]";
  122.     
  123.     var provinceArr = new Array();
  124.     if (checkProvinceArr != null) {
  125.         for (var i = 0;i < checkProvinceArr.length; i++) {
  126.             var hash = $H();
  127.             hash.set("id",checkProvinceArr[i]);
  128.             provinceArr[i]= hash.toJSON();
  129.         }
  130.     }
  131.     var jsonProvince = "[" + provinceArr + "]";
  132.     
  133.     var totalJson = new Array();
  134.     //var totalHash = new $H();
  135.     //totalHash.set("product",jsonProduct);
  136.     //totalHash.set("grade",jsonGrade);
  137.     //totalHash.set("province",jsonProvince);
  138.     //totalJson[0] = totalHash.toJSON();
  139.     //构造JSON字符串
  140.     totalJson[0] ="{/"product/":"+jsonProduct+",/"grade/":"+jsonGrade+",/"province/":"+jsonProvince+"}";
  141.     
  142.     $("parameter").value = totalJson;
  143.     
  144.     if (type == "add") {
  145.         $("type").value = "add";
  146.     } else {
  147.         $("type").value = "publish";
  148.     }
  149.     document.forms[0].submit();
  150. }
  151. function showMessage()
  152. {
  153.     var message = '<%=message%>';
  154.     if(message !="null" && message !='')
  155.     {       
  156.        if(message =="exceedThan5M")
  157.        {
  158.            alert("您上传的单个文件大小超过5M,请重新选择附件!");
  159.            return;
  160.        }
  161.        if(message=="fileExist")
  162.        {
  163.           alert("您上传的文件已在服务器上存在,请更改文件名后再上传!");
  164.           return;
  165.        }
  166.        if(message=="pathError")
  167.        {
  168.            alert("您上传的文件名或路径不正确,请重新上传!");
  169.            return;
  170.        }
  171.     }
  172.    
  173. }
  174. function MultiSelector(list_target, max)   
  175.     this.list_target = list_target;
  176.     this.count = 0;
  177.     this.id = 0;
  178.     this.oldElement=null;
  179.     if (max)   
  180.     {   
  181.         this.max = max;  
  182.     }    
  183.     else   
  184.     {     
  185.         this.max = -1;     
  186.     }  
  187.     
  188.     /**  
  189.      * Add a new file input element  
  190.      */  
  191.     this.addElement = function(element)   
  192.     {
  193.       
  194.           if (element.tagName == 'INPUT' && element.type == 'file')   
  195.           {
  196.               this.oldElement=element;
  197.               element.name = 'file_' + this.id++;
  198.               element.multi_selector = this;
  199.               element.onchange = function()   
  200.               { 
  201.                   var new_element = document.createElement('input');   
  202.                   new_element.type = 'file';   
  203.                   new_element.size = 1;   
  204.                   new_element.className = "addfile";
  205.                   this.parentNode.insertBefore(new_element, this);                  
  206.                   this.multi_selector.addElement(new_element); 
  207.                   this.multi_selector.addListRow(this); 
  208.                   this.style.position = 'absolute';
  209.                   this.style.left = '-1000px';
  210.                      
  211.              };
  212.             
  213.             if (this.max != -1 && this.count >= this.max)   
  214.             {   
  215.                  element.disabled = true;                
  216.             }          
  217.             
  218.             this.count++;
  219.            
  220.             this.current_element = element;
  221.             
  222.         }     
  223.         else     
  224.         {  
  225.             alert('Error: not a file input element');     
  226.         };     
  227.     };   
  228.   
  229.     /**   
  230.      * Add a new row to the list of files   
  231.      */    
  232.     this.addListRow = function(element)     
  233.     {     
  234.         
  235.         if(this.list_target.innerText.indexOf(element.value) !=-1)
  236.         {
  237.            alert("列表中已包含此文件,无须重复提交!");
  238.            this.count--; 
  239.            this.oldElement.disabled = false;
  240.            thisthis.current_element = this.oldElement;
  241.            return;
  242.         }    
  243.         var new_col = document.createElement('div');        
  244.         new_col.align="left";      
  245.         var new_row_button = document.createElement('input');   
  246.         new_row_button.type = 'button'
  247.         new_row_button.value = '删除';
  248.         new_row_button.className="tbutton";
  249.         new_col.element = element; 
  250.         new_row_button.onclick = function()   
  251.         {     
  252.          
  253.             this.parentNode.element.parentNode.removeChild(this.parentNode.element);   
  254.            
  255.             this.parentNode.parentNode.removeChild(this.parentNode);   
  256.           
  257.             this.parentNode.element.multi_selector.count--;
  258.             this.parentNode.element.multi_selector.current_element.disabled = false;
  259.             if($('files_list').innerText==''){
  260.                $('fileStr').style.display="none";
  261.             }  
  262.             return false;    
  263.         };       
  264.         new_col.innerHTML = element.value + " ";
  265.         new_col.appendChild(new_row_button);     
  266.         
  267.         this.list_target.appendChild(new_col);
  268.         
  269.         if($('files_list').innerText!=''){
  270.            $('fileStr').style.display="block";
  271.         }    
  272.     };     
  273. }
  274. </script>
  275. </head>
  276. <body onload="showMessage();">
  277. <!-- Part I: page title -->
  278. <table width="100%" height="32">
  279.     <tr>
  280.         <td class="page_title">公告管理 >> 新建公告</td>
  281.     </tr>
  282. </table>
  283. <br />
  284. <!-- Part II: search bar -->
  285. <html:form action="/notice.do" enctype="multipart/form-data">
  286.     <html:hidden property="method" value="doAdd" />
  287.     <html:hidden property="parameter" />
  288.     <html:hidden property="type" />
  289.     <input type="hidden" name="num" value="0">
  290.     <table width="78%" align=center class="tablecss" cellpadding="0"
  291.         cellspacing="1">
  292.         <tbody class="tbodycss">
  293.             <tr>
  294.                 <td width="59">标题:</td>
  295.                 <td align="left"><html:text property="title" size="60"
  296.                     styleId="title" styleClass="textcss"></html:text><font
  297.                     color="#FF0000">*</font></td>
  298.                 <td><a href="javascript:void(1==1);" class="addfile"
  299.                     style="cursor: default;"><input id="my_file_element"
  300.                     class="addfile" type="file" name="file_1" size="1" title="点击选择附件">
  301.                 </a> <font color="#FF0000">(附件单个文件大小不能超过5兆)</font></td>
  302.             </tr>
  303.             <tr id="fileStr" style="display:none">
  304.                 <td>附件列表:</td>
  305.                 <td colspan="2">
  306.                 <div id="files_list"></div>
  307.                 </td>
  308.             </tr>
  309.             <tr>
  310.                 <td colspan=3 align="center">公 告 内 容</td>
  311.             </tr>
  312.             <tr>
  313.                 <td colspan=3><html:textarea property="content" cols="100"
  314.                     rows="20" /></td>
  315.             </tr>
  316.         </tbody>
  317.     </table>
  318.     <br />
  319.     <table width="78%" align=center class="tablecss" cellpadding="0"
  320.         cellspacing="1">
  321.         <tr>
  322.             <td colspan="3" class="tdBagcolor_td_header_unSetFont"><font
  323.                 color="#FF0000"></font>选择发布的产品类别,分销商级别和发布的区域</td>
  324.         </tr>
  325.         <thead class="theadcss">
  326.             <tr>
  327.                 <td width="31%">产品类别</td>
  328.                 <td width="27%">分销商级别</td>
  329.                 <td width="42%">发布区域</td>
  330.             </tr>
  331.         </thead>
  332.         <tbody class="tbodycss">
  333.             <tr>
  334.                 <td align="left" valign="top"><logic:iterate
  335.                     name="listProductType" id="productType">
  336.                     <input type="checkBox" id="checkProductType"
  337.                         value="<bean:write name='productType' property='id' />" />
  338.                     <bean:write name="productType" property="name" />
  339.                     <br>
  340.                 </logic:iterate></td>
  341.                 <td align="left" valign="top"><logic:iterate
  342.                     name="listDistributeGrade" id="distributeGrade">
  343.                     <input type="checkBox" id="checkDistributeGrade"
  344.                         value="<bean:write name='distributeGrade' property='id' />" />
  345.                     <bean:write name="distributeGrade" property="name" />
  346.                     <br>
  347.                 </logic:iterate></td>
  348.                 <td align="left"><logic:iterate name="listProvince"
  349.                     id="province">
  350.                     <input type="checkBox" id="checkProvince"
  351.                         value="<bean:write name='province' property='id' />" />
  352.                     <bean:write name="province" property="name" />
  353.                 </logic:iterate></td>
  354.             </tr>
  355.             <tr align="left">
  356.                 <td colspan="3"><font color="#0000FF">注意:</font><font
  357.                     color="#FF0000"></font><font color="#0000FF">为必填项</font></td>
  358.             </tr>
  359.         </tbody>
  360.     </table>
  361.     <div align="center"><br />
  362.     <span class="search_button"> <input name="Submit" type="button"
  363.         class="tbutton" value="保 存" onClick="doAdd('add')" /> <input
  364.         name="Submit" type="button" class="tbutton" value="发 布"
  365.         onclick="doAdd('publish')" /> <input name="Submit2" type="button"
  366.         class="tbutton" onClick="history.back();" value="返 回" /> </span></div>
  367.     <div align="center"><br />
  368.     </div>
  369. </html:form>
  370. <script>     
  371. var multi_selector = new MultiSelector(document.getElementById('files_list'), 5);    
  372. multi_selector.addElement(document.getElementById('my_file_element'));    
  373. </script>
  374. </body>
  375. </html>

 

 

Action

 

  1. /**
  2.      * 描述:添加公告(转发)
  3.      * 
  4.      * @return
  5.      */
  6.     public ActionForward prepareAdd(ActionMapping mapping, ActionForm form,
  7.             HttpServletRequest request, HttpServletResponse response) {
  8.         // 保存令牌
  9.         this.saveToken(request);
  10.         List listProductType = noticeBo.listProductType();
  11.         List listDistributorGrade = noticeBo.listDistributeGrade();
  12.         List listProvince = noticeBo.listProvince();
  13.         // request.setAttribute(MSG, "");
  14.         request.setAttribute(LISTPRODUCTTYPE, listProductType);
  15.         request.setAttribute(LISTDISTRIBUTEGRADE, listDistributorGrade);
  16.         request.setAttribute(LISTPROVINCE, listProvince);
  17.         return mapping.findForward(ADD);
  18.     }
  19.     /**
  20.      * 描述:添加公告
  21.      * 
  22.      * @return
  23.      */
  24.     public ActionForward doAdd(ActionMapping mapping, ActionForm form,
  25.             HttpServletRequest request, HttpServletResponse response) {
  26.         if (isTokenValid(request)) {
  27.             Notice notice = new Notice();
  28.             NoticeForm searchForm = (NoticeForm) form;
  29.             JSONObject jsonObject = JSONObject.fromObject(searchForm
  30.                     .getParameter());
  31.             JSONArray jsonArraytmp1 = (JSONArray) jsonObject.get("product");
  32.             List listProduct = new ArrayList();
  33.             for (int i = 0, n = jsonArraytmp1.size(); i < n; i++) {
  34.                 JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp1.get(i);
  35.                 listProduct.add(jsonObjecttmp1.get("id"));
  36.             }
  37.             JSONArray jsonArraytmp2 = (JSONArray) jsonObject.get("grade");
  38.             List listGrade = new ArrayList();
  39.             for (int i = 0, n = jsonArraytmp2.size(); i < n; i++) {
  40.                 JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp2.get(i);
  41.                 listGrade.add(jsonObjecttmp1.get("id"));
  42.             }
  43.             JSONArray jsonArraytmp3 = (JSONArray) jsonObject.get("province");
  44.             List listProvince = new ArrayList();
  45.             for (int i = 0, n = jsonArraytmp3.size(); i < n; i++) {
  46.                 JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp3.get(i);
  47.                 listProvince.add(jsonObjecttmp1.get("id"));
  48.             }
  49.             String dir = servlet.getServletContext().getRealPath(
  50.                     "system/notice/upload");
  51.             Hashtable files = searchForm.getMultipartRequestHandler()
  52.                     .getFileElements();
  53.             StringBuffer fileName = new StringBuffer("");
  54.             for (Enumeration e = files.keys(); e.hasMoreElements();) {
  55.                 String key = (String) e.nextElement();
  56.                 FormFile formFile = (FormFile) files.get(key);
  57.                 if (formFile.getFileSize() > 0) {
  58.                     if (formFile.getFileSize() / 1024 / 1024 > 5) {
  59.                         // 上传文件大于5M
  60.                         request.setAttribute(MSG, EXCEEDTHAN5M);
  61.                         return prepareAdd(mapping, form, request, response);
  62.                     }
  63.                     // 先判断服务器上有没有同名文件
  64.                     File file = new File(dir + "//"
  65.                             + formFile.getFileName().trim());
  66.                     fileName.append(formFile.getFileName().trim()).append(";");
  67.                     if (file.exists()) {
  68.                         // 存在同名文件,提示用户
  69.                         request.setAttribute(MSG, FILEEXIST);
  70.                         return prepareAdd(mapping, form, request, response);
  71.                     }
  72.                     // 上传文件
  73.                     InputStream in = null;
  74.                     OutputStream out = null;
  75.                     try {
  76.                         in = formFile.getInputStream();
  77.                         File uploadFile = new File(dir);
  78.                         if (!uploadFile.exists() || uploadFile == null) {
  79.                             uploadFile.mkdir();
  80.                         }
  81.                         String path = uploadFile.getPath() + "/"
  82.                                 + formFile.getFileName();
  83.                         out = new FileOutputStream(path);
  84.                         int byteRead = 0;
  85.                         byte[] buffer = new byte[8192];
  86.                         while ((byteRead = in.read(buffer, 08192)) != -1) {
  87.                             out.write(buffer, 0, byteRead);
  88.                         }
  89.                     } catch (Exception ex) {
  90.                         ex.printStackTrace();
  91.                     } finally {
  92.                         try {
  93.                             if (in != null) {
  94.                                 in.close();
  95.                             }
  96.                             if (out != null) {
  97.                                 out.close();
  98.                             }
  99.                             formFile.destroy();
  100.                         } catch (Exception ee) {
  101.                             ee.printStackTrace();
  102.                         }
  103.                     }
  104.                 } else if (formFile.getFileSize() == 0
  105.                         && !CommonUtil.isEmpty(formFile.getFileName())) {
  106.                     // 本地上传路径不正确
  107.                     // 记录错误信息
  108.                     request.setAttribute(MSG, PATHERROR);
  109.                     return prepareAdd(mapping, form, request, response);
  110.                 }
  111.             }
  112.             UserBean userBean = (UserBean) request.getSession().getAttribute(
  113.                     USERBEAN);
  114.             Account account = new Account();
  115.             account.setId(userBean.getAccount_id());
  116.             notice.setAttachment(fileName.toString());
  117.             notice.setAccount(account);
  118.             notice.setContent(searchForm.getContent());
  119.             notice.setTitle(searchForm.getTitle());
  120.             if (CommonUtil.isEmpty(searchForm.getIsDelete())) {
  121.                 searchForm.setIsDelete(Constants.ENABLE_N);
  122.             }
  123.             notice.setIsDelete(searchForm.getIsDelete());
  124.             notice.setDistributorGradeList(listGrade);
  125.             notice.setProductTypeList(listProduct);
  126.             notice.setProvinceList(listProvince);
  127.             if (searchForm.getType().equals(ADD)) {
  128.                 notice.setIsPublished(Constants.ENABLE_N);
  129.             } else {
  130.                 notice.setIsPublished(Constants.ENABLE_Y);
  131.                 notice.setCreateDate(new Date(System.currentTimeMillis()));
  132.             }
  133.             if (this.isTokenValid(request)) {
  134.                 noticeBo.AddNotice(notice, userBean);
  135.                 this.saveToken(request);
  136.             }
  137.             // 操作成功后重置令牌
  138.             this.saveToken(request);
  139.             return mapping.findForward(SINGLELIST);
  140.         } else {
  141.             // 重新生成令牌
  142.             saveToken(request);
  143.             return prepareAdd(mapping, form, request, response);
  144.         }
  145.     }
  146.     /**
  147.      * 描述:下载附件操作
  148.      * 
  149.      * @param mapping
  150.      * @param form
  151.      * @param request
  152.      * @param response
  153.      * @return
  154.      * @throws UnsupportedEncodingException
  155.      * @throws Exception
  156.      */
  157.     public ActionForward downLoad(ActionMapping mapping, ActionForm form,
  158.             HttpServletRequest request, HttpServletResponse response)
  159.             throws UnsupportedEncodingException {
  160.         NoticeForm noticeForm = (NoticeForm) form;
  161.         String fileName = noticeForm.getSubAttachment();
  162.         String dir = servlet.getServletContext().getRealPath(
  163.                 "system/notice/upload");
  164.         //
  165.         dir = dir + "//" + fileName;
  166.         File f = new File(dir);
  167.         byte[] buf = new byte[1024];
  168.         int len = 0;
  169.         response.reset();
  170.         response.setContentType("application/x-msdownload;charset=ISO-8859-1");
  171.         response.setHeader("Content-Disposition""attachment; filename="
  172.                 + CommonUtil.Utf8URLencode(fileName));
  173.         OutputStream out;
  174.         try {
  175.             BufferedInputStream br = new BufferedInputStream(
  176.                     new FileInputStream(f));
  177.             out = response.getOutputStream();
  178.             while ((len = br.read(buf)) > 0) {
  179.                 out.write(buf, 0, len);
  180.                 out.flush();
  181.             }
  182.             br.close();
  183.             out.close();
  184.         } catch (IOException e) {
  185.             e.printStackTrace();
  186.         }
  187.         return null;
  188.     }
  189.     /**
  190.      * 描述:修改公告(转发)
  191.      * 
  192.      * @return
  193.      */
  194.     public ActionForward prepareUpdate(ActionMapping mapping, ActionForm form,
  195.             HttpServletRequest request, HttpServletResponse response) {
  196.         String id = request.getParameter("id");
  197.         Long noticeId = null;
  198.         try {
  199.             noticeId = Long.valueOf(id);
  200.         } catch (Exception e) {
  201.             e.printStackTrace();
  202.         }
  203.         Notice notice = noticeBo.getNotice(noticeId);
  204.         NoticeForm noticeForm = (NoticeForm) form;
  205.         request.setAttribute(OLDPAGE, new Integer(noticeForm.getCurrentPage()));
  206.         noticeForm.setId(notice.getId());
  207.         noticeForm.setTitle(notice.getTitle());
  208.         noticeForm.setContent(notice.getContent());
  209.         noticeForm.setIsPublished(notice.getIsPublished());
  210.         noticeForm.setIsDelete(notice.getIsDelete());
  211.         noticeForm.setAttachment(notice.getAttachment());
  212.         List distributorGradeList = notice.getDistributorGradeList();
  213.         List productTypeList = notice.getProductTypeList();
  214.         List provinceList = notice.getProvinceList();
  215.         if (distributorGradeList != null) {
  216.             int distributorSize = distributorGradeList.size();
  217.             String[] distributor = new String[distributorSize];
  218.             for (int si = 0; si < distributorSize; si++) {
  219.                 NoticeDistributorGrade distributorGrade = (NoticeDistributorGrade) distributorGradeList
  220.                         .get(si);
  221.                 distributor[si] = String.valueOf(distributorGrade
  222.                         .getDistributorGrade().getId());
  223.             }
  224.             noticeForm.setCheckDistributeGrade(distributor);
  225.         }
  226.         if (productTypeList != null) {
  227.             int productTypeSize = productTypeList.size();
  228.             String[] checkProductType = new String[productTypeSize];
  229.             for (int si = 0; si < productTypeSize; si++) {
  230.                 NoticePT productType = (NoticePT) productTypeList.get(si);
  231.                 checkProductType[si] = String.valueOf(productType
  232.                         .getProductType().getId());
  233.             }
  234.             noticeForm.setCheckProductType(checkProductType);
  235.         }
  236.         if (provinceList != null) {
  237.             int provinceListSize = provinceList.size();
  238.             String[] checkProvince = new String[provinceListSize];
  239.             for (int si = 0; si < provinceListSize; si++) {
  240.                 NoticeProvince province = (NoticeProvince) provinceList.get(si);
  241.                 checkProvince[si] = String.valueOf(province.getProvince()
  242.                         .getId());
  243.             }
  244.             noticeForm.setCheckProvince(checkProvince);
  245.         }
  246.         List list = new ArrayList();
  247.         if (null != notice.getAttachment()) {
  248.             String[] str = notice.getAttachment().split(";");
  249.             for (int i = 0; i < str.length; i++) {
  250.                 ConstBean cb = new ConstBean();
  251.                 cb.setLabel(str[i]);
  252.                 list.add(cb);
  253.             }
  254.         }
  255.         request.setAttribute(ATTACHMENTLIST, list);
  256.         List listProductType = noticeBo.listProductType();
  257.         List listDistributorGrade = noticeBo.listDistributeGrade();
  258.         List listProvince = noticeBo.listProvince();
  259.         // request.setAttribute(MSG, "");
  260.         request.setAttribute("formFile", notice.getAttachment() == null ? ""
  261.                 : notice.getAttachment());
  262.         request.setAttribute(LISTPRODUCTTYPE, listProductType);
  263.         request.setAttribute(LISTDISTRIBUTEGRADE, listDistributorGrade);
  264.         request.setAttribute(LISTPROVINCE, listProvince);
  265.         // 设置令牌
  266.         this.saveToken(request);
  267.         return mapping.findForward(UPDATE);
  268.     }
  269.     /**
  270.      * 描述:修改公告
  271.      * 
  272.      * @return
  273.      */
  274.     public ActionForward doUpdate(ActionMapping mapping, ActionForm form,
  275.             HttpServletRequest request, HttpServletResponse response) {
  276.         try {
  277.             if (isTokenValid(request)) {
  278.                 NoticeForm searchForm = (NoticeForm) form;
  279.                 JSONObject jsonObject = JSONObject.fromObject(searchForm
  280.                         .getParameter());
  281.                 JSONArray jsonArraytmp1 = (JSONArray) jsonObject.get("product");
  282.                 List listProduct = new ArrayList();
  283.                 for (int i = 0, n = jsonArraytmp1.size(); i < n; i++) {
  284.                     JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp1
  285.                             .get(i);
  286.                     listProduct.add(jsonObjecttmp1.get("id"));
  287.                 }
  288.                 JSONArray jsonArraytmp2 = (JSONArray) jsonObject.get("grade");
  289.                 List listGrade = new ArrayList();
  290.                 for (int i = 0, n = jsonArraytmp2.size(); i < n; i++) {
  291.                     JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp2
  292.                             .get(i);
  293.                     listGrade.add(jsonObjecttmp1.get("id"));
  294.                 }
  295.                 JSONArray jsonArraytmp3 = (JSONArray) jsonObject
  296.                         .get("province");
  297.                 List listProvince = new ArrayList();
  298.                 for (int i = 0, n = jsonArraytmp3.size(); i < n; i++) {
  299.                     JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp3
  300.                             .get(i);
  301.                     listProvince.add(jsonObjecttmp1.get("id"));
  302.                 }
  303.                 UserBean userBean = (UserBean) request.getSession()
  304.                         .getAttribute(USERBEAN);
  305.                 Notice notice = new Notice();
  306.                 Notice noticeTemp = (Notice) noticeBo.getNoticeById(searchForm
  307.                         .getId());
  308.                 Account account = new Account();
  309.                 account.setId(userBean.getAccount_id());
  310.                 notice.setAccount(account);
  311.                 notice.setId(searchForm.getId());
  312.                 notice.setContent(searchForm.getContent());
  313.                 notice.setTitle(searchForm.getTitle());
  314.                 notice.setModifyDate(new Date(System.currentTimeMillis()));
  315.                 if (CommonUtil.isEmpty(searchForm.getIsDelete())) {
  316.                     searchForm.setIsDelete(Constants.ENABLE_N);
  317.                 }
  318.                 notice.setIsDelete(searchForm.getIsDelete());
  319.                 notice.setDistributorGradeList(listGrade);
  320.                 notice.setProductTypeList(listProduct);
  321.                 notice.setProvinceList(listProvince);
  322.                 if (searchForm.getType().equals(UPDATE)) {
  323.                     notice.setIsPublished(searchForm.getIsPublished());
  324.                     notice.setCreateDate(noticeTemp.getCreateDate());
  325.                 } else {
  326.                     notice.setIsPublished(Constants.ENABLE_Y);
  327.                     notice.setCreateDate(new Date(System.currentTimeMillis()));
  328.                 }
  329.                 String dir = servlet.getServletContext().getRealPath(
  330.                         "system/notice/upload");
  331.                 StringBuffer fileName = new StringBuffer("");
  332.                 // 获取原有附件
  333.                 if (!CommonUtil.isEmpty(searchForm.getAttachment())) {
  334.                     fileName.append(searchForm.getAttachment());
  335.                 }
  336.                 // 如果原来有附件,现在已删除,则删除存放在服务器端的原来的附件
  337.                 if (!CommonUtil.isEmpty(notice.getAttachment())
  338.                         && !notice.getAttachment().equals(
  339.                                 searchForm.getAttachment())) {
  340.                     // 找出被删除的附件
  341.                     String[] att = notice.getAttachment().split(";");
  342.                     String temp = searchForm.getAttachment();
  343.                     for (int i = 0; i < att.length; i++) {
  344.                         // 如果该文件名在传过来的文件名中不存在,则删除
  345.                         if (temp.indexOf(att[i]) == -1) {
  346.                             File file = new File(dir + "//" + att[i]);
  347.                             if (file.exists()) {
  348.                                 // 存在则删除
  349.                                 file.delete();
  350.                             }
  351.                         }
  352.                     }
  353.                 }
  354.                 Hashtable files = searchForm.getMultipartRequestHandler()
  355.                         .getFileElements();
  356.                 for (Enumeration e = files.keys(); e.hasMoreElements();) {
  357.                     String key = (String) e.nextElement();
  358.                     FormFile formFile = (FormFile) files.get(key);
  359.                     if (formFile.getFileSize() > 0) {
  360.                         if (formFile.getFileSize() / 1024 / 1024 > 5) {
  361.                             // 上传文件大于5M
  362.                             request.setAttribute(MSG, EXCEEDTHAN5M);
  363.                             return prepareUpdate(mapping, form, request,
  364.                                     response);
  365.                         }
  366.                         // 先判断服务器上有没有同名文件
  367.                         File file = new File(dir + "//"
  368.                                 + formFile.getFileName().trim());
  369.                         if (file.exists()) {
  370.                             // 存在同名文件,提示用户
  371.                             request.setAttribute(MSG, FILEEXIST);
  372.                             return prepareUpdate(mapping, form, request,
  373.                                     response);
  374.                         }
  375.                         // 判断原来上传的文件中是否有相同的名称,有则提示
  376.                         if (!CommonUtil.isEmpty(notice.getAttachment())) {
  377.                             if (notice.getAttachment().indexOf(
  378.                                     formFile.getFileName().trim()) != -1) {
  379.                                 // 存在同名文件,提示用户
  380.                                 request.setAttribute(MSG, FILEEXIST);
  381.                                 return prepareUpdate(mapping, form, request,
  382.                                         response);
  383.                             }
  384.                         }
  385.                         // 上传文件
  386.                         InputStream in = null;
  387.                         OutputStream out = null;
  388.                         try {
  389.                             in = formFile.getInputStream();
  390.                             File uploadFile = new File(dir);
  391.                             if (!uploadFile.exists() || uploadFile == null) {
  392.                                 uploadFile.mkdir();
  393.                             }
  394.                             String path = uploadFile.getPath() + "/"
  395.                                     + formFile.getFileName();
  396.                             out = new FileOutputStream(path);
  397.                             int byteRead = 0;
  398.                             byte[] buffer = new byte[8192];
  399.                             while ((byteRead = in.read(buffer, 08192)) != -1) {
  400.                                 out.write(buffer, 0, byteRead);
  401.                             }
  402.                             // 保存路径
  403.                             fileName.append(formFile.getFileName().trim())
  404.                                     .append(";");
  405.                         } catch (Exception ex) {
  406.                             ex.printStackTrace();
  407.                         } finally {
  408.                             try {
  409.                                 if (in != null) {
  410.                                     in.close();
  411.                                 }
  412.                                 if (out != null) {
  413.                                     out.close();
  414.                                 }
  415.                                 formFile.destroy();
  416.                             } catch (Exception ee) {
  417.                                 ee.printStackTrace();
  418.                             }
  419.                         }
  420.                     } else if (formFile.getFileSize() == 0
  421.                             && !CommonUtil.isEmpty(formFile.getFileName())) {
  422.                         // 本地上传路径不正确
  423.                         // 记录错误信息
  424.                         request.setAttribute(MSG, PATHERROR);
  425.                         return prepareUpdate(mapping, form, request, response);
  426.                     }
  427.                 }
  428.                 notice.setAttachment(fileName.toString());
  429.                 noticeBo.updateNotice(notice, userBean);
  430.                 // 重置令牌
  431.                 this.saveToken(request);
  432.                 return mapping.findForward(SINGLELIST);
  433.             } else {
  434.                 // 重新生成令牌
  435.                 saveToken(request);
  436.                 return prepareUpdate(mapping, form, request, response);
  437.             }
  438.         } catch (Exception e) {
  439.             e.printStackTrace();
  440.             return null;
  441.         }
  442.     }
  443.     /**
  444.      * 描述:发布公告
  445.      * 
  446.      * @return
  447.      */
  448.     public ActionForward doPublish(ActionMapping mapping, ActionForm form,
  449.             HttpServletRequest request, HttpServletResponse response) {
  450.         String id = request.getParameter("id");
  451.         Long noticeId = null;
  452.         try {
  453.             noticeId = Long.valueOf(id);
  454.         } catch (Exception e) {
  455.         }
  456.         UserBean userBean = (UserBean) request.getSession().getAttribute(
  457.                 USERBEAN);
  458.         noticeBo.promulgate(noticeId, userBean);
  459.         return mapping.findForward(SINGLELIST);
  460.     }
  461.     /**
  462.      * 描述:显示公告
  463.      * 
  464.      * @return
  465.      */
  466.     public ActionForward display(ActionMapping mapping, ActionForm form,
  467.             HttpServletRequest request, HttpServletResponse response) {
  468.         String id = request.getParameter("id");
  469.         Long noticeId = null;
  470.         try {
  471.             noticeId = Long.valueOf(id);
  472.         } catch (Exception e) {
  473.         }
  474.         Notice notice = noticeBo.getNotice(noticeId);
  475.         notice.setContent(notice.getContent().replaceAll("//r//n""<br/>"));
  476.         if (notice == null) {
  477.             notice = new Notice();
  478.         }
  479.         List list = new ArrayList();
  480.         if (null != notice.getAttachment()) {
  481.             String[] str = notice.getAttachment().split(";");
  482.             for (int i = 0; i < str.length; i++) {
  483.                 ConstBean cb = new ConstBean();
  484.                 cb.setLabel(str[i]);
  485.                 list.add(cb);
  486.             }
  487.         }
  488.         request.setAttribute(ATTACHMENTLIST, list);
  489.         String type = request.getParameter("type");
  490.         if (type != null && type.equals(DISTRIBUTOR)) {
  491.             notice.setProvinceList(new ArrayList());
  492.             notice.setDistributorGradeList(new ArrayList());
  493.         }
  494.         request.setAttribute(NOTICE, notice);
  495.         return mapping.findForward(DISPLAY);
  496.     }
  497.     /**
  498.      * 描述:彻底删除公告
  499.      * 
  500.      * @return
  501.      */
  502.     public ActionForward doDeleted(ActionMapping mapping, ActionForm form,
  503.             HttpServletRequest request, HttpServletResponse response) {
  504.         String id = request.getParameter("id");
  505.         Long noticeId = null;
  506.         try {
  507.             noticeId = Long.valueOf(id);
  508.             // 判断公告是否有附件,有则删除
  509.             Notice notice = noticeBo.getNotice(noticeId);
  510.             File file = null;
  511.             if (!CommonUtil.isEmpty(notice.getAttachment())) {
  512.                 String dir = servlet.getServletContext().getRealPath(
  513.                         "system/notice/upload");
  514.                 String[] att = notice.getAttachment().split(";");
  515.                 for (int i = 0; i < att.length; i++) {
  516.                     file = new File(dir + "//" + att[i]);
  517.                     if (file.exists()) {
  518.                         // 存在则删除
  519.                         file.delete();
  520.                     }
  521.                 }
  522.             }
  523.             UserBean userBean = (UserBean) request.getSession().getAttribute(
  524.                     USERBEAN);
  525.             noticeBo.deletedNotice(noticeId, userBean);
  526.         } catch (Exception e) {
  527.             request.setAttribute(MSG, "deleteError");
  528.             e.printStackTrace();
  529.         }
  530.         return mapping.findForward(ALLLIST);
  531.     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值