update.jsp
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8" import="java.util.*"%>
- <%@ taglib uri="/WEB-INF/taglib/struts-bean.tld" prefix="bean"%>
- <%@ taglib uri="/WEB-INF/taglib/struts-html.tld" prefix="html"%>
- <%@ taglib uri="/WEB-INF/taglib/struts-logic.tld" prefix="logic"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path;
- String message = (String) request.getAttribute("msg");
- List list = (List) request.getAttribute("attachmentList");
- int size = 0;
- if (list != null) {
- size = list.size();
- }
- int currentpage = ((Integer) request.getAttribute("oldPage"))
- .intValue();
- %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>修改公告</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta http-equiv="pragma" content="no-cache" />
- <link href="<%=basePath%>/css/common.css" rel="stylesheet"
- type="text/css" />
- <script src="<%=basePath%>/js/prototype.js"></script>
- <script src="<%=basePath%>/js/common.js"></script>
- <script src="<%=basePath%>/js/WebCalendar.js"></script>
- <script src="../js/credit/credit.js"></script>
- <script src="../js/AjaxBean.js"></script>
- <style>
- a.addfile {
- background-image:url(../image/all_toolbar.gif);
- color: #375771;
- font-weight: bold;
- text-align: center;
- font-size: 12px;
- display:block;
- float:left;
- height:28px;
- margin-top:-1px;
- position:relative;
- text-decoration:none;
- top:0pt;
- width:38px;
- }
- input.addfile {
- /*left:-18px;*/
- }
- input.addfile {
- cursor:pointer !important;
- height:28px;
- left:-10px;
- filter:alpha(opacity=0);
- position:absolute;
- top:2px;
- width:1px;
- }
- </style>
- <script type="text/javascript">
- function doUpdate(type) {
- //获取标题
- var title = $F("title");
- var length = getStringLength(title);
- if (length == 0) {
- alert("标题不能为空");
- $("title").focus();
- return;
- }
- if (length > 90) {
- alert("标题只能输入90个字符(30个汉字),当前长度为:" + length);
- $("title").focus();
- return;
- }
- //获取内容
- if(!check('content','公告内容')){ $('content').focus();return;}
- if(get('content') != "")
- {
- var length = getStringLength($F('content'));
- if (length > 1500) {
- alert("公告内容最多只能输入1500个字符(500个汉字)");
- $('content').focus();
- return;
- }
- }
- //获取选取的产品ID
- var checkProductArr = checkedCheckBox("checkProductType");
- if (checkProductArr.length == 0) {
- alert("请勾选产品类别");
- return;
- }
- //获取选取的级别ID
- var checkGradeArr = checkedCheckBox("checkDistributeGrade");
- if (checkGradeArr.length == 0) {
- alert("请勾选分销商级别");
- return;
- }
- //获取选取的省份ID
- var checkProvinceArr = checkedCheckBox("checkProvince");
- if (checkProvinceArr.length == 0) {
- alert("请勾选省份");
- return;
- }
- //用json封装参数
- var productTypeArr = new Array();
- if (checkProductArr != null) {
- for (var i = 0;i < checkProductArr.length; i++) {
- var hash = $H();
- hash.set("id",checkProductArr[i]);
- productTypeArr[i]= hash.toJSON();
- }
- }
- var jsonProduct = "[" + productTypeArr + "]";
- var gradeArr = new Array();
- if (checkGradeArr != null) {
- for (var i = 0;i < checkGradeArr.length; i++) {
- var hash = $H();
- hash.set("id",checkGradeArr[i]);
- gradeArr[i]= hash.toJSON();
- }
- }
- var jsonGrade = "[" + gradeArr + "]";
- var provinceArr = new Array();
- if (checkProvinceArr != null) {
- for (var i = 0;i < checkProvinceArr.length; i++) {
- var hash = $H();
- hash.set("id",checkProvinceArr[i]);
- provinceArr[i]= hash.toJSON();
- }
- }
- var jsonProvince = "[" + provinceArr + "]";
- var totalJson = new Array();
- //构造JSON字符串
- totalJson[0] ="{/"product/":"+jsonProduct+",/"grade/":"+jsonGrade+",/"province/":"+jsonProvince+"}";
- $("parameter").value = totalJson;
- if (type == "update") {
- $("type").value = "update";
- } else {
- $("type").value = "publish";
- }
- document.forms[0].submit();
- }
- var i = <%=size%>;
- var maxSize=5;
- function MultiSelector(list_target, max)
- {
- this.list_target = list_target;
- this.count = 0;
- this.id = 0;
- this.oldElement=null;
- if (max)
- {
- this.max = max;
- }
- else
- {
- this.max = -1;
- }
- /**
- * Add a new file input element
- */
- this.addElement = function(element)
- {
- if (element.tagName == 'INPUT' && element.type == 'file')
- {
- this.max = max-i;
- this.oldElement=element;
- element.name = 'file_' + this.id++;
- element.multi_selector = this;
- element.onchange = function()
- {
- var new_element = document.createElement('input');
- new_element.type = 'file';
- new_element.size = 1;
- new_element.className = "addfile";
- this.parentNode.insertBefore(new_element, this);
- this.multi_selector.addElement(new_element);
- this.multi_selector.addListRow(this);
- this.style.position = 'absolute';
- this.style.left = '-1000px';
- };
- if (this.max != -1 && this.count >= this.max)
- {
- element.disabled = true;
- };
- this.count++;
- this.current_element = element;
- }
- else
- {
- alert('Error: not a file input element');
- };
- };
- /**
- * Add a new row to the list of files
- */
- this.addListRow = function(element)
- {
- if(this.list_target.innerText.indexOf(element.value) !=-1)
- {
- alert("列表中已包含此文件,无须重复提交!");
- this.count--;
- this.oldElement.disabled = false;
- thisthis.current_element = this.oldElement;
- return;
- }
- var new_col = document.createElement('div');
- new_col.align="left";
- var new_row_button = document.createElement('input');
- new_row_button.type = 'button';
- new_row_button.value = '删 除';
- new_row_button.className="tbutton";
- new_col.element = element;
- new_row_button.onclick = function()
- {
- this.parentNode.element.parentNode.removeChild(this.parentNode.element);
- this.parentNode.parentNode.removeChild(this.parentNode);
- this.parentNode.element.multi_selector.count--;
- this.parentNode.element.multi_selector.current_element.disabled = false;
- if($('files_list').innerText==''){
- $('fileStr').style.display="none";
- }
- return false;
- };
- new_col.innerHTML = element.value + " ";
- new_col.appendChild(new_row_button);
- this.list_target.appendChild(new_col);
- if($('files_list').innerText!=''){
- $('fileStr').style.display="block";
- }
- };
- }
- function del(attch)
- {
- i--;
- var att = $F('attachment');
- if(att.indexOf(attch) != -1)
- {
- attatt = att.replace(attch+";","");
- $('attachment').value=att;
- $(attch).style.display="none";
- if(att=="" && $('files_list').innerText=='')
- {
- $('fileStr').style.display="none";
- }
- }
- }
- function openAttach(name){
- $('subAttachment').value = name;
- $('mainForm').submit();
- }
- function showMe()
- {
- var j ='<%=size%>';
- if(j !='null' && j !='0')
- {
- $('fileStr').style.display="block";
- }
- var message = '<%=message%>';
- if(message =="exceedThan5M")
- {
- alert("您上传的单个文件大小超过5M,请重新选择附件!");
- return;
- }
- if(message=="fileExist")
- {
- alert("您上传的文件已在服务器上存在,请更改文件名后再上传!");
- return;
- }
- if(message=="pathError")
- {
- alert("您上传的文件名或路径不正确,请重新上传!");
- return;
- }
- }
- function doBack()
- {
- location.href="notice.do?method=listSingle¤tPage="+<%=currentpage%>;
- }
- </script>
- </head>
- <body onload='showMe()'>
- <!-- Part I: page title -->
- <table width="100%" height="32">
- <tr>
- <td class="page_title">公告管理 >>修改公告</td>
- </tr>
- </table>
- <br />
- <!-- Part II: search bar -->
- <html:form action="/notice.do" enctype="multipart/form-data">
- <html:hidden property="method" value="doUpdate" />
- <html:hidden property="id" />
- <html:hidden property="type" />
- <html:hidden property="isPublished" />
- <html:hidden property="attachment" />
- <html:hidden property="parameter" />
- <input type="hidden" name="num" value="0">
- <table width="78%" align=center class="tablecss" cellpadding="0"
- cellspacing="1">
- <tbody class="tbodycss">
- <tr>
- <td width="10%">标题:</td>
- <td align="left"><html:text property="title" size="60"
- styleId="title" styleClass="textcss"></html:text><font
- color="#FF0000">*</font></td>
- <td width="30%"><a href="javascript:void(1==1);"
- class="addfile" style="cursor: default;"><input
- id="my_file_element" class="addfile" type="file" name="file_1"
- size="1" title="点击选择附件"> </a> <font color="#FF0000">(附件单个文件大小不能超过5M)</font></td>
- </tr>
- <tr id="fileStr" style="display:none">
- <td>附件列表:</td>
- <td colspan="2"><logic:notEmpty name="attachmentList">
- <logic:iterate name="attachmentList" id="attachments">
- <div align="left"
- id="<bean:write name="attachments" property="label"/>">
- <a
- onclick="openAttach('<bean:write name="attachments" property="label"/>');"
- style="cursor:hand"> <u><bean:write name="attachments"
- property="label" /></u> </a> <input type="button" value="删 除"
- onclick="del('<bean:write name="attachments" property="label"/>')"
- class="tbutton" /> <br />
- </div>
- </logic:iterate>
- </logic:notEmpty>
- <div id="files_list"></div>
- </td>
- </tr>
- <tr>
- <td colspan=3 align="center">公 告 内 容</td>
- </tr>
- <tr>
- <td colspan=3><html:textarea property="content" cols="100"
- rows="20" /></td>
- </tr>
- </tbody>
- </table>
- <br />
- <table width="78%" align=center class="tablecss" cellpadding="0"
- cellspacing="1">
- <tr>
- <td colspan="3" class="tdBagcolor_td_header_unSetFont"><font
- color="#FF0000">* </font>选择发布的产品类别,分销商级别和发布的区域</td>
- </tr>
- <thead class="theadcss">
- <tr>
- <td width="31%">产品类别</td>
- <td width="31%">分销商级别</td>
- <td width="38%">发布区域</td>
- </tr>
- </thead>
- <tbody class="tbodycss">
- <tr>
- <td align="left"><input type="checkBox" id="allGrade"
- onclick="checkAll(this,'checkProductType')" />全选</td>
- <td align="left"><input type="checkBox" id="allGrade"
- onclick="checkAll(this,'checkDistributeGrade')" />全选</td>
- <td align="left"><input type="checkBox" id="allProvince"
- onclick="checkAll(this,'checkProvince')" />全选</td>
- </tr>
- <tr>
- <td align="left" valign="top"><logic:iterate
- name="listProductType" id="productType">
- <html:multibox property="checkProductType">
- <bean:write name="productType" property="id" />
- </html:multibox>
- <bean:write name="productType" property="name" />
- <br>
- </logic:iterate></td>
- <td align="left" valign="top"><logic:iterate
- name="listDistributeGrade" id="distributeGrade">
- <html:multibox property="checkDistributeGrade">
- <bean:write name="distributeGrade" property="id" />
- </html:multibox>
- <bean:write name="distributeGrade" property="name" />
- <br>
- </logic:iterate></td>
- <td align="left"><logic:iterate name="listProvince"
- id="province">
- <html:multibox property="checkProvince">
- <bean:write name="province" property="id" />
- </html:multibox>
- <bean:write name="province" property="name" />
- </logic:iterate></td>
- </tr>
- <tr align="left">
- <td colspan="3"><font color="#0000FF">注意:</font><font
- color="#FF0000">* </font><font color="#0000FF">为必填项</font></td>
- </tr>
- </tbody>
- </table>
- <div align="center"><br />
- <span class="search_button"> <input name="Submit" type="button"
- class="tbutton" value="保 存" onClick="doUpdate('update')" /> <input
- name="Submit" type="button" class="tbutton" value="发 布"
- onclick="doUpdate('publish')" /> <input name="Submit2" type="button"
- class="tbutton" onClick="doBack();" value="返 回" /> </span></div>
- <div align="center"><br />
- </div>
- </html:form>
- <html:form action="notice.do" method="post" styleId="mainForm">
- <html:hidden property="method" value="downLoad" />
- <html:hidden property="subAttachment" />
- </html:form>
- <script>
- var multi_selector = new MultiSelector(document.getElementById('files_list'),maxSize);
- multi_selector.addElement(document.getElementById('my_file_element'));
- </script>
- </body>
- </html>
add.jsp
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%@ taglib uri="/WEB-INF/taglib/struts-bean.tld" prefix="bean"%>
- <%@ taglib uri="/WEB-INF/taglib/struts-html.tld" prefix="html"%>
- <%@ taglib uri="/WEB-INF/taglib/struts-logic.tld" prefix="logic"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path;
- String message = (String) request.getAttribute("msg");
- %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>新增公告</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta http-equiv="pragma" content="no-cache" />
- <link href="<%=basePath%>/css/common.css" rel="stylesheet"
- type="text/css" />
- <script src="<%=basePath%>/js/prototype.js"></script>
- <script src="<%=basePath%>/js/common.js"></script>
- <script src="<%=basePath%>/js/WebCalendar.js"></script>
- <script src="../js/credit/credit.js"></script>
- <script src="../js/AjaxBean.js"></script>
- <style>
- a.addfile {
- background-image:url(../image/all_toolbar.gif);
- color: #375771;
- font-weight: bold;
- text-align: center;
- font-size: 12px;
- display:block;
- float:left;
- height:28px;
- margin-top:-1px;
- position:relative;
- text-decoration:none;
- top:0pt;
- width:38px;
- }
- input.addfile {
- /*left:-18px;*/
- }
- input.addfile {
- cursor:pointer !important;
- height:28px;
- left:-10px;
- filter:alpha(opacity=0);
- position:absolute;
- top:2px;
- width:1px;
- }
- </style>
- <script type="text/javascript">
- function doAdd(type) {
- //获取标题
- var title = $F("title");
- var length = getStringLength(title);
- if (length == 0) {
- alert("标题不能为空");
- $("title").focus();
- return;
- }
- if (length > 90) {
- alert("标题只能输入90个字符(30个汉字),当前长度为:" + length);
- $("title").focus();
- return;
- }
- //获取内容
- if(!check('content','公告内容')){$('content').focus();return;}
- if(get('content') != "")
- {
- var length = getStringLength($F('content'));
- if (length > 1500) {
- alert("公告内容最多只能输入1500个字符(500个汉字)");
- $('content').focus();
- return;
- }
- }
- //获取选取的产品ID
- var checkProductArr = checkedCheckBox("checkProductType");
- if (checkProductArr.length == 0) {
- alert("请勾选产品类别");
- return;
- }
- //获取选取的级别ID
- var checkGradeArr = checkedCheckBox("checkDistributeGrade");
- if (checkGradeArr.length == 0) {
- alert("请勾选分销商级别");
- return;
- }
- //获取选取的省份ID
- var checkProvinceArr = checkedCheckBox("checkProvince");
- if (checkProvinceArr.length == 0) {
- alert("请勾选省份");
- return;
- }
- //用json封装参数
- var productTypeArr = new Array();
- if (checkProductArr != null) {
- for (var i = 0;i < checkProductArr.length; i++) {
- var hash = $H();
- hash.set("id",checkProductArr[i]);
- productTypeArr[i]= hash.toJSON();
- }
- }
- var jsonProduct = "[" + productTypeArr + "]";
- var gradeArr = new Array();
- if (checkGradeArr != null) {
- for (var i = 0;i < checkGradeArr.length; i++) {
- var hash = $H();
- hash.set("id",checkGradeArr[i]);
- gradeArr[i]= hash.toJSON();
- }
- }
- var jsonGrade = "[" + gradeArr + "]";
- var provinceArr = new Array();
- if (checkProvinceArr != null) {
- for (var i = 0;i < checkProvinceArr.length; i++) {
- var hash = $H();
- hash.set("id",checkProvinceArr[i]);
- provinceArr[i]= hash.toJSON();
- }
- }
- var jsonProvince = "[" + provinceArr + "]";
- var totalJson = new Array();
- //var totalHash = new $H();
- //totalHash.set("product",jsonProduct);
- //totalHash.set("grade",jsonGrade);
- //totalHash.set("province",jsonProvince);
- //totalJson[0] = totalHash.toJSON();
- //构造JSON字符串
- totalJson[0] ="{/"product/":"+jsonProduct+",/"grade/":"+jsonGrade+",/"province/":"+jsonProvince+"}";
- $("parameter").value = totalJson;
- if (type == "add") {
- $("type").value = "add";
- } else {
- $("type").value = "publish";
- }
- document.forms[0].submit();
- }
- function showMessage()
- {
- var message = '<%=message%>';
- if(message !="null" && message !='')
- {
- if(message =="exceedThan5M")
- {
- alert("您上传的单个文件大小超过5M,请重新选择附件!");
- return;
- }
- if(message=="fileExist")
- {
- alert("您上传的文件已在服务器上存在,请更改文件名后再上传!");
- return;
- }
- if(message=="pathError")
- {
- alert("您上传的文件名或路径不正确,请重新上传!");
- return;
- }
- }
- }
- function MultiSelector(list_target, max)
- {
- this.list_target = list_target;
- this.count = 0;
- this.id = 0;
- this.oldElement=null;
- if (max)
- {
- this.max = max;
- }
- else
- {
- this.max = -1;
- }
- /**
- * Add a new file input element
- */
- this.addElement = function(element)
- {
- if (element.tagName == 'INPUT' && element.type == 'file')
- {
- this.oldElement=element;
- element.name = 'file_' + this.id++;
- element.multi_selector = this;
- element.onchange = function()
- {
- var new_element = document.createElement('input');
- new_element.type = 'file';
- new_element.size = 1;
- new_element.className = "addfile";
- this.parentNode.insertBefore(new_element, this);
- this.multi_selector.addElement(new_element);
- this.multi_selector.addListRow(this);
- this.style.position = 'absolute';
- this.style.left = '-1000px';
- };
- if (this.max != -1 && this.count >= this.max)
- {
- element.disabled = true;
- }
- this.count++;
- this.current_element = element;
- }
- else
- {
- alert('Error: not a file input element');
- };
- };
- /**
- * Add a new row to the list of files
- */
- this.addListRow = function(element)
- {
- if(this.list_target.innerText.indexOf(element.value) !=-1)
- {
- alert("列表中已包含此文件,无须重复提交!");
- this.count--;
- this.oldElement.disabled = false;
- thisthis.current_element = this.oldElement;
- return;
- }
- var new_col = document.createElement('div');
- new_col.align="left";
- var new_row_button = document.createElement('input');
- new_row_button.type = 'button';
- new_row_button.value = '删除';
- new_row_button.className="tbutton";
- new_col.element = element;
- new_row_button.onclick = function()
- {
- this.parentNode.element.parentNode.removeChild(this.parentNode.element);
- this.parentNode.parentNode.removeChild(this.parentNode);
- this.parentNode.element.multi_selector.count--;
- this.parentNode.element.multi_selector.current_element.disabled = false;
- if($('files_list').innerText==''){
- $('fileStr').style.display="none";
- }
- return false;
- };
- new_col.innerHTML = element.value + " ";
- new_col.appendChild(new_row_button);
- this.list_target.appendChild(new_col);
- if($('files_list').innerText!=''){
- $('fileStr').style.display="block";
- }
- };
- }
- </script>
- </head>
- <body onload="showMessage();">
- <!-- Part I: page title -->
- <table width="100%" height="32">
- <tr>
- <td class="page_title">公告管理 >> 新建公告</td>
- </tr>
- </table>
- <br />
- <!-- Part II: search bar -->
- <html:form action="/notice.do" enctype="multipart/form-data">
- <html:hidden property="method" value="doAdd" />
- <html:hidden property="parameter" />
- <html:hidden property="type" />
- <input type="hidden" name="num" value="0">
- <table width="78%" align=center class="tablecss" cellpadding="0"
- cellspacing="1">
- <tbody class="tbodycss">
- <tr>
- <td width="59">标题:</td>
- <td align="left"><html:text property="title" size="60"
- styleId="title" styleClass="textcss"></html:text><font
- color="#FF0000">*</font></td>
- <td><a href="javascript:void(1==1);" class="addfile"
- style="cursor: default;"><input id="my_file_element"
- class="addfile" type="file" name="file_1" size="1" title="点击选择附件">
- </a> <font color="#FF0000">(附件单个文件大小不能超过5兆)</font></td>
- </tr>
- <tr id="fileStr" style="display:none">
- <td>附件列表:</td>
- <td colspan="2">
- <div id="files_list"></div>
- </td>
- </tr>
- <tr>
- <td colspan=3 align="center">公 告 内 容</td>
- </tr>
- <tr>
- <td colspan=3><html:textarea property="content" cols="100"
- rows="20" /></td>
- </tr>
- </tbody>
- </table>
- <br />
- <table width="78%" align=center class="tablecss" cellpadding="0"
- cellspacing="1">
- <tr>
- <td colspan="3" class="tdBagcolor_td_header_unSetFont"><font
- color="#FF0000">* </font>选择发布的产品类别,分销商级别和发布的区域</td>
- </tr>
- <thead class="theadcss">
- <tr>
- <td width="31%">产品类别</td>
- <td width="27%">分销商级别</td>
- <td width="42%">发布区域</td>
- </tr>
- </thead>
- <tbody class="tbodycss">
- <tr>
- <td align="left" valign="top"><logic:iterate
- name="listProductType" id="productType">
- <input type="checkBox" id="checkProductType"
- value="<bean:write name='productType' property='id' />" />
- <bean:write name="productType" property="name" />
- <br>
- </logic:iterate></td>
- <td align="left" valign="top"><logic:iterate
- name="listDistributeGrade" id="distributeGrade">
- <input type="checkBox" id="checkDistributeGrade"
- value="<bean:write name='distributeGrade' property='id' />" />
- <bean:write name="distributeGrade" property="name" />
- <br>
- </logic:iterate></td>
- <td align="left"><logic:iterate name="listProvince"
- id="province">
- <input type="checkBox" id="checkProvince"
- value="<bean:write name='province' property='id' />" />
- <bean:write name="province" property="name" />
- </logic:iterate></td>
- </tr>
- <tr align="left">
- <td colspan="3"><font color="#0000FF">注意:</font><font
- color="#FF0000">* </font><font color="#0000FF">为必填项</font></td>
- </tr>
- </tbody>
- </table>
- <div align="center"><br />
- <span class="search_button"> <input name="Submit" type="button"
- class="tbutton" value="保 存" onClick="doAdd('add')" /> <input
- name="Submit" type="button" class="tbutton" value="发 布"
- onclick="doAdd('publish')" /> <input name="Submit2" type="button"
- class="tbutton" onClick="history.back();" value="返 回" /> </span></div>
- <div align="center"><br />
- </div>
- </html:form>
- <script>
- var multi_selector = new MultiSelector(document.getElementById('files_list'), 5);
- multi_selector.addElement(document.getElementById('my_file_element'));
- </script>
- </body>
- </html>
Action
- /**
- * 描述:添加公告(转发)
- *
- * @return
- */
- public ActionForward prepareAdd(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- // 保存令牌
- this.saveToken(request);
- List listProductType = noticeBo.listProductType();
- List listDistributorGrade = noticeBo.listDistributeGrade();
- List listProvince = noticeBo.listProvince();
- // request.setAttribute(MSG, "");
- request.setAttribute(LISTPRODUCTTYPE, listProductType);
- request.setAttribute(LISTDISTRIBUTEGRADE, listDistributorGrade);
- request.setAttribute(LISTPROVINCE, listProvince);
- return mapping.findForward(ADD);
- }
- /**
- * 描述:添加公告
- *
- * @return
- */
- public ActionForward doAdd(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- if (isTokenValid(request)) {
- Notice notice = new Notice();
- NoticeForm searchForm = (NoticeForm) form;
- JSONObject jsonObject = JSONObject.fromObject(searchForm
- .getParameter());
- JSONArray jsonArraytmp1 = (JSONArray) jsonObject.get("product");
- List listProduct = new ArrayList();
- for (int i = 0, n = jsonArraytmp1.size(); i < n; i++) {
- JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp1.get(i);
- listProduct.add(jsonObjecttmp1.get("id"));
- }
- JSONArray jsonArraytmp2 = (JSONArray) jsonObject.get("grade");
- List listGrade = new ArrayList();
- for (int i = 0, n = jsonArraytmp2.size(); i < n; i++) {
- JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp2.get(i);
- listGrade.add(jsonObjecttmp1.get("id"));
- }
- JSONArray jsonArraytmp3 = (JSONArray) jsonObject.get("province");
- List listProvince = new ArrayList();
- for (int i = 0, n = jsonArraytmp3.size(); i < n; i++) {
- JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp3.get(i);
- listProvince.add(jsonObjecttmp1.get("id"));
- }
- String dir = servlet.getServletContext().getRealPath(
- "system/notice/upload");
- Hashtable files = searchForm.getMultipartRequestHandler()
- .getFileElements();
- StringBuffer fileName = new StringBuffer("");
- for (Enumeration e = files.keys(); e.hasMoreElements();) {
- String key = (String) e.nextElement();
- FormFile formFile = (FormFile) files.get(key);
- if (formFile.getFileSize() > 0) {
- if (formFile.getFileSize() / 1024 / 1024 > 5) {
- // 上传文件大于5M
- request.setAttribute(MSG, EXCEEDTHAN5M);
- return prepareAdd(mapping, form, request, response);
- }
- // 先判断服务器上有没有同名文件
- File file = new File(dir + "//"
- + formFile.getFileName().trim());
- fileName.append(formFile.getFileName().trim()).append(";");
- if (file.exists()) {
- // 存在同名文件,提示用户
- request.setAttribute(MSG, FILEEXIST);
- return prepareAdd(mapping, form, request, response);
- }
- // 上传文件
- InputStream in = null;
- OutputStream out = null;
- try {
- in = formFile.getInputStream();
- File uploadFile = new File(dir);
- if (!uploadFile.exists() || uploadFile == null) {
- uploadFile.mkdir();
- }
- String path = uploadFile.getPath() + "/"
- + formFile.getFileName();
- out = new FileOutputStream(path);
- int byteRead = 0;
- byte[] buffer = new byte[8192];
- while ((byteRead = in.read(buffer, 0, 8192)) != -1) {
- out.write(buffer, 0, byteRead);
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- } finally {
- try {
- if (in != null) {
- in.close();
- }
- if (out != null) {
- out.close();
- }
- formFile.destroy();
- } catch (Exception ee) {
- ee.printStackTrace();
- }
- }
- } else if (formFile.getFileSize() == 0
- && !CommonUtil.isEmpty(formFile.getFileName())) {
- // 本地上传路径不正确
- // 记录错误信息
- request.setAttribute(MSG, PATHERROR);
- return prepareAdd(mapping, form, request, response);
- }
- }
- UserBean userBean = (UserBean) request.getSession().getAttribute(
- USERBEAN);
- Account account = new Account();
- account.setId(userBean.getAccount_id());
- notice.setAttachment(fileName.toString());
- notice.setAccount(account);
- notice.setContent(searchForm.getContent());
- notice.setTitle(searchForm.getTitle());
- if (CommonUtil.isEmpty(searchForm.getIsDelete())) {
- searchForm.setIsDelete(Constants.ENABLE_N);
- }
- notice.setIsDelete(searchForm.getIsDelete());
- notice.setDistributorGradeList(listGrade);
- notice.setProductTypeList(listProduct);
- notice.setProvinceList(listProvince);
- if (searchForm.getType().equals(ADD)) {
- notice.setIsPublished(Constants.ENABLE_N);
- } else {
- notice.setIsPublished(Constants.ENABLE_Y);
- notice.setCreateDate(new Date(System.currentTimeMillis()));
- }
- if (this.isTokenValid(request)) {
- noticeBo.AddNotice(notice, userBean);
- this.saveToken(request);
- }
- // 操作成功后重置令牌
- this.saveToken(request);
- return mapping.findForward(SINGLELIST);
- } else {
- // 重新生成令牌
- saveToken(request);
- return prepareAdd(mapping, form, request, response);
- }
- }
- /**
- * 描述:下载附件操作
- *
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws UnsupportedEncodingException
- * @throws Exception
- */
- public ActionForward downLoad(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response)
- throws UnsupportedEncodingException {
- NoticeForm noticeForm = (NoticeForm) form;
- String fileName = noticeForm.getSubAttachment();
- String dir = servlet.getServletContext().getRealPath(
- "system/notice/upload");
- //
- dir = dir + "//" + fileName;
- File f = new File(dir);
- byte[] buf = new byte[1024];
- int len = 0;
- response.reset();
- response.setContentType("application/x-msdownload;charset=ISO-8859-1");
- response.setHeader("Content-Disposition", "attachment; filename="
- + CommonUtil.Utf8URLencode(fileName));
- OutputStream out;
- try {
- BufferedInputStream br = new BufferedInputStream(
- new FileInputStream(f));
- out = response.getOutputStream();
- while ((len = br.read(buf)) > 0) {
- out.write(buf, 0, len);
- out.flush();
- }
- br.close();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * 描述:修改公告(转发)
- *
- * @return
- */
- public ActionForward prepareUpdate(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- String id = request.getParameter("id");
- Long noticeId = null;
- try {
- noticeId = Long.valueOf(id);
- } catch (Exception e) {
- e.printStackTrace();
- }
- Notice notice = noticeBo.getNotice(noticeId);
- NoticeForm noticeForm = (NoticeForm) form;
- request.setAttribute(OLDPAGE, new Integer(noticeForm.getCurrentPage()));
- noticeForm.setId(notice.getId());
- noticeForm.setTitle(notice.getTitle());
- noticeForm.setContent(notice.getContent());
- noticeForm.setIsPublished(notice.getIsPublished());
- noticeForm.setIsDelete(notice.getIsDelete());
- noticeForm.setAttachment(notice.getAttachment());
- List distributorGradeList = notice.getDistributorGradeList();
- List productTypeList = notice.getProductTypeList();
- List provinceList = notice.getProvinceList();
- if (distributorGradeList != null) {
- int distributorSize = distributorGradeList.size();
- String[] distributor = new String[distributorSize];
- for (int si = 0; si < distributorSize; si++) {
- NoticeDistributorGrade distributorGrade = (NoticeDistributorGrade) distributorGradeList
- .get(si);
- distributor[si] = String.valueOf(distributorGrade
- .getDistributorGrade().getId());
- }
- noticeForm.setCheckDistributeGrade(distributor);
- }
- if (productTypeList != null) {
- int productTypeSize = productTypeList.size();
- String[] checkProductType = new String[productTypeSize];
- for (int si = 0; si < productTypeSize; si++) {
- NoticePT productType = (NoticePT) productTypeList.get(si);
- checkProductType[si] = String.valueOf(productType
- .getProductType().getId());
- }
- noticeForm.setCheckProductType(checkProductType);
- }
- if (provinceList != null) {
- int provinceListSize = provinceList.size();
- String[] checkProvince = new String[provinceListSize];
- for (int si = 0; si < provinceListSize; si++) {
- NoticeProvince province = (NoticeProvince) provinceList.get(si);
- checkProvince[si] = String.valueOf(province.getProvince()
- .getId());
- }
- noticeForm.setCheckProvince(checkProvince);
- }
- List list = new ArrayList();
- if (null != notice.getAttachment()) {
- String[] str = notice.getAttachment().split(";");
- for (int i = 0; i < str.length; i++) {
- ConstBean cb = new ConstBean();
- cb.setLabel(str[i]);
- list.add(cb);
- }
- }
- request.setAttribute(ATTACHMENTLIST, list);
- List listProductType = noticeBo.listProductType();
- List listDistributorGrade = noticeBo.listDistributeGrade();
- List listProvince = noticeBo.listProvince();
- // request.setAttribute(MSG, "");
- request.setAttribute("formFile", notice.getAttachment() == null ? ""
- : notice.getAttachment());
- request.setAttribute(LISTPRODUCTTYPE, listProductType);
- request.setAttribute(LISTDISTRIBUTEGRADE, listDistributorGrade);
- request.setAttribute(LISTPROVINCE, listProvince);
- // 设置令牌
- this.saveToken(request);
- return mapping.findForward(UPDATE);
- }
- /**
- * 描述:修改公告
- *
- * @return
- */
- public ActionForward doUpdate(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- try {
- if (isTokenValid(request)) {
- NoticeForm searchForm = (NoticeForm) form;
- JSONObject jsonObject = JSONObject.fromObject(searchForm
- .getParameter());
- JSONArray jsonArraytmp1 = (JSONArray) jsonObject.get("product");
- List listProduct = new ArrayList();
- for (int i = 0, n = jsonArraytmp1.size(); i < n; i++) {
- JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp1
- .get(i);
- listProduct.add(jsonObjecttmp1.get("id"));
- }
- JSONArray jsonArraytmp2 = (JSONArray) jsonObject.get("grade");
- List listGrade = new ArrayList();
- for (int i = 0, n = jsonArraytmp2.size(); i < n; i++) {
- JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp2
- .get(i);
- listGrade.add(jsonObjecttmp1.get("id"));
- }
- JSONArray jsonArraytmp3 = (JSONArray) jsonObject
- .get("province");
- List listProvince = new ArrayList();
- for (int i = 0, n = jsonArraytmp3.size(); i < n; i++) {
- JSONObject jsonObjecttmp1 = (JSONObject) jsonArraytmp3
- .get(i);
- listProvince.add(jsonObjecttmp1.get("id"));
- }
- UserBean userBean = (UserBean) request.getSession()
- .getAttribute(USERBEAN);
- Notice notice = new Notice();
- Notice noticeTemp = (Notice) noticeBo.getNoticeById(searchForm
- .getId());
- Account account = new Account();
- account.setId(userBean.getAccount_id());
- notice.setAccount(account);
- notice.setId(searchForm.getId());
- notice.setContent(searchForm.getContent());
- notice.setTitle(searchForm.getTitle());
- notice.setModifyDate(new Date(System.currentTimeMillis()));
- if (CommonUtil.isEmpty(searchForm.getIsDelete())) {
- searchForm.setIsDelete(Constants.ENABLE_N);
- }
- notice.setIsDelete(searchForm.getIsDelete());
- notice.setDistributorGradeList(listGrade);
- notice.setProductTypeList(listProduct);
- notice.setProvinceList(listProvince);
- if (searchForm.getType().equals(UPDATE)) {
- notice.setIsPublished(searchForm.getIsPublished());
- notice.setCreateDate(noticeTemp.getCreateDate());
- } else {
- notice.setIsPublished(Constants.ENABLE_Y);
- notice.setCreateDate(new Date(System.currentTimeMillis()));
- }
- String dir = servlet.getServletContext().getRealPath(
- "system/notice/upload");
- StringBuffer fileName = new StringBuffer("");
- // 获取原有附件
- if (!CommonUtil.isEmpty(searchForm.getAttachment())) {
- fileName.append(searchForm.getAttachment());
- }
- // 如果原来有附件,现在已删除,则删除存放在服务器端的原来的附件
- if (!CommonUtil.isEmpty(notice.getAttachment())
- && !notice.getAttachment().equals(
- searchForm.getAttachment())) {
- // 找出被删除的附件
- String[] att = notice.getAttachment().split(";");
- String temp = searchForm.getAttachment();
- for (int i = 0; i < att.length; i++) {
- // 如果该文件名在传过来的文件名中不存在,则删除
- if (temp.indexOf(att[i]) == -1) {
- File file = new File(dir + "//" + att[i]);
- if (file.exists()) {
- // 存在则删除
- file.delete();
- }
- }
- }
- }
- Hashtable files = searchForm.getMultipartRequestHandler()
- .getFileElements();
- for (Enumeration e = files.keys(); e.hasMoreElements();) {
- String key = (String) e.nextElement();
- FormFile formFile = (FormFile) files.get(key);
- if (formFile.getFileSize() > 0) {
- if (formFile.getFileSize() / 1024 / 1024 > 5) {
- // 上传文件大于5M
- request.setAttribute(MSG, EXCEEDTHAN5M);
- return prepareUpdate(mapping, form, request,
- response);
- }
- // 先判断服务器上有没有同名文件
- File file = new File(dir + "//"
- + formFile.getFileName().trim());
- if (file.exists()) {
- // 存在同名文件,提示用户
- request.setAttribute(MSG, FILEEXIST);
- return prepareUpdate(mapping, form, request,
- response);
- }
- // 判断原来上传的文件中是否有相同的名称,有则提示
- if (!CommonUtil.isEmpty(notice.getAttachment())) {
- if (notice.getAttachment().indexOf(
- formFile.getFileName().trim()) != -1) {
- // 存在同名文件,提示用户
- request.setAttribute(MSG, FILEEXIST);
- return prepareUpdate(mapping, form, request,
- response);
- }
- }
- // 上传文件
- InputStream in = null;
- OutputStream out = null;
- try {
- in = formFile.getInputStream();
- File uploadFile = new File(dir);
- if (!uploadFile.exists() || uploadFile == null) {
- uploadFile.mkdir();
- }
- String path = uploadFile.getPath() + "/"
- + formFile.getFileName();
- out = new FileOutputStream(path);
- int byteRead = 0;
- byte[] buffer = new byte[8192];
- while ((byteRead = in.read(buffer, 0, 8192)) != -1) {
- out.write(buffer, 0, byteRead);
- }
- // 保存路径
- fileName.append(formFile.getFileName().trim())
- .append(";");
- } catch (Exception ex) {
- ex.printStackTrace();
- } finally {
- try {
- if (in != null) {
- in.close();
- }
- if (out != null) {
- out.close();
- }
- formFile.destroy();
- } catch (Exception ee) {
- ee.printStackTrace();
- }
- }
- } else if (formFile.getFileSize() == 0
- && !CommonUtil.isEmpty(formFile.getFileName())) {
- // 本地上传路径不正确
- // 记录错误信息
- request.setAttribute(MSG, PATHERROR);
- return prepareUpdate(mapping, form, request, response);
- }
- }
- notice.setAttachment(fileName.toString());
- noticeBo.updateNotice(notice, userBean);
- // 重置令牌
- this.saveToken(request);
- return mapping.findForward(SINGLELIST);
- } else {
- // 重新生成令牌
- saveToken(request);
- return prepareUpdate(mapping, form, request, response);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- /**
- * 描述:发布公告
- *
- * @return
- */
- public ActionForward doPublish(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- String id = request.getParameter("id");
- Long noticeId = null;
- try {
- noticeId = Long.valueOf(id);
- } catch (Exception e) {
- }
- UserBean userBean = (UserBean) request.getSession().getAttribute(
- USERBEAN);
- noticeBo.promulgate(noticeId, userBean);
- return mapping.findForward(SINGLELIST);
- }
- /**
- * 描述:显示公告
- *
- * @return
- */
- public ActionForward display(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- String id = request.getParameter("id");
- Long noticeId = null;
- try {
- noticeId = Long.valueOf(id);
- } catch (Exception e) {
- }
- Notice notice = noticeBo.getNotice(noticeId);
- notice.setContent(notice.getContent().replaceAll("//r//n", "<br/>"));
- if (notice == null) {
- notice = new Notice();
- }
- List list = new ArrayList();
- if (null != notice.getAttachment()) {
- String[] str = notice.getAttachment().split(";");
- for (int i = 0; i < str.length; i++) {
- ConstBean cb = new ConstBean();
- cb.setLabel(str[i]);
- list.add(cb);
- }
- }
- request.setAttribute(ATTACHMENTLIST, list);
- String type = request.getParameter("type");
- if (type != null && type.equals(DISTRIBUTOR)) {
- notice.setProvinceList(new ArrayList());
- notice.setDistributorGradeList(new ArrayList());
- }
- request.setAttribute(NOTICE, notice);
- return mapping.findForward(DISPLAY);
- }
- /**
- * 描述:彻底删除公告
- *
- * @return
- */
- public ActionForward doDeleted(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- String id = request.getParameter("id");
- Long noticeId = null;
- try {
- noticeId = Long.valueOf(id);
- // 判断公告是否有附件,有则删除
- Notice notice = noticeBo.getNotice(noticeId);
- File file = null;
- if (!CommonUtil.isEmpty(notice.getAttachment())) {
- String dir = servlet.getServletContext().getRealPath(
- "system/notice/upload");
- String[] att = notice.getAttachment().split(";");
- for (int i = 0; i < att.length; i++) {
- file = new File(dir + "//" + att[i]);
- if (file.exists()) {
- // 存在则删除
- file.delete();
- }
- }
- }
- UserBean userBean = (UserBean) request.getSession().getAttribute(
- USERBEAN);
- noticeBo.deletedNotice(noticeId, userBean);
- } catch (Exception e) {
- request.setAttribute(MSG, "deleteError");
- e.printStackTrace();
- }
- return mapping.findForward(ALLLIST);
- }