使用SSM框架 实现登录、注册、分页和增删改操作

1.

applicaltion.xml

使用SSM框架 实现登录、注册、分页和增删改操作

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
        
        <!-- 配置数据源 -->
        <import resource="spring-db.xml"/>
        <!-- 事务管理器 -->
         <import resource="spring-tx.xml"/>
        <!-- Mapper代理开发(基于MapperScannerConfigurer) -->
        <import resource="spring-dao.xml"/>
</beans> 

2.

db.properties

使用SSM框架 实现登录、注册、分页和增删改操作

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm_db
jdbc.username=root
jdbc.password=123456
jdbc.minIdle=3
jdbc.maxActive=20
jdbc.initialSize=3
jdbc.maxWait=10000

3.

log4j.properties

使用SSM框架 实现登录、注册、分页和增删改操作

# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.xin=TRACE
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

4.

mybatis-config.xml

使用SSM框架 实现登录、注册、分页和增删改操作

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
 PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
	<!-- 取别名 -->
	<package name="com.xin.po"/>
</typeAliases>
</configuration>

5.

spring-dao.xml

使用SSM框架 实现登录、注册、分页和增删改操作

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
        
        <!-- Mapper代理开发(基于MapperScannerConfigurer) -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        	<property name="basePackage" value="com.xin.dao"></property>
        </bean>
</beans>

6.

spring-db.xml

使用SSM框架 实现登录、注册、分页和增删改操作

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
        
        <!-- 读取db.propertis -->
        <context:property-placeholder location="classpath:db.properties"/>
        <!-- 配置数据源 -->
        <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        	<!-- 数据库驱动 -->
        	<property name="driverClassName" value="${jdbc.driver}" />
        	<property name="url" value="${jdbc.url}" />
        	<property name="username" value="${jdbc.username}" />
        	<property name="password" value="${jdbc.password}" />
        	<property name="minIdle" value="${jdbc.minIdle}" />
        	<property name="maxActive" value="${jdbc.maxActive}" />
        	<property name="initialSize" value="${jdbc.initialSize}" />
        	<property name="maxWait" value="${jdbc.maxWait}" />
        </bean>
        <!-- 配置 Mybatis SqlSessionFactory -->
        <bean  class="org.mybatis.spring.SqlSessionFactoryBean">
        	<property name="configLocation" value="classpath:mybatis-config.xml"></property>
        	<property name="dataSource" ref="dataSource"></property>
        	<property name="mapperLocations" value="classpath:com/xin/mapper/*.xml"></property>
        </bean>
</beans>

7.*

spring-tx.xml

![在这里插入图片描述](https://img-blog.csdnimg.cn/20190505211338378.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1dpbnNvbTE=,size_16,color_FFFFFF,t_70)
<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
        
         <!-- 事务管理器 -->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        	<property name="dataSource" ref="dataSource"></property>
        </bean>
        <!-- 开启事务扫描 -->
        <tx:annotation-driven transaction-manager="transactionManager" />
        <!-- 开启扫描 Service对象创建 -->
        <context:component-scan base-package="com.xin"/>
</beans>

8.

springmvc-config.xml

使用SSM框架 实现登录、注册、分页和增删改操作

<?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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
        
        <!-- 配置包扫描,扫描@Controller 注解标注类-->
        <context:component-scan base-package="com.xin.controller"/>
        <!-- 配置注解驱动 基于注解式处理器映射器和处理器适配器 -->
        <mvc:annotation-driven/>
        <!-- 视图解析器 -->
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        	<!-- 设置前缀 -->
        	<property name="prefix" value="/WEB-INF/jsp/"></property>
        	<!-- 设置后缀 -->
        	<property name="suffix" value=".jsp"></property>
        </bean>
</beans>

9.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
   <!-- 配置加载Spring 文件监听器 -->
    <context-param>
    	<param-name>contextConfigLocation</param-name>
    	<param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
    	<listener-class>
    		org.springframework.web.context.ContextLoaderListener
    	</listener-class>
    </listener>
  <servlet>
  <!--SpringMVC 前端控制器 -->
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	<!-- 初始化加载配置文件 -->
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:springmvc-config.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <!-- 配置拦截器 (编码过滤器)设置post提交编码格式 -->
  <filter>
  	<filter-name>encodingFilter</filter-name>
  	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  	<init-param>
  		<param-name>encoding</param-name>
  		<param-value>utf-8</param-value>
  	</init-param>
  	
  </filter>
  <filter-mapping>
  		<filter-name>encodingFilter</filter-name>
  		<url-pattern>/*</url-pattern>
  </filter-mapping>
 
</web-app>

10.User实体类

package com.xin.po;

public class User {
	private Integer user_id;
	private String user_name;
	private String password;
	private Integer user_age;
	public Integer getUser_id() {
		return user_id;
	}
	public void setUser_id(Integer user_id) {
		this.user_id = user_id;
	}
	public String getUser_name() {
		return user_name;
	}
	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public Integer getUser_age() {
		return user_age;
	}
	public void setUser_age(Integer user_age) {
		this.user_age = user_age;
	}
	@Override
	public String toString() {
		return "User [user_id=" + user_id + ", user_name=" + user_name
				+ ", password=" + password + ", user_age=" + user_age + "]";
	}
	
}

11.page实体类

package com.xin.po;

import java.util.List;

public class page<T> {
	private int currPage;//当前页数
    private int pageSize;//每页显示的记录数
    private int totalCount;//总记录数
    private int totalPage;//总页数
    private List<User> lists;//每页的显示的数据
	public int getCurrPage() {
		return currPage;
	}
	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public List<User> getLists() {
		return lists;
	}
	public void setLists(List<User> lists) {
		this.lists = lists;
	}
	@Override
	public String toString() {
		return "page [currPage=" + currPage + ", pageSize=" + pageSize
				+ ", totalCount=" + totalCount + ", totalPage=" + totalPage
				+ ", lists=" + lists + "]";
	}
	
    
}

12.UserDao接口

package com.xin.dao;

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

import com.xin.po.User;
import com.xin.po.page;

public interface UserDao {
	/***
	 * 根据编号查询客户信息
	 * @param id 用户编号
	 * @return 客户信息
	 */
	public List<User> list();//查询所有
	public User get(Integer id);//查询单条
	public User getLogin(User user);//登录页
	public Integer delete(Integer id);// 删除
	public Integer update(User user); // 修改
	public Integer add(User user);// 添加
	// 查询用户记录总数
    public int getUserCount(page p);
    /**
     * 查询用户记录总数
     * @return
     */
    int selectCount();

   //分页操作,调用findByPage limit分页方法
    public List<User> findByPage(HashMap<String,Object> map);
    //page<User> findByPage(int currentPage);
}

