Standard实体类

package entity;


import java.util.Date;


public class Standard implements java.io.Serializable {

private Integer id;
private String stdNum;
private String zhname;
private String version;
private String keys;
private Date releaseDate;
private Date implDate;
private String packagePath;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getStdNum() {
return stdNum;
}
public void setStdNum(String stdNum) {
this.stdNum = stdNum;
}
public String getZhname() {
return zhname;
}
public void setZhname(String zhname) {
this.zhname = zhname;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getKeys() {
return keys;
}
public void setKeys(String keys) {
this.keys = keys;
}
public Date getReleaseDate() {
return releaseDate;
}
public void setReleaseDate(Date releaseDate) {
this.releaseDate = releaseDate;
}
public Date getImplDate() {
return implDate;
}
public void setImplDate(Date implDate) {
this.implDate = implDate;
}
public String getPackagePath() {
return packagePath;
}
public void setPackagePath(String packagePath) {
this.packagePath = packagePath;
}
public Standard(Integer id, String stdNum, String zhname, String version,
String keys, Date releaseDate, Date implDate, String packagePath) {
super();
this.id = id;
this.stdNum = stdNum;
this.zhname = zhname;
this.version = version;
this.keys = keys;
this.releaseDate = releaseDate;
this.implDate = implDate;
this.packagePath = packagePath;
}
public Standard() {
super();
// TODO Auto-generated constructor stub
}



}

Standard.hbm.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="entity.Standard" table="STANDARD" schema="SYSTEM">
<id name="id" >
<column name="ID" precision="10" scale="0" />
<generator class="sequence">
<param name="sequence">seq_standard</param>
</generator>
</id>
<property name="stdNum">
<column name="STD_NUM" length="50" unique="true" />
</property>
<property name="zhname">
<column name="ZHNAME" length="40" />
</property>
<property name="version">
<column name="VERSION" length="10" />
</property>
<property name="keys">
<column name="KEYS" length="50" />
</property>
<property name="releaseDate">
<column name="RELEASE_DATE" length="7" />
</property>
<property name="implDate">
<column name="IMPL_DATE" length="7" />
</property>
<property name="packagePath">
<column name="PACKAGE_PATH" length="100" />
</property>
</class>
</hibernate-mapping>



StandardDao

package dao;

import java.util.List;

import entity.Standard;

public interface StandardDao {
/**
* 查询指定条件的记录数
*/
public int getCountsByTJ(String searchKey);

/**
* 查询指定条件的记录集合
*/
public List<Standard> getStandardsByTJAndPage(int pageIdex, int pageSize,
String searchKey);

/**
* 查询指定标准号的记录数
*/
public int getCountsByStdNum(String stdNum);

/**
* 增加标准信息
*/
public int addStandard(Standard tandard);


/**
* 根据id删除标准信息
*/
public int deleteStandard(List<Integer>idList);

/**
* 根据信息编号查找指定标准信息
*/
public Standard findById(int id);

/**
* 根据编号修改标准信息
*/
public int updateStandard(Standard standard);

}


StandardDaoImpl

package dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import dao.StandardDao;
import entity.Standard;

public class StandardDaoImpl extends HibernateDaoSupport implements StandardDao {

// 查询指定条件的记录数
public int getCountsByTJ(String searchKey) {
String hql = "select count(*) from Standard";
if (null != searchKey) {
hql += " where stdNum like '%" + searchKey + "%' or zhname like '%"
+ searchKey + "%'";
}
Query query = getSession().createQuery(hql);
return ((Long) query.uniqueResult()).intValue();
}

// 查询指定条件的记录集合
public List<Standard> getStandardsByTJAndPage(int pageIndex, int pageSize,
String searchKey) { // 注意这里是有空格的,hql语句的查询都是对象和属性
String hql = "from Standard";
if (null != searchKey) {
hql += " where stdNum like '%" + searchKey + "%' or zhname like '%"
+ searchKey + "%'";
}
hql += " order by stdNum";
Query query = getSession().createQuery(hql);
// 设置分页
query.setFirstResult((pageIndex - 1) * pageSize);
query.setMaxResults(pageSize);
return query.list();
}

// 查询指定标准号的记录数,增加时用来验证是否有重复的时候用
public int getCountsByStdNum(String stdNum) {
String hql = "select count(*) from Standard where stdNum = '" + stdNum
+ "'";
Query query = getSession().createQuery(hql);
return ((Long) query.uniqueResult()).intValue();
}

// 增加标准信息
public int addStandard(Standard standard) {
try {
getHibernateTemplate().save(standard);
return 1;
} catch (DataAccessException e) {
e.printStackTrace();
return 0;
}
}

// 删除标准信息
@Override
public int deleteStandard(List<Integer> idList) {
try {
for (Integer ids : idList) {
Standard s = getHibernateTemplate().load(Standard.class, ids);
getHibernateTemplate().delete(s);
}
return 1;
} catch (DataAccessException e) {
e.printStackTrace();
}
return 0;
}

// 根据查找标准信息
@Override
public Standard findById(int id) {
return getHibernateTemplate().get(Standard.class, id);

}

//根据id修改标准信息
@Override
public int updateStandard(Standard standard) {
try {
Standard s = getHibernateTemplate().load(Standard.class, standard.getId());
s.setImplDate(standard.getImplDate());
s.setKeys(standard.getKeys());
s.setPackagePath(standard.getPackagePath());
s.setReleaseDate(standard.getReleaseDate());
s.setVersion(standard.getVersion());
s.setZhname(standard.getZhname());

getHibernateTemplate().update(s);
return 1;
} catch (DataAccessException e) {
e.printStackTrace();
return 0;
}
}
}


StandardService

package service;

import java.util.List;
import java.util.Map;

import entity.Standard;

public interface StandardService {

/*
* 带有条件的分页查询
*/
public Map<String, Object> findStandardsByTjAndPage(int pageIndex,
int pageSize, String searchKey);

/*
* 验证标准号是否存在
*/
public boolean checkStdNum(String stdNum);

/*
* 新增标准信息
*/
public boolean addStandard(Standard standard);


/*
* 删除标准信息
*/
public boolean deleteStandard(List<Integer> idList);


/*
* 根据标准信息id查找信息
*/
public Standard findStandardById(int id);

/*
* 修改标准信息
*/
public boolean updateStandard(Standard standard);

}

StandardServiceImpl

package service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import dao.StandardDao;
import entity.Standard;
import service.StandardService;

public class StandardServiceImpl implements StandardService {
// 定义Dao依赖对象
private StandardDao standardDao;

/*
* 提供Dao注入方法
*/
public void setStandardDao(StandardDao standardDao) {
this.standardDao = standardDao;
}

@Override
// 带条件的分页查询
public Map<String, Object> findStandardsByTjAndPage(int pageIndex,
int pageSize, String searchKey) {
// 计算总页数
int counts = standardDao.getCountsByTJ(searchKey);
int totalPages = 1;
if (counts > 0) {
totalPages = counts % pageSize == 0 ? counts / pageSize : counts
/ pageSize + 1;
}
// 判断请求页数是否超出范围
if (pageIndex < 1) {
pageIndex = 1;
}
if (pageIndex > totalPages) {
pageIndex = totalPages;
}
// 查询指定页数的数据
List<Standard> standardList = standardDao.getStandardsByTJAndPage(
pageIndex, pageSize, searchKey);
Map<String, Object> map = new HashMap<String, Object>();
map.put("pageIndex", pageIndex);
map.put("totalPages", totalPages);
map.put("standardList", standardList);
return map;
}

// 检验标准号是否存在
@Override
public boolean checkStdNum(String stdNum) {
if (standardDao.getCountsByStdNum(stdNum) > 0)
return false;
return true;
}

// 新增标准信息
@Override
public boolean addStandard(Standard standard) {
if (standardDao.addStandard(standard) > 0)
return true;
return false;
}
/*
* 批量删除标准信息
*/
public boolean deleteStandard(List<Integer> idList) {
if(standardDao.deleteStandard(idList) > 0)
return true;
return false;
}


/*
* 根据id查找标准信息
*
*/
@Override
public Standard findStandardById(int id) {
return standardDao.findById(id);
}

/*
* 根据id修改标准信息
* @see service.StandardService#updateStandard(entity.Standard)
*/
@Override
/*
* 修改标准信息
*/
public boolean updateStandard(Standard standard) {
if(standardDao.updateStandard(standard) > 0)
return true;
return false;
}




}

StandardAction

package action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import service.StandardService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import entity.Standard;

public class StandardAction extends ActionSupport {

// 定义依赖的Service对象
private StandardService standardService;

// 查询方法所需参数
private String searchKey;
private Integer pageIndex;//PageIndex不要给get方法

// ajax验证标准号所需参数
private String stdNum;

// 增加标准信息记录的参数
private Standard standard;
// 带有文件上传的增加
private File attchPkg;
private String attchPkgContentType;
private String attchPkgFileName;

// 文件上传路径,动态参数
private String savePath;

// 动态结果参数
private String nextDispose;
// 分页时,每页显示条数 从Action中获取param
private Integer pageSize;

/*
* 查询方法 (兼容三中提交请求:1.主页请求,2.检索请求,3.翻页请求)
*/
public String showAll() {
if (null == pageIndex)
pageIndex = 1;
Map<String, Object> session = ActionContext.getContext().getSession();
if (null == searchKey) {
searchKey = (String) session.get("searchKey");
}
Map<String, Object> map = standardService.findStandardsByTjAndPage(
pageIndex, pageSize, searchKey);
session.put("pageIndex", map.get("pageIndex"));
session.put("totalPages", map.get("totalPages"));
session.put("standardList", map.get("standardList"));
// 存储本次查询条件用于下次分页时获取条件
session.put("searchKey", searchKey);
nextDispose = "showAll.jsp";
return SUCCESS;
}

/*
* 验证标准号是否重复(Ajax处理)
*/
public void checkStdNum() {
try {
PrintWriter out = ServletActionContext.getResponse().getWriter();
if (standardService.checkStdNum(stdNum)) {
out.print("true");
} else {
out.print("false");
}
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}

}

/*
* 增加标准信息方法
*/
public String add() {
try {
// 处理上传文件
String absSavePath = ServletActionContext.getServletContext().getRealPath(savePath);
FileInputStream fis = new FileInputStream(attchPkg);
FileOutputStream fos = new FileOutputStream(absSavePath + File.separator + attchPkgFileName);
byte[] b = new byte[fis.available()];
fis.read(b);
fos.write(b);
fis.close();
fos.flush();
fos.close();

// 上传成功后,记录上传路径
standard.setPackagePath(savePath+"/"+attchPkgFileName);
// 调用增加业务方法
if(standardService.addStandard(standard)){
nextDispose = "showAllStandard";
return "nextAction";
} else {
nextDispose = "addStandard.jsp";
}

} catch (Exception e) {
nextDispose = "addStandard.jsp";
e.printStackTrace();
}
return SUCCESS;
}

public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}

public String getNextDispose() {
return nextDispose;
}

public void setPageIndex(Integer pageIndex) {
this.pageIndex = pageIndex;
}

public String getSearchKey() {
return searchKey;
}

public void setSearchKey(String searchKey) {
this.searchKey = searchKey;
}

public void setStdNum(String stdNum) {
this.stdNum = stdNum;
}

public Standard getStandard() {
return standard;
}

public void setStandard(Standard standard) {
this.standard = standard;
}

public File getAttchPkg() {
return attchPkg;
}

public void setAttchPkg(File attchPkg) {
this.attchPkg = attchPkg;
}

public String getAttchPkgContentType() {
return attchPkgContentType;
}

public void setAttchPkgContentType(String attchPkgContentType) {
this.attchPkgContentType = attchPkgContentType;
}

public String getAttchPkgFileName() {
return attchPkgFileName;
}

public void setAttchPkgFileName(String attchPkgFileName) {
this.attchPkgFileName = attchPkgFileName;
}

public void setSavePath(String savePath) {
this.savePath = savePath;
}

/*
* Service对象注入方法
*/
public void setStandardService(StandardService standardService) {
this.standardService = standardService;
}

}


