SSH action+struts.xml+jsp

StandardsAction 控制类

package cn.action;
import java.util.List;
import cn.biz.StandardsBiz;
import cn.entity.Standards;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class StandardsAction extends ActionSupport {
	private StandardsBiz standardsBiz;
	private List<Standards> standards;
	private Standards standard;
	private int pageIndex;
	private int pagecount;
	private Integer stdId;
	private String stdNum;
	private Integer[] stdIds; 
	public String toList() throws Exception{
		Integer pageSize = 4;
		pagecount = (int)Math.ceil((double)standardsBiz.findAll().size()/pageSize);
		if(pageIndex <= pagecount){
			if(stdNum == null){
				standards = standardsBiz.findByPage(pageIndex, pageSize);
			}else{
				standards = standardsBiz.findByPageOfsearch(pageIndex, pageSize, stdNum);
			}
		}else{
			if(stdNum == null){
				standards = standardsBiz.findByPage(pagecount, pageSize);
				pageIndex = pagecount;
			}else{
				standards = standardsBiz.findByPageOfsearch(pagecount, pageSize, stdNum);
				pageIndex = pagecount;
			}
		}
		return SUCCESS;
	}
	public String toUpdate() throws Exception{
		if(standard != null){
			standardsBiz.update(standard);
			return "tolist";
		}
		standard = standardsBiz.findById(stdId);
		return SUCCESS;
	}
	public String toAdd() throws Exception{
		if(standard != null){
			standardsBiz.insert(standard);
			return "tolist";
		}
		return SUCCESS;
	}
	public String toDelete() throws Exception{
		System.out.println(stdIds);
		standardsBiz.deleteByIds(stdIds);
		return SUCCESS;
	}
	public StandardsBiz getStandardsBiz() {
		return standardsBiz;
	}
	public void setStandardsBiz(StandardsBiz standardsBiz) {
		this.standardsBiz = standardsBiz;
	}
	public List<Standards> getStandards() {
		return standards;
	}
	public void setStandards(List<Standards> standards) {
		this.standards = standards;
	}
	public Standards getStandard() {
		return standard;
	}
	public void setStandard(Standards standard) {
		this.standard = standard;
	}
	public Integer getPageIndex() {
		if(pageIndex<=0){
			return 1;
		}
		return pageIndex;
	}
	public int getPagecount() {
		return pagecount;
	}
	public void setPagecount(int pagecount) {
		this.pagecount = pagecount;
	}
	public String getStdNum() {
		return stdNum;
	}
	public void setStdNum(String stdNum) {
		this.stdNum = stdNum;
	}
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}
	public Integer getStdId() {
		return stdId;
	}
	public void setStdId(Integer stdId) {
		this.stdId = stdId;
	}
	public Integer[] getStdIds() {
		return stdIds;
	}
	public void setStdIds(Integer[] stdIds) {
		this.stdIds = stdIds;
	}
}

 

struts.xml 配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" 
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<constant name="struts.i18n.encoding" value="utf-8"></constant>
	<constant name="struts.ui.theme" value="simple"></constant>  
	<constant name="struts.configuration.xml.reload" value="true"></constant>  
	<package name="cn.action" extends="struts-default" namespace="/">
		<!-- 显示列表 -->
		<action name="toList" class="cn.action.StandardsAction" 
			method="toList">
			<result name="success">list.jsp</result>
		</action>
		<!-- 修改 -->
		<action name="toUpdate" class="cn.action.StandardsAction"
			method="toUpdate">
			<result name="success">update.jsp</result>
			<result name="tolist">index.jsp</result>
		</action>
		<!-- 增加 -->
		<action name="toAdd" class="cn.action.StandardsAction"
			method="toAdd">
			<result name="success">add.jsp</result>
			<result name="tolist">index.jsp</result>
		</action>
		<!-- 删除 -->
		<action name="toDelete" class="cn.action.StandardsAction"
			method="toDelete">
		</action>
	</package>
</struts>    

 

index.jsp 页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<!-- 跳转页面 -->
<c:redirect url="toList.action"/>
</body>
</html>

 