13.UserService接口

package com.xin.service;
import java.util.List;

import com.xin.po.User;
import com.xin.po.page;

public interface UserService {
	public List<User> list();//查询所有
	public User get(Integer id);//查询单条
	public Integer delete(Integer id);// 删除
	public Integer update(User user); // 修改
	public Integer add(User user);// 添加
	public User getLogin(User user);//登录页
	public Integer getUserCount(page p);
	 /**
     * 查询用户记录总数
     * @return
     */
    int selectCount();

	//分页操作,调用findByPage limit分页方法
    public  page<User> findByPage(int currentPage);
	//List<User> findByPage(HashMap<String, Object> map);
}

## 14.UserServiceImpl实现接口
package com.xin.service.impl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xin.dao.UserDao;
import com.xin.po.User;
import com.xin.po.page;
import com.xin.service.UserService;
@Service
@Transactional
public class UserServiceImpl implements UserService{
	@Autowired
	private UserDao userDao;
	
	@Override
	public Integer delete(Integer id) {
		// TODO Auto-generated method stub
		return userDao.delete(id);
	}
	@Override
	public Integer update(User user) {
		// TODO Auto-generated method stub
		return userDao.update(user);
	}
	@Override
	public Integer add(User user) {
		// TODO Auto-generated method stub
		return userDao.add(user);
	}
	@Override
	public List<User> list() {
		// TODO Auto-generated method stub
		return userDao.list();
	}
	@Override
	public User get(Integer id) {
		// TODO Auto-generated method stub
		return userDao.get(id);
	}
	@Override
	public User getLogin(User user) {
		// TODO Auto-generated method stub
		return userDao.getLogin(user);
	}
	@Override
	public Integer getUserCount(page p) {
		// TODO Auto-generated method stub
		return userDao.getUserCount(p);
	}
	/*@Override
	public List<User> findByPage(HashMap<String, Object> map) {
		// TODO Auto-generated method stub
		return userDao.findByPage(map);
	}*/
	@Override
	public page<User> findByPage(int currentPage) {
		HashMap<String,Object> map = new HashMap<String,Object>();
		page<User> pageBean = new page<User>();
		
	    //封装当前页数
        pageBean.setCurrPage(currentPage);
        
		//每页显示的数据
		int pageSize=5;
		pageBean.setPageSize(pageSize);
		
		//封装总记录数
		int totalCount = userDao.selectCount();
		pageBean.setTotalCount(totalCount);
		
		//封装总页数
		double tc = totalCount;
        Double num =Math.ceil(tc/pageSize);//向上取整
        pageBean.setTotalPage(num.intValue());
      
		map.put("start",(currentPage-1)*pageSize);
		map.put("size", pageBean.getPageSize());
		//封装每页显示的数据
		List<User> lists = userDao.findByPage(map);
		pageBean.setLists(lists);
		
		return pageBean;
	}
	@Override
	public int selectCount() {
		// TODO Auto-generated method stub
		return userDao.selectCount();
	}
	
}