DeleteAction

package action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import service.StandardService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DeleteAction extends ActionSupport {

private String nextDispose;
// 批量删除标准信息记录的参数
private List<Integer> ids;// 这个集合类型的int类型的,jsp页面传过来的ids=1&ids=2&ids=3,到这里就变成了
// 1,2,3
// 定义依赖的Service对象
private StandardService standardService;


public String getNextDispose() {
return nextDispose;
}


public void setNextDispose(String nextDispose) {
this.nextDispose = nextDispose;
}


public List<Integer> getIds() {
return ids;
}


public void setIds(List<Integer> ids) {
this.ids = ids;
}


public StandardService getStandardService() {
return standardService;
}


public void setStandardService(StandardService standardService) {
this.standardService = standardService;
}


public String delete() {
Map<String, Object> request = (Map<String, Object>) ActionContext
.getContext().get("request");
if (standardService.deleteStandard(ids)) {
request.put("deleteFlag", "success");
} else {
request.put("deleteFlag", "error");
}
nextDispose = "alertMeg.jsp";
return SUCCESS;

}
}

UpdateAction

package action;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;

import javax.imageio.stream.FileImageInputStream;

import org.apache.struts2.ServletActionContext;

import service.StandardService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import entity.Standard;

public class UpdateAction extends ActionSupport {
private Standard standard;
private String nextDispose;
private StandardService service;

// 带有文件上传的增加
private File attchPkg;
private String attchPkgContentType;
private String attchPkgFileName;
// 文件上传路径,动态参数
private String savePath;

public File getAttchPkg() {
return attchPkg;
}

public void setAttchPkg(File attchPkg) {
this.attchPkg = attchPkg;
}

public String getAttchPkgContentType() {
return attchPkgContentType;
}

public void setAttchPkgContentType(String attchPkgContentType) {
this.attchPkgContentType = attchPkgContentType;
}

public String getAttchPkgFileName() {
return attchPkgFileName;
}

public void setAttchPkgFileName(String attchPkgFileName) {
this.attchPkgFileName = attchPkgFileName;
}

public String getSavePath() {
return savePath;
}

public void setSavePath(String savePath) {
this.savePath = savePath;
}

public UpdateAction(StandardService service) {// 这个service的构造方法要写。否则调用services的方法会报错
super();
this.service = service;
}

public StandardService getService() {
return service;
}

public void setService(StandardService service) {
this.service = service;
}

public Standard getStandard() {
return standard;
}

public void setStandard(Standard standard) {
this.standard = standard;
}

public String getNextDispose() {
return nextDispose;
}

public void setNextDispose(String nextDispose) {
this.nextDispose = nextDispose;
}

/*
* 根据编号查询指定待修改标准信息
*/
public String findById() {
standard = service.findStandardById(standard.getId());// service的构造方法要写,否则会报空指针
nextDispose = "updateStandard.jsp";
return SUCCESS;
}

/*
* 根据编号修改信息
*/
public String update() {
// 如果没有现在的附件,则默认使用原有附件
if (attchPkg != null){
// 有附件
// 处理上传文件
try {
String absSavePath = ServletActionContext.getServletContext()
.getRealPath(savePath);
System.out.println(absSavePath);
FileInputStream fis = new FileInputStream(attchPkg);
FileOutputStream fos = new FileOutputStream(absSavePath
+ File.separator + attchPkgFileName);
byte[] b = new byte[fis.available()];
fis.read(b);
fos.write(b);
fos.flush();
fos.close();
// 上传成功后,记录上传路径
standard.setPackagePath(savePath + "/" + attchPkgFileName);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

} else {
// 无附件,则使用原有附件
Standard s = service.findStandardById(standard.getId());
standard.setPackagePath(s.getPackagePath());
}
Map<String, Object> request = (Map<String, Object>) ActionContext
.getContext().get("request");
// 修改
if (service.updateStandard(standard)) {
request.put("updateFlag", "success");
} else {
request.put("updateFlag", "error");
}
nextDispose = "alertMeg.jsp";
return SUCCESS;
}

}

DeleteAction

package action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import service.StandardService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DeleteAction extends ActionSupport {

private String nextDispose;
// 批量删除标准信息记录的参数
private List<Integer> ids;// 这个集合类型的int类型的,jsp页面传过来的ids=1&ids=2&ids=3,到这里就变成了
// 1,2,3
// 定义依赖的Service对象
private StandardService standardService;


public String getNextDispose() {
return nextDispose;
}


public void setNextDispose(String nextDispose) {
this.nextDispose = nextDispose;
}


public List<Integer> getIds() {
return ids;
}


public void setIds(List<Integer> ids) {
this.ids = ids;
}


public StandardService getStandardService() {
return standardService;
}


public void setStandardService(StandardService standardService) {
this.standardService = standardService;
}


public String delete() {
Map<String, Object> request = (Map<String, Object>) ActionContext
.getContext().get("request");
if (standardService.deleteStandard(ids)) {
request.put("deleteFlag", "success");
} else {
request.put("deleteFlag", "error");
}
nextDispose = "alertMeg.jsp";
return SUCCESS;

}
}

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!--配置数据源 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="system"></property>
<property name="password" value="password"></property>
</bean>

<!--dataSource就是数据库的配置,把数据源注入session工厂 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property><!--配置映射文件 -->
<property name="mappingResources">
<list>
<value>entity/Standard.hbm.xml</value></list>
</property>
</bean>

<!-- 配置DAO组件 注入session工厂--><!-- 这里都是impl实现类 -->
<bean id="standardDao" class="dao.impl.StandardDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 配置SERVICE组件 --><!-- 这里都是impl实现类 ,这个类里面有DAO属性-->
<bean id="standardService" class="service.impl.StandardServiceImpl">
<property name="standardDao" ref="standardDao" />
</bean>

<!-- 配置spring声明式事务管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" read-only="true"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut expression="execution(* service.impl.*.*(..))" id="servicept"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="servicept"/>
</aop:config>


</beans>

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>

<package name="default" namespace="/" extends="struts-default">
<action name="*Standard" class="action.StandardAction" method="{1}">
<param name="pageSize">3</param>
<param name="savePath">upload</param>
<result>${nextDispose}</result>
<result name="nextAction" type="redirectAction">${nextDispose}</result>
</action>

<action name="checkStdNum" class="action.StandardAction"
method="checkStdNum" />
<!--删除 -->
<action name="deleteStandard" class="action.DeleteAction"
method="delete">
<result>${nextDispose}</result>
</action>
<!-- 显示修改信息 -->
<action name="findById" class="action.UpdateAction" method="findById">
<result>${nextDispose}</result>
</action>
<!--修改信息 -->
<action name="update" class="action.UpdateAction" method="update">
<param name="savePath">upload</param>
<result>${nextDispose}</result>
</action>
<!--下载信息 -->
<action name="download" class="action.DownloadAction" method="download">
<result name="download" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${downFileName}"</param>
</result>
</action>
</package>

</struts>


addStandard.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>增加标准信息页面</title>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
// ajax验证标准号是否重复的标志位
var stdNumFlag = false;
$("form[name=addForm]").submit(function(){

// 验证*号(非空)
var stdNum = $("input[name$=stdNum]").val();
if(stdNum == ""){
alert("标准号不能为空!");
return false;
}
var attchPkg = $("input[name=attchPkg]").val();
if(attchPkg == ""){
alert("附件不能为空!");
return false;
}

// 使用正则表达式验证日期格式
var reg = /^\d{4}-\d{2}-\d{2}$/;
var releaseDate = $("input[name$=releaseDate]").val();
if("" != releaseDate) {
if(!reg.test(releaseDate)){
alert("发布日期格式错误!");
return false;
}
}

// 当所有静态验证均通过时,验证ajax的标志位
if(!stdNumFlag){
alert("标准号重复!");
return false;
}

// 全部通过
return true;
});

// ajax验证标准号
$("input[name$=stdNum]").blur(function(){
var stdNum = $(this).val();
if("" == stdNum) return;
$.ajax({
url:"checkStdNum.action",
type:"post",
data:{"stdNum":stdNum},
dataType:"text",
success:function(result){
if("true"==result){
stdNumFlag = true;
} else {
stdNumFlag = false;
}
}
});
});

});
</script>
</head>

