S2SH+DWR实现的增删改查实例

一、介绍

 

主要技术:

    (1)s2sh之间的整合

    (2)dwr和s2sh整合(验证姓名是否相同)

    (3)强大的jquery validator验证框架验证表单

    (4)分页bean的编写

    (5)过滤器,拦截器的编写

    (6)泛型dao的编写

二、实例
1、数据库脚本
本例是采用mysql数据库,脚本如下:
CREATE DATABASE /*!32312 IF NOT EXISTS*/`practice` /*!40100 DEFAULT CHARACTER SET gbk */; USE `practice`; DROP TABLE IF EXISTS `student`; CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, `age` int(11) DEFAULT NULL, `sex` varchar(1) DEFAULT NULL, `address` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=gbk; insert into `student`(`id`,`name`,`age`,`sex`,`address`) values (2,'张民生',24,'男','江苏淮安市'),(26,'李军',41,'男','江苏南京'),(27,'李丽丽',25,'女','浙江杭州'),(28,'周塔利',36,'男','黑龙江'),(29,'李丽',24,'女','湖北'),(30,'凯萨',21,'女','新疆乌鲁木齐'); DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) DEFAULT NULL, `password` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk; insert into `users`(`id`,`username`,`password`) values (1,'admin','123456');  
2、表现层
(1)login.jsp(登录页面)
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%> <%@taglib prefix="s" uri="/struts-tags"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> // --> // --> // -->

 
(2)logout.jsp(退出页面)
<%@ page language="java" pageEncoding="ISO-8859-1"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> My JSP 'logout.jsp' starting page <% response.setHeader("Pragma","No-cache"); response.setHeader("Cache-Control","no-cache"); response.setHeader("Cache-Control", "no-store"); response.setDateHeader("Expires",0); if(session!=null) session.invalidate(); %>  
(3)exception(错误异常显示页面)
<%@ page contentType="text/html; charset=gbk"%> <%@taglib prefix="s" uri="/struts-tags"%> <s:text name="exception_title"/>