15.controller控制器

package com.xin.controller;

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

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xin.po.User;
import com.xin.po.page;
import com.xin.service.UserService;
@Controller
@RequestMapping("/user")
public class CustomerController {
	@Autowired
	private UserService userService;
	@RequestMapping("/setlogin")
	public String setFindUserById(){
		return "login";
	}
	//登录页
	@RequestMapping("/getlogin")
	public ModelAndView getLogin(HttpSession session,User user,Model model){
		User u=userService.getLogin(user);
		if(u==null){
			session.setAttribute("msg", "登录失败,请重新登录");
		/*model.addAttribute("msg", );*/
			ModelAndView mav=new ModelAndView("redirect:setlogin");
			return mav;
		}
		if (user.getUser_name()!=null&&user.getPassword()!=null&&user.getUser_name().equals(u.getUser_name())&&user.getPassword().equals(u.getPassword())) {
			model.addAttribute("msg", "登录成功");
			session.setAttribute("msg", user.getUser_name());
			ModelAndView mav=new ModelAndView("redirect:getfind");
			return mav;
		}
		model.addAttribute("msg", "登录失败,请重新登录");
		ModelAndView mav=new ModelAndView("redirect:setlogin");
		return mav;
	
}
//查询所有的页面
@RequestMapping("getfind")
public ModelAndView list(){
	ModelAndView mav = new ModelAndView();
	List<User> list = userService.list();
	mav.addObject("list", list);
	mav.setViewName("main");
	return mav;
}
//删除页面
@RequestMapping("/delete")
public ModelAndView delete(Integer id){
	userService.delete(id);
	ModelAndView mav=new ModelAndView("redirect:getfind");
	return mav;
}

// 单条明细修改跳转到修改页面
	@RequestMapping("/editgo")
	public ModelAndView editgo(Integer id) {
		User user = userService.get(id);
		ModelAndView mav = new ModelAndView("editgo");
		mav.addObject("user", user);
		return mav;
	}
//修改页面
@RequestMapping("/update")
public ModelAndView update(User user){
	userService.update(user);
	ModelAndView mav=new ModelAndView("redirect:getfind");
	return mav;
}
// 添加   跳转 到添加页面
	@RequestMapping("addgo")
	public ModelAndView addgo() {
		ModelAndView mav = new ModelAndView("add");
		return mav;
	}
 
	// 添加数据
	@ResponseBody
	@RequestMapping("toadd")
	public ModelAndView add(User user) {
		userService.add(user);
		ModelAndView mav = new ModelAndView("redirect:getfind");
		return mav;
	}
	@RequestMapping("/main")
	public String  main(@RequestParam(value="currentPage",defaultValue="1",required=false)int currentPage,Model model){
		model.addAttribute("pagemsg", userService.findByPage(currentPage));//回显分页数据
		return "main";
	}

}

16.LoginInterceptor拦截器

package com.xin.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class LoginInterceptor implements HandlerInterceptor{

	@Override
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2) throws Exception {
		String url=arg0.getRequestURI();
		if (url.indexOf("/getlogin")!=0) {
			return true;
		}
		Object name=arg0.getSession().getAttribute("user");
		if (name!=null) {
			return true;
		}
		arg0.setAttribute("msg","登录失败");
		arg0.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(arg0, arg1);
		return false;
	}

}