<body>
<form name="addForm" action="addStandard.action" method="post" enctype="multipart/form-data">
<table align="center" border="1" width="60%">
<caption><h2>增加标准信息</h2></caption>
<tr>
<td align="right">* 标准号:</td>
<td><input type="text" name="standard.stdNum" /></td>
</tr>
<tr>
<td align="right">* 中文名称:</td>
<td><input type="text" name="standard.zhname" /></td>
</tr>
<tr>
<td align="right">* 版本:</td>
<td><input type="text" name="standard.version" /></td>
</tr>
<tr>
<td align="right">* 关键字/词:</td>
<td><input type="text" name="standard.keys" /></td>
</tr>
<tr>
<td align="right">发布日期(yyyy-MM-dd):</td>
<td><input type="text" name="standard.releaseDate" /></td>
</tr>
<tr>
<td align="right">实施日期(yyyy-MM-dd):</td>
<td><input type="text" name="standard.implDate" /></td>
</tr>
<tr>
<td align="right">* 附件:</td>
<td><input type="file" name="attchPkg" /></td>
</tr>
<tr>
<th colspan="2">
<input type="submit" value="保存" />

<input type="button" value="取消" οnclick="history.back();" />
</th>
</tr>
</table>
</form>
</body>
</html>

alterMeg.jsp


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--删除提示 --%>
<c:if test="${deleteFlag != null }">
<script>
<c:if test="${deleteFlag == 'success' }">
alert('删除成功!');
</c:if>
<c:if test="${deleteFlag == 'error' }">
alert('删除失败!');
</c:if>
location='showAllStandard.action';
</script>
</c:if>
<%--修改提示 --%>
<c:if test="${updateFlag != null }">
<script>
<c:if test="${updateFlag == 'success' }">
alert('修改成功!');
location='showAllStandard.action';
</c:if>
<c:if test="${updateFlag == 'error' }">
alert('修改失败!');
location='findById.action?standard.id=${standard.id }';
</c:if>
</script>
</c:if>