list.jsp 页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>标准信息列表</title>
<style type="text/css">  
*{ margin:0; padding:0; }  
body{ font-family:"宋体"; color:#333; font-size:14px; background:#fff;}  
a{ color:#069; text-decoration:underline;}  
a:hover{ color:#f60; text-decoration:underline;}  
h3{ text-align:center; line-height:40px;}  
table{ margin:0 auto; line-height:23px;}  
table tr th{ background:#B8860B;}  
table tr td{ padding:0 8px;}  
table .tdBg td{ background:#999}  
</style>  
<script type="text/javascript">
	function $(id) {
		return document.getElementById(id);
	}
	//全选  
	function checkAll(val) {
		var arr = document.getElementsByName("stdIds");
		//循环全选和非全选  
		for ( var i = 0; i < arr.length; i++) {
			arr[i].checked = val;
		}
	}
	//删除多行  
	function delRow() {
		var stdIds = document.getElementsByName("stdIds");
		var count = 0;
		var arr = new Array();
		for ( var i = 0; i < stdIds.length; i++) {
			if (stdIds[i].checked == true) {
				arr[count] = i;
				count++;
			}
		}
		if (count == 0) {
			alert("请选择你要删除的行");
		} else {
			if (confirm("你确定要删除第" + arr + "条吗?")) {
				for ( var i = 0; i < arr.length; i++) {
					//调用 ajax
					ajaxDelete(stdIds[arr[i]].value);
				}
				alert("删除成功");
				window.location.href="toList.action";
			}
		}
	}
	//删除 ajax
	function ajaxDelete(stdIdsVal) {
		var xmlHttp = new XMLHttpRequest();
		var url = "toDelete.action?stdIds=" + escape(stdIdsVal);
		xmlHttp.open("GET", url);//设置一个请求  
		xmlHttp.onreadystatechange = function() { //设置请求完成之后处理的回调函数    
			if (xmlHttp.readyState == 4) {//数据返回完毕    
				if (xmlHttp.status == 200) {//HTTP操作正常    
					var text = xmlHttp.responseText;//接收返回的内容    
					if (text != null && text != "") {
						alert(text);
					}
				}
			}
		};
		xmlHttp.send(null);//发送请求,不传递任何参数    
	}
</script>
</head>
<body>
	<div style=" border: 1px solid #333; padding: 8px; width: 780px; margin: 0 auto;">
		<h3>标准信息列表</h3>
		<form action="toList.action" method="post">
			<table border="1" align="center">
				<tr>
					<td colspan="7"><input type="text" name="stdNum"> <input
						type="submit" value="提交检索"> <input type="button"
						onclick="window.open('toAdd.action')" value="新增标准"> <input
						type="button" onclick="delRow();" value="删除标准"></td>
				</tr>
				<tr>
					<th><input type="checkbox" onclick="checkAll(this.checked)">
					</th>
					<th>标准号</th>
					<th>中文名称</th>
					<th>版本</th>
					<th>发布日期</th>
					<th>实施日期</th>
					<th>操作</th>
				</tr>
				<s:iterator value="Standards" status="st">
					<tr <s:if test="#st.even">class="tdBg"</s:if>>
						<td><input type="checkbox" name="stdIds"
							value="<s:property value='stdId'/>" /></td>
						<td><a
							href="toUpdate.action?stdId=<s:property value='stdId'/>"><s:property
									value="stdId"></s:property>
						</a>
						</td>
						<td><s:property value="stdNum"></s:property>
						</td>
						<td><s:property value="zhname"></s:property>
						</td>
						<td><s:date name="releaseDate" format="yyyy-MM-dd"></s:date>
						</td>
						<td><s:date name="implDate" format="yyyy-MM-dd"></s:date>
						</td>
						<td><a
							href="toUpdate.action?stdId=<s:property value='stdId'/>">修改</a>
						</td>
					</tr>
				</s:iterator>
				<tr>
					<td colspan="7"><a href="toList.action?pageIndex=1">首页</a>| <a
						href="toList.action?pageIndex=<s:property value='pageIndex-1'/>">上一页</a>|
						<a
						href="toList.action?pageIndex=<s:property value='pageIndex+1'/>">下一页</a>|
						<a href="toList.action?pageIndex=<s:property value='pagecount'/>">末页</a>
						&nbsp;&nbsp; 第<s:property value="pageIndex" />页/共<s:property
							value="pagecount" />页</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>

 

效果图:
SSH action+struts.xml+jsp_第1张图片
 

update.jsp 页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>修改标准信息</title>
<style type="text/css">  
*{ margin:0; padding:0; }  
body{ font-family:"宋体"; color:#333; font-size:14px; background:#fff;}  
h3{ text-align:center; line-height:40px;}  
table{ margin:0 auto; line-height:23px;}  
table input[type="text"]{ border:1px solid #333; height:18px; line-height:18px; padding-left:6px;}  
table select{ border:1px solid #333; }  
</style>  
</head>
<body>
	<div style=" padding: 8px; border: 1px solid #333; width: 480px; margin: 0 auto;">
		<form action="toUpdate.action" method="post">
			<h3>修改标准信息</h3>
			<table>
				<tr>
					<td>*标准号:<input type="hidden"
						value="<s:property value='standard.stdId'/>" name="standard.stdId">
					</td>
					<td><input type="text"
						value="<s:property value='standard.stdNum'/>"
						name="standard.stdNum">
					</td>
				</tr>
				<tr>
					<td>*中文名称:</td>
					<td><input type="text"
						value="<s:property value='standard.zhname'/>"
						name="standard.zhname">
					</td>
				</tr>
				<tr>
					<td>*版本:</td>
					<td><input type="text"
						value="<s:property value='standard.stdVersion'/>"
						name="standard.stdVersion">
					</td>
				</tr>
				<tr>
					<td>*关键字/词:</td>
					<td><input type="text"
						value="<s:property value='standard.keys'/>" name="standard.keys">
					</td>
				</tr>
				<tr>
					<td>*发布日期(yyyy-MM-dd):</td>
					<td><input type="text"
						value="<s:date name='standard.releaseDate' format='yyyy-MM-dd'></s:date>"
						name="standard.releaseDate">
					</td>
				</tr>
				<tr>
					<td>*实施日期(yyyy-MM-dd):</td>
					<td><input type="text"
						value="<s:date name='standard.implDate' format='yyyy-MM-dd'></s:date>"
						name="standard.implDate">
					</td>
				</tr>
				<tr>
					<td>*附件:</td>
					<td><input type="text"
						value="<s:property value='standard.packagePath'/>"
						name="standard.packagePath">
					</td>
				</tr>
				<tr>
					<td colspan="2"><input type="submit" value="保存">&nbsp;<input
						type="button" value="取消">
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>

 

效果图:
SSH action+struts.xml+jsp_第2张图片
 

add.jsp 页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>新增标准信息</title>
<style type="text/css">  
*{ margin:0; padding:0; }  
body{ font-family:"宋体"; color:#333; font-size:14px; background:#fff;}  
h3{ text-align:center; line-height:40px;}  
table{ margin:0 auto; line-height:23px;}  
table input[type="text"]{ border:1px solid #333; height:18px; line-height:18px; padding-left:6px;}  
table select{ border:1px solid #333; }  
</style>  
</head>
<body>
	<div style=" padding: 8px; border: 1px solid #333; width: 480px; margin: 0 auto;">
		<form action="toAdd.action" method="post">
			<h3>新增标准信息</h3>
			<table>
				<tr>
					<td>*标准号:</td>
					<td><input type="text" name="standard.stdNum">
					</td>
				</tr>
				<tr>
					<td>*中文名称:</td>
					<td><input type="text" name="standard.zhname">
					</td>
				</tr>
				<tr>
					<td>*版本:</td>
					<td><input type="text" name="standard.stdVersion">
					</td>
				</tr>
				<tr>
					<td>*关键字/词:</td>
					<td><input type="text" name="standard.keys">
					</td>
				</tr>
				<tr>
					<td>*发布日期(yyyy-MM-dd):</td>
					<td><input type="text" name="standard.releaseDate">
					</td>
				</tr>
				<tr>
					<td>*实施日期(yyyy-MM-dd):</td>
					<td><input type="text" name="standard.implDate">
					</td>
				</tr>
				<tr>
					<td>*附件:</td>
					<td><input type="text" name="standard.packagePath">
					</td>
				</tr>
				<tr>
					<td colspan="2"><input type="submit" value="保存">&nbsp;<input
						type="button" value="取消">
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>

 

效果图:
SSH action+struts.xml+jsp_第3张图片
 

 

 

 

你可能感兴趣的:(struts.xml)