17.Mapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 
 <mapper namespace="com.xin.dao.UserDao"> 
  <select id="list" parameterType="int" resultType="user">
  	select * from tbl_user
  </select>
  <select id="get" parameterType="int" resultType="user">
  	select * from tbl_user where user_id=#{user_id}
  </select>
   <select id="getLogin" parameterType="user" resultType="user">
  	select * from tbl_user where user_name=#{user_name} and password=#{password}
  </select>
  <delete id="delete" parameterType="int">
  	delete from tbl_user where user_id=#{user_id}
  </delete>
  <update id="update" parameterType="user">
  	update tbl_user set user_name=#{user_name},user_age=#{user_age},password=#{password} where user_id=#{user_id}
  </update>
  <insert id="add" parameterType="user">
  	insert into tbl_user(user_name,user_age,password) values(#{user_name},#{user_age},#{password})
  </insert>
  <select id="selectCount" resultType="int">
		select count(1) from tbl_user
	</select>
	<select id="findByPage" resultMap="baseUser" parameterType="page">
		select * from tbl_user limit #{start},#{size}
	</select>
	<resultMap type="user" id="baseUser">
		<id column="user_id" property="user_id" />
		<result column="user_name" property="user_name" />
		<result column="user_pwd" property="user_pwd" />
		<result column="user_age" property="user_age" />
	</resultMap>
</mapper>

18.注册页面 add.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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 'add.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <form action="${pageContext.request.contextPath }/user/toadd" method="get">
    	<table border="1">
			<tr>
				<td colspan="2">添加用户信息</td>
			</tr>
			<tr>
				<td>姓名</td>
				<td>
					<input type="text" name="user_name" />
				</td>
			</tr>
			<tr>
				<td>年龄</td>
				<td>
					<input type="text" name="user_age" />
				</td>
			</tr>
			<tr>
				<td>密码</td>
				<td>
					<input type="text" name="password" />
				</td>
			</tr>
			<tr>
				<td>
					<a href="/user/getfind">返回</a>
				</td>
				<td>
					<input type="submit" value="提交" />					
				</td>
			</tr>
		</table>
    </form>
  </body>
</html>

使用SSM框架 实现登录、注册、分页和增删改操作

19.修改界面 editgo.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 'editgo.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
   	<form action="user/update" method="post">
   		<table border="1">
			
			<tr>
				<td colspan="2">修改用户信息</td>
			</tr>
			<tr>
				<td>编号</td>
				<td>
					<input type="text" name="user_id" value="${user.user_id}" readonly/>
				</td>
			</tr>
			<tr>
				<td>姓名</td>
				<td>
					<input type="text" name="user_name" value="${user.user_name }" />
				</td>
			</tr>
			<tr>
				<td>密码</td>
				<td>
					<input type="text" name="password" value="${user.password }"/>
				</td>
			</tr>
			<tr>
				<td>年龄</td>
				<td>
					<input type="text" name="user_age" value="${user.user_age }"/>
				</td>
			</tr>
			<tr>
			<tr>
				<td>
					<a href="user/getfind">返回</a>
				</td>
				<td>
					<input type="submit" value="提交" />					
				</td>
			</tr>
		</table>
   	</form>
  </body>
</html>

20.查询界面 find.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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 'find.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <form action="${pageContext.request.contextPath }/user/getfind">
    	<input type="text" name="id">
    	<input type="submit" value="查询">
    </form>
  </body>
</html>

21.登录界面 login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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 'login.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  ${msg }
   	<form action="${pageContext.request.contextPath }/user/getlogin">
   	<table>
   		<tr>
   			<td>用户名</td>
   			<td><input type="text" name="user_name"></td>
   		</tr>
   		<tr>
   			<td>密码</td>
   			<td><input type="text" name="password"></td>
   		</tr>
   		<tr>
				<td>
					<a href="${pageContext.request.contextPath }/user/addgo">注册</a>
				</td>
				<td>
					<input type="submit" value="登录" />					
				</td>
			</tr>
   	</table>
   		
   	</form>
  </body>
</html>

22.主页面 main.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 'main.jsp' starting page</title>
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.10.2.js"></script>

  </head>
  <body>

   <table border="1">
   	<tr>
   		<th>编号:</th>
   		<th>姓名:</th>
   		<th>密码:</th>
   		<th>年龄:</th>
   		<th>操作:</th>
   	</tr>	
   	<c:forEach items="${requestScope.pagemsg.lists}" var="user">
   		<tr>
   		<td>${user.user_id }</td>
   		<td>${user.user_name }</td>
   		<td>${user.password }</td>
   		<td>${user.user_age }</td>
   		<td><a href="user/delete?id=${user.user_id}" >删除</a></td>
   		<td><a href="user/editgo?id=${user.user_id}">修改</a></td>
   	</tr>
   	</c:forEach>
  
   <tr>
	<td class="td2">
	   <span>第${requestScope.pagemsg.currPage }/ ${requestScope.pagemsg.totalPage}页</span>  
	   <span>总记录数:${requestScope.pagemsg.totalCount }  每页显示:${requestScope.pagemsg.pageSize}</span>  
	   <span>
	       <c:if test="${requestScope.pagemsg.currPage != 1}">
	           <a href="${pageContext.request.contextPath }/user/main?currentPage=1">[首页]</a>  
	           <a href="${pageContext.request.contextPath }/user/main?currentPage=${requestScope.pagemsg.currPage-1}">[上一页]</a>  
	       </c:if>
	       
	       <c:if test="${requestScope.pagemsg.currPage != requestScope.pagemsg.totalPage}">
	           <a href="${pageContext.request.contextPath }/user/main?currentPage=${requestScope.pagemsg.currPage+1}">[下一页]</a>  
	           <a href="${pageContext.request.contextPath }/user/main?currentPage=${requestScope.pagemsg.totalPage}">[尾页]</a>  
	       </c:if>
	   </span>
	</td>
</tr>
 </table>
  </body>
</html>