index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%

response.sendRedirect("showAllStandard.action");

%>


showAll.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>标准信息列表</title>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function() {
$("#add").click(function() {
location = "addStandard.jsp";
});

//复选框全选,删除按钮
$("#all").click(function() {
var $sidList = $(".sid");
$.each($sidList, function() {
this.checked = $("#all")[0].checked;
});
});

$(".sid").click(function() {
var $sidList = $(".sid");
var flag = true;
$.each($sidList, function() {
if (!this.checked) {
flag = false;
}
});
$("#all")[0].checked = flag;
});

//实现删除功能的提交
$("#delete").click(function() {
var str = "";
$(".sid").each(function() {
if (this.checked) {
str += "&ids=" + this.value;
}
});
str = str.substring(1, str.length);
if (str == "") {
alert("请选择你要删除的信息!!");
} else {
alert(str);
if (confirm("确认要删除吗??")) {
location = "deleteStandard.action?" + str; /* 这里是传递是:deleteStandard.action?ids=1&ids=2&ids=3*/
} /* 到接收的那里,以为是int类型的集合,所以接收的都是int的值。 */
}
});
});
</script>
</head>
<body>
<table align="center" border="1" width="90%">
<caption>
<h2>标准信息列表</h2>
</caption>
<tr align="right">
<td colspan="7">
<form action="showAllStandard.action" method="post"
style="display: inline;">
<input type="text" name="searchKey" value="${searchKey}" /> <input
type="submit" value="提交检索" /> <input type="button" value="新增标准"
id="add" /> <input type="button" value="删除标准" id="delete" />
</form></td>
</tr>
<tr style="background-color: gray;">
<th><input type="checkbox" id="all" />
</th>
<th>标准号</th>
<th>中文名称</th>
<th>版本</th>
<th>发布日期</th>
<th>实施日期</th>
<th>操作</th>
</tr>
<c:forEach var="s" items="${standardList }" varStatus="status">
<tr
<c:if test="${status.index % 2 == 1 }">style="background-color: green;"</c:if>>
<th><input type="checkbox" class="sid" value="${s.id}" />
</th>
<th>${s.stdNum }</th>
<td>${s.zhname }</td>
<th>${s.version }</th>
<th><fmt:formatDate value="${s.releaseDate }"
pattern="yyyy-MM-dd" /></th>
<th><fmt:formatDate value="${s.implDate }" pattern="yyyy-MM-dd" />
</th>
<th><a href="download.action?downPkg=${s.packagePath }">下载</a> <a href="findById.action?standard.id=${s.id}">修改</a></th>
</tr>
</c:forEach>
<tr align="right">
<td colspan="7"><a href="showAllStandard.action?pageIndex=1">首页</a>|
<a href="showAllStandard.action?pageIndex=${pageIndex - 1 }">上一页</a>|
<a href="showAllStandard.action?pageIndex=${pageIndex + 1 }">下一页</a>|
<a href="showAllStandard.action?pageIndex=${totalPages }">末页</a>
第${pageIndex }页/共${totalPages }页</td>
</tr>
</table>
</body>
</html>

