Program 模块设计及实现

本文介绍了一个基于Struts2框架实现的节目管理模块,该模块允许用户创建包含多种资源类型的节目,并提供了资源的选择与布局设计功能。文章详细解释了页面结构、脚本功能、资源管理及节目创建流程。

manage_program.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <style type="text/css"> .programConfig { width: 200px; height: 400px; border: 1px solid; float: left; } .programArea { border: 1px solid; position: relative; width: 600px; height: 400px; left: 250px; } .hid{ display: none; } </style> <script type="text/javascript"> function lastIndexDemo() { var str1 = "123,abc,"; var s = str1.lastIndexOf(","); alert(s); alert(str1.substr(0,s)); alert(str1.substring(0, str1.length-1)); } $(document).ready(function(){ $('#btnSaveProgram').click(function(){ var programName = $('#programName').val(); var hours = $('#hours').val(); var minutes = $('#minutes').val(); var seconds = $('#seconds').val(); var programLength = (parseInt(hours)*60 + parseInt(minutes))*60 + parseInt(seconds); var jsonData = ""; $("#programArea div").each(function(data){ if(this.style.display != "none"){ var key = this.id;// template model id var value1 = this.title; // template model dimension var value2 = this.style.zIndex; // template model gradation var value3 = this.innerHTML; // resource name jsonData += (key + ":" + value1 + ":" + value2 + ":" + value3 + "|"); } }); jsonData = jsonData.substring(0, jsonData.length - 1); alert(jsonData); $.ajax({ type: "POST", url: "/CPSolution/addProgram.html", dataType:"html", data: {programName:programName,length:programLength,relation:jsonData}, success: function(data){ alert(data); }, error:function(){ alert("加载失败"); } }); }); }); function selectResource(modeldiv){ var type = modeldiv.id.split("_")[1].substr(0,1); if(type == "i"){ $("#imageSourceList").dialog({ height:520, width:900, modal:true }); $("#imageSourceList a").click(function(){ alert(this.title); $('#imageSourceList').dialog("close"); modeldiv.innerHTML = this.title; }); } if(type == "v"){ $("#videoSourceList").dialog({ height:520, width:900, modal:true }); $("#videoSourceList a").click(function(){ alert(this.title); $('#videoSourceList').dialog("close"); modeldiv.innerHTML = this.title; }); } if(type == "t"){ $("#textSourceList").dialog({ height:520, width:900, modal:true }); $("#textSourceList a").click(function(){ alert(this.title); $('#textSourceList').dialog("close"); modeldiv.innerHTML = this.title; }); } if(type == "a" ){ $("#audioSourceList").dialog({ height:520, width:900, modal:true }); $("#audioSourceList a").click(function(){ alert(this.title); $('#audioSourceList').dialog("close"); modeldiv.innerHTML = this.title; }); } } function templateSelected(selectObj){ var selectedValue = selectObj.value; if(selectedValue == "0"){ $('#templateSelect').options[0].selected=true; $("#programArea div input").each(function(data){ var modelDiv = $("#"+(this.id)).parent(); modelDiv.css("display","none"); }); }else{ // 将模板中的布局画到programArea中 $("#programArea div input").each(function(data){ var modelDiv = $("#"+(this.id)).parent(); modelDiv.css("display","none"); if(selectedValue == this.value){ var dimensionVals = modelDiv.attr("title").split(","); var leftVal = dimensionVals[0]; var topVal = dimensionVals[1]; var widthVal = parseInt(dimensionVals[2]) - parseInt(leftVal); var heightVale = parseInt(dimensionVals[3]) - parseInt(topVal); modelDiv.css("left",leftVal+"px"); modelDiv.css("top",topVal+"px"); modelDiv.css("width",widthVal); modelDiv.css("height",heightVale); modelDiv.css("display",""); modelDiv.css("position","absolute"); if(this.id.split("_")[2] == "video"){ modelDiv.css("background","red"); } if(this.id.split("_")[2] == "audio"){ modelDiv.css("background","black"); } if(this.id.split("_")[2] == "image"){ modelDiv.css("background","blue"); } if(this.id.split("_")[2] == "text"){ modelDiv.css("background","green"); } } }); } } // 添加节目 function addProgram(){ templateSelected(0); popupAlert("alertBoxAddProgram",880,440); } </script> </head> <body> <div onclick="javascript:addProgram()">添加节目</div> <div id="alertBoxAddProgram" style="display: none;"> <div id="programConfig" class="rightBoxes" style="z-index: 1000"> <div class="rightBoxesTop"> <h3>节目配置</h3> </div> <div class="rightContent"> 节目名称:<input id="programName" type="text" name="" size="15"/><br> 播放时长:<br> <input id="hours" type="text" name="" style="text-align: right;" value="0" size="15"/><span>小时</span><br> <input id="minutes" type="text" name="" style="text-align: right;" value="0" size="15"/><span>分钟</span><br> <input id="seconds" type="text" name="" style="text-align: right;" value="0" size="15"/><span>秒</span><br> 选择模板: <s:select id="templateSelect" onchange="javascript:templateSelected(this)" name="template" list="templateList" listKey="id" listValue="name" headerKey="0" headerValue="请选择模板" label="请选择模板" /> </div> <div> <input id="btnSaveProgram" type="button" value="保存" /> <input onclick="lastIndexDemo();" id="btnCancelProgram" type="button" value="取消" /> </div> </div> <div id="programArea" class="programArea"> <s:iterator value="templateList" var="templateObj"> <s:iterator value="#templateObj.models" var="model"> <div ondblclick="javascript:selectResource(this)" title="${model.dimension}" id="${model.id }" style="z-index: ${model.gradation }; display:none;text-align:center;font-size:12px;color:white;" ><input id="${model.id }_${model.type }" type="hidden" value="${templateObj.id }">双击我选择${model.type }类型资源</div> </s:iterator> </s:iterator> </div> </div> <div id="videoSourceList" class="hid"> <table class="sTable"> <thead> <tr> <th><strong>视频名称</strong></th> <th><strong>视频备注</strong></th> <th><strong>预览</strong></th> <th><strong>选择</strong></th> </tr> </thead> <s:iterator value="#session.videoList" id="" status="" var="video"> <tr class="oddRow"> <td class="firstCol">${video.resourceName }</td> <td>${video.paramRemark }</td> <td class="secondCol">点击播放</td> <td class="secondCol"><a title="${video.resourceName }" href="#">点击选择</a></td> </tr> </s:iterator> </table> </div> <!-- image --> <div id="imageSourceList" class="hid"> <table class="sTable"> <thead> <tr> <th><strong>图片名称</strong></th> <th><strong>图片备注</strong></th> <th><strong>预览</strong></th> <th><strong>选择</strong></th> </tr> </thead> <s:iterator value="#session.imageList" id="" status="" var="image"> <tr class="oddRow"> <td class="firstCol">${image.resourceName }</td> <td>${image.paramRemark }</td> <td class="secondCol">点击预览</td> <td class="secondCol"><a title="${image.resourceName }" href="#">点击选择</a></td> </tr> </s:iterator> </table> </div> <!-- audio --> <div id="audioSourceList" class="hid"> <table class="sTable"> <thead> <tr> <th><strong>音频名称</strong></th> <th><strong>音频备注</strong></th> <th><strong>试听</strong></th> <th><strong>选择</strong></th> </tr> </thead> <s:iterator value="#session.audioList" id="" status="" var="audio"> <tr class="oddRow"> <td class="firstCol">${audio.resourceName }</td> <td>${audio.paramRemark }</td> <td class="secondCol">点击试听</td> <td class="secondCol"><a title="${audio.resourceName }" href="#">点击选择</a></td> </tr> </s:iterator> </table> </div> <!-- text --> <div id="textSourceList" class="hid"> <table class="sTable"> <thead> <tr> <th><strong>文本名称</strong></th> <th><strong>文本备注</strong></th> <th><strong>预览</strong></th> <th><strong>选择</strong></th> </tr> </thead> <s:iterator value="#session.textList" id="" status="" var="text"> <tr class="oddRow"> <td class="firstCol">${text.resourceName }</td> <td>${text.paramRemark }</td> <td class="secondCol">点击预览</td> <td class="secondCol"><a title="${text.resourceName }" href="#">点击选择</a></td> </tr> </s:iterator> </table> </div> </body> </html>

ProgramDB.xml

<programs> <program id="program_1329275880060" name="test"> <param name="remark">test</param> <param name="length">3600</param> <param name="createtime">2012-18-15 11:18:00</param> <param name="createby">a</param> <param name="template">template_1300535343</param> <param name="onebyones"> <onebyone resource="1225234235623523.jpg" dimension="0,0,301,211" gradation="1" /> </param> </program> </programs>

ResourceAction.java

package com.cemso.action; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import org.jdom.JDOMException; import com.cemso.dto.ResourceDTO; import com.cemso.service.ResourceService; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class ResourceAction extends ActionSupport { /** * */ private static final long serialVersionUID = 1L; private ResourceService resourceService; private List<ResourceDTO> resourceList; private List<ResourceDTO> videoList; private List<ResourceDTO> imageList; private List<ResourceDTO> audioList; private List<ResourceDTO> textList; public String execute() { ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); String resourceType = request.getParameter("type"); imageList = new ArrayList<ResourceDTO>(); videoList = new ArrayList<ResourceDTO>(); audioList = new ArrayList<ResourceDTO>(); textList = new ArrayList<ResourceDTO>(); Map<String,Object> session = context.getSession(); try { resourceList = resourceService.getResourceList(); for(ResourceDTO resource : resourceList){ if(resource.getResourceType().equals("video")){ videoList.add(resource); } if(resource.getResourceType().equals("audio")){ audioList.add(resource); } if(resource.getResourceType().equals("image")){ imageList.add(resource); } if(resource.getResourceType().equals("text")){ textList.add(resource); } } session.put("videoList", videoList); session.put("imageList", imageList); session.put("audioList", audioList); session.put("textList", textList); session.put("resourceList", resourceList); // text if(resourceType.equals("#box-1")){ return "textpage"; } // audio if(resourceType.equals("#box-2")){ return "audiopage"; } // image if(resourceType.equals("#box-3")){ return "imagepage"; } // video if(resourceType.equals("#box-4")){ return "videopage"; } } catch (JDOMException e) { e.printStackTrace(); return ERROR; } catch (IOException e) { e.printStackTrace(); return ERROR; } return ERROR; } public String displayCategory(){ return "manageResourcePage"; } public ResourceService getResourceService() { return resourceService; } public void setResourceService(ResourceService resourceService) { this.resourceService = resourceService; } public List<ResourceDTO> getResourceList() { return resourceList; } public void setResourceList(List<ResourceDTO> resourceList) { this.resourceList = resourceList; } public List<ResourceDTO> getVideoList() { return videoList; } public void setVideoList(List<ResourceDTO> videoList) { this.videoList = videoList; } public List<ResourceDTO> getImageList() { return imageList; } public void setImageList(List<ResourceDTO> imageList) { this.imageList = imageList; } public List<ResourceDTO> getAudioList() { return audioList; } public void setAudioList(List<ResourceDTO> audioList) { this.audioList = audioList; } public List<ResourceDTO> getTextList() { return textList; } public void setTextList(List<ResourceDTO> textList) { this.textList = textList; } }
ProgramAction.java

package com.cemso.action; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import org.jdom.JDOMException; import com.cemso.dto.OnebyoneDTO; import com.cemso.dto.ProgramDTO; import com.cemso.dto.ResourceDTO; import com.cemso.dto.TemplateDTO; import com.cemso.dto.UserDTO; import com.cemso.service.ProgramService; import com.cemso.service.ResourceService; import com.cemso.service.TemplateService; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class ProgramAction extends ActionSupport { /** * */ private static final long serialVersionUID = 1L; private ProgramService programService; private TemplateService templateService; private ResourceService resourceService; private List<TemplateDTO> templateList; private List<ResourceDTO> resourceList; public String getProgram(){ try { templateList = templateService.getTemlates(); resourceList = resourceService.getResourceList(); return "programpage"; } catch (JDOMException e) { e.printStackTrace(); return ERROR; } catch (IOException e) { e.printStackTrace(); return ERROR; } } // add program public String addProgram(){ ProgramDTO program = new ProgramDTO(); List<OnebyoneDTO> onebyoneList = new ArrayList<OnebyoneDTO>(); ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); Map<String, Object> session = context.getSession(); SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String createtime = formate.format(System.currentTimeMillis()); String createby = ((UserDTO)session.get("user")).getUserName(); String programName = request.getParameter("programName"); String length = request.getParameter("length"); String relation = request.getParameter("relation"); System.out.println(createtime); System.out.println(createby); System.out.println(programName); System.out.println(length); System.out.println(relation); String[] onebyones = relation.split("u007C"); // "|" String templateId = "template" + relation.split("_")[0]; program.setId("program_"+System.currentTimeMillis()); program.setName(programName); program.setCreateby(createby); program.setCreatetime(createtime); program.setTemplateId(templateId); program.setLength(length); for(int i = 0;i<onebyones.length;i++){ String[] onebyone = onebyones[i].split(":"); OnebyoneDTO onebyoneDTO = new OnebyoneDTO(); onebyoneDTO.setDimension(onebyone[1]); onebyoneDTO.setGradation(onebyone[2]); onebyoneDTO.setResource(onebyone[3]); onebyoneList.add(onebyoneDTO); } program.setOnebyoneList(onebyoneList); return SUCCESS; } public ProgramService getProgramService() { return programService; } public void setProgramService(ProgramService programService) { this.programService = programService; } public TemplateService getTemplateService() { return templateService; } public void setTemplateService(TemplateService templateService) { this.templateService = templateService; } public ResourceService getResourceService() { return resourceService; } public void setResourceService(ResourceService resourceService) { this.resourceService = resourceService; } public List<TemplateDTO> getTemplateList() { return templateList; } public void setTemplateList(List<TemplateDTO> templateList) { this.templateList = templateList; } public List<ResourceDTO> getResourceList() { return resourceList; } public void setResourceList(List<ResourceDTO> resourceList) { this.resourceList = resourceList; } }
ProgramDTO.java

package com.cemso.dto; import java.util.List; public class ProgramDTO { private String id; private String name; private String length; private String createtime; private String createby; private String templateId; private List<OnebyoneDTO> onebyoneList; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getLength() { return length; } public void setLength(String length) { this.length = length; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public String getCreateby() { return createby; } public void setCreateby(String createby) { this.createby = createby; } public String getTemplateId() { return templateId; } public void setTemplateId(String templateId) { this.templateId = templateId; } public List<OnebyoneDTO> getOnebyoneList() { return onebyoneList; } public void setOnebyoneList(List<OnebyoneDTO> onebyoneList) { this.onebyoneList = onebyoneList; } }

struts.xml

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.ui.theme" value="simple" /> <constant name="struts.custom.i18n.resources" value="message"></constant> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <constant name="struts.objectFactory" value="spring" /> <constant name="struts.multipart.maxSize" value="209715200" /> <constant name="struts.action.extension" value="html,do,action" /> <include file="struts-default.xml" /> <package name="default" extends="struts-default"> <action name="loginAction" class="loginAction" method="login"> <result name="success">index.jsp</result> <result name="error">common/error.html</result> </action> <action name="allResourceAction" class="resourceAction" method="displayCategory"> <result name="manageResourcePage">manage_resource.jsp</result> <result name="success">index.jsp</result> <result name="error">common/error.html</result> </action> <action name="resourceAction" class="resourceAction" method="execute"> <result name="videopage">manage_video.jsp</result> <result name="imagepage">manage_image.jsp</result> <result name="textpage">manage_text.jsp</result> <result name="audiopage">manage_audio.jsp</result> <result name="success">index.jsp</result> <result name="error">common/error.html</result> </action> <action name="fileUpload" class="com.cemso.action.FileUploadAction"> <result name="input">/index.jsp</result> <result name="success">/success.jsp</result> </action> <!-- template action --> <action name="templateAction" class="templateAction" method="addTemplate"> <result name="success">index.jsp</result> <result name="error">common/error.html</result> </action> <action name="getTemplateAction" class="templateAction" method="getTemplates"> <result name="templatepage">manage_template.jsp</result> <result name="success">index.jsp</result> <result name="error">common/error.html</result> </action> <action name="templateDesignAction" class="templateAction" method="templateDesign"> <result name="templateDesignPage">design_template.jsp</result> <result name="success">index.jsp</result> <result name="error">common/error.html</result> </action> <!-- program action --> <action name="getProgramAction" class="programAction" method="getProgram"> <result name="programpage">manage_program.jsp</result> <result name="success">index.jsp</result> <result name="error">common/error.html</result> </action> <action name="addProgram" class="programAction" method="addProgram"> <result name="success">index.jsp</result> <result name="error">common/error.html</result> </action> </package> </struts>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值