updateStandard.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>修改标准信息页面</title>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
$("form[name=updateForm]").submit(function(){

// 验证*号(非空)
var stdNum = $("input[name$=stdNum]").val();
if(stdNum == ""){
alert("标准号不能为空!");
return false;
}

// 使用正则表达式验证日期格式
var reg = /^\d{4}-\d{2}-\d{2}$/;
var releaseDate = $("input[name$=releaseDate]").val();
if("" != releaseDate) {
if(!reg.test(releaseDate)){
alert("发布日期格式错误!");
return false;
}
}

// 全部通过
return true;
});

});
</script>
</head>

<body>
<form name="updateForm" action="update.action" method="post" enctype="multipart/form-data">
<input type="hidden" name="standard.id" value="${standard.id }" />
<table align="center" border="1" width="60%">
<caption><h2>修改标准信息</h2></caption>
<tr>
<td align="right">* 标准号:</td>
<td><input type="text" name="standard.stdNum" value="${standard.stdNum }" readonly="readonly" /></td>
</tr>
<tr>
<td align="right">* 中文名称:</td>
<td><input type="text" name="standard.zhname" value="${standard.zhname }" /></td>
</tr>
<tr>
<td align="right">* 版本:</td>
<td><input type="text" name="standard.version" value="${standard.version }" /></td>
</tr>
<tr>
<td align="right">* 关键字/词:</td>
<td><input type="text" name="standard.keys" value="${standard.keys }" /></td>
</tr>
<tr>
<td align="right">发布日期(yyyy-MM-dd):</td>
<td><input type="text" name="standard.releaseDate" value="<fmt:formatDate value="${standard.releaseDate }" pattern="yyyy-MM-dd"/>" /></td>
</tr>
<tr>
<td align="right">实施日期(yyyy-MM-dd):</td>
<td><input type="text" name="standard.implDate" value="<fmt:formatDate value="${standard.implDate }" pattern="yyyy-MM-dd"/>" /></td>
</tr>
<tr>
<td align="right">* 附件:</td>
<td><input type="file" name="attchPkg" /></td>
</tr>
<tr>
<th colspan="2">
<input type="submit" value="保存" />

<input type="button" value="取消" οnclick="history.back();" />
</th>
</tr>
</table>
</form>
</body>
</html>