springmvc分层设计

系统分层

如何分层

  • 表示层(UI):数据展现/操作界面,请求分发。
  • 业务层(服务层):封装业务逻辑处理。
  • 持久层(数据访问层):封装数据访问逻辑。

各层之间的关系

  • 表示层通过接口调用业务层,业务层通过接口调用持久层。
  • 这样,当下一层的实现发生改变,不影响上一层。
  • 注:MVC是一种表示层架构思想。
    在这里插入图片描述
    在这里插入图片描述

处理表单中文参数值乱码问题

乱码问题产生的原因

表单提交时,浏览器会对表单中文参数值进行编码(会使用打开该表单
所在页面时的字符集来编码),服务器端默认会使用iso-8859-1来解码。
所以会产生乱码。

解决

可以使用SpringMVC提供的过滤器(CharacterEncodingFilter)来解决。
只需要配置该过滤器即可

  • 过滤器的编码设置应该与jsp页面保持一致
  • 表单的提交方式设置为POST
<filter>
 	<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
 	<url-pattern>/*</url-pattern>
 </filter-mapping>

增删改查的实现

数据库与表的设计

数据库的创建

create database ems;

在这里插入图片描述
在这里插入图片描述

jar包的依赖

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>cn.company</groupId>
	<artifactId>TestDemo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<dependencies>
		<dependency>
			<!-- junit:单元测试 -->
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
		<!--spring-webmvc -->
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>5.2.5.RELEASE</version>
		</dependency>
		<!-- 数据库连接池 -->
		<!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp -->
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.4</version>
		</dependency>
		<!--mysql -->
		<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>8.0.19</version>
		</dependency>
		<!-- servlet的jar包依赖,
		 <scope>provided</scope>
		  表示编译时有效,不会打包发布到Tomcat中 -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>4.0.1</version>
			<scope>provided</scope>
		</dependency>
		<!-- jsp的jar包依赖 -->
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>javax.servlet.jsp-api</artifactId>
			<version>2.3.3</version>
			<scope>provided</scope>
		</dependency>
		<!-- jstl表达式 -->
		<!-- https://mvnrepository.com/artifact/jstl/jstl -->
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
	</dependencies>
	<!-- 添加tomcat插件 -->
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.2</version>
				<configuration>
					<port>8080</port>
					<hostName>localhost</hostName>
					<uriEncoding>UTF-8</uriEncoding>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

前端控制器和过滤器的配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>TestDemo</display-name>
 <!-- 前端控制器 -->
 <servlet>
 	<servlet-name>springmvc</servlet-name>
 	<!--  初始化方法会启动spring容器-->
 	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 	<init-param>
 		<param-name>contextConfigLocation</param-name>
 		<!--springmvc配置文件的位置  -->
 		<param-value>classpath:annotation.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>
 <filter>
 	<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
 	<url-pattern>/*</url-pattern>
 </filter-mapping>
</web-app>

数据库连接配置文件db.properties

# database connection parameters
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ems?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=root

springmvc配置文件

<?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:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:jpa="http://www.springframework.org/schema/data/jpa"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
		http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.8.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
		
		
		<!-- 配置组件扫描 -->
		<context:component-scan base-package="cn.ems"/> 
		<!-- 配置MVC注解扫描  --> 
		<mvc:annotation-driven/>
		<!-- 配置视图解析器 -->
		<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
			<property name="prefix" value="/WEB-INF/"/>
			<property name="suffix" value=".jsp"/>
		</bean>
		<!-- 静态资源的加载 -->
		<mvc:resources location="/" mapping="/**"/>
		<!--加载数据库配置文件  -->
		<util:properties id="db" location="classpath:db.properties"/>
		<!-- 配置数据库连接池 -->
		<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="ds">
			<property name="driverClassName" value="#{db['jdbc.driver']}"/>
			<property name="url" value="#{db['jdbc.url']}"/>
			<property name="username" value="#{db['jdbc.username']}"/>
			<property name="password" value="#{db['jdbc.password']}"/>
		</bean>
		
</beans>

实体类

package cn.ems.entity;

/**
 * 雇员类
 * 
 * @author 86182
 *
 */
public class Employee {
	private int id;// 主键
	private String ename;// 雇员名字
	private double salary;// 薪水
	private int age;// 年龄

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getEname() {
		return ename;
	}

	public void setEname(String ename) {
		this.ename = ename;
	}

	public double getSalary() {
		return salary;
	}

	public void setSalary(double salary) {
		this.salary = salary;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String toString() {
		return "Employee [id=" + id + ", ename=" + ename + ", salary=" + salary + ", age=" + age + "]";
	}
}

package cn.ems.entity;

/**
 * 用户类
 * 
 * @author 86182
 *
 */
public class User {
	private int id;// 主键
	private String username;// 账号
	private String name;// 名称
	private String password;// 密码
	private String gender;// 性别

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String toString() {
		return "User [id=" + id + ", username=" + username + ", name=" + name + ", password=" + password + ", gender="
				+ gender + "]";
	}
}

持久层

package cn.ems.dao;

import cn.ems.entity.User;

/**
 *持久层接口 
 * @author 86182
 *用户类接口
 */
public interface UserDAO {
	public User findByUsername(String uname);
	public void addUser(User user);
}

package cn.ems.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.stereotype.Repository;

import cn.ems.entity.User;

/**
 * 持久层实现类
 * 
 * @author 86182
 *
 */
@Repository("userDAO")
public class UserDAOJdbcImpl implements UserDAO {

	@Resource(name = "ds")
	DataSource ds;

	/*
	 * 根据用户名查找用户
	 */
	public User findByUsername(String uname) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		User user = null;
		try {
			conn = ds.getConnection();
			String sql = "select * from t_user where username=?";
			ps = conn.prepareStatement(sql);
			ps.setString(1, uname);
			rs = ps.executeQuery();
			while (rs.next()) {
				user = new User();
				user.setId(rs.getInt("id"));
				user.setUsername(uname);
				user.setName(rs.getString("name"));
				user.setPassword(rs.getString("password"));
				user.setGender(rs.getString("gender"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return user;

	}

	/*
	 * 添加用户信息
	 */
	public void addUser(User user) {
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			conn = ds.getConnection();
			String sql = "insert into t_user values(null,?,?,?,?)";
			ps = conn.prepareStatement(sql);
			ps.setString(1, user.getUsername());
			ps.setString(2, user.getName());
			ps.setString(3, user.getPassword());
			ps.setString(4, user.getGender());
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

	}

}

package cn.ems.dao;

import java.util.List;

import cn.ems.entity.Employee;

public interface EmployeeDAO {
	public List<Employee>findAll();
	public void addEmployee(Employee e);
	public Employee findEmployeeById(int id);
	public int updateEmployee(Employee e);
	public void deleteEmployee(int id);
}

package cn.ems.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.stereotype.Repository;

import cn.ems.entity.Employee;
/**
*职员类接口
*/
@Repository("employeeDAO")
public class EmployeeDAOJdbcImpl implements EmployeeDAO {

	@Resource(name = "ds")
	DataSource ds;

	/*
	 * 查询所有的雇员信息
	 */
	public List<Employee> findAll() {
		List<Employee> employeeList = new ArrayList<Employee>();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			conn = ds.getConnection();
			String sql = "select * from t_emp";
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				Employee e = new Employee();
				e.setId(rs.getInt("id"));
				e.setEname(rs.getString("ename"));
				e.setSalary(rs.getDouble("salary"));
				e.setAge(rs.getInt("age"));
				employeeList.add(e);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return employeeList;
	}

	/*
	 * 新增雇员
	 */
	public void addEmployee(Employee e) {
		Connection conn = null;
		PreparedStatement ps = null;
		String sql = "insert into t_emp values(null,?,?,?)";
		try {
			conn = ds.getConnection();
			ps = conn.prepareStatement(sql);
			ps.setString(1, e.getEname());
			ps.setDouble(2, e.getSalary());
			ps.setInt(3, e.getAge());
			ps.executeUpdate();
		} catch (SQLException e1) {
			e1.printStackTrace();
		} finally {
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
		}

	}

	/*
	 * 根据id查询雇员
	 */
	public Employee findEmployeeById(int id) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Employee e = null;
		try {
			conn = ds.getConnection();
			String sql = "select * from t_emp where id=?";
			ps = conn.prepareStatement(sql);
			ps.setInt(1, id);
			rs = ps.executeQuery();
			while (rs.next()) {
				e = new Employee();
				e.setId(rs.getInt("id"));
				e.setEname(rs.getString("ename"));
				e.setSalary(rs.getDouble("salary"));
				e.setAge(rs.getInt("age"));
			}
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		return e;
	}

	/*
	 * 更新雇员信息
	 */
	public int updateEmployee(Employee e) {
		int count = 0;
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			conn = ds.getConnection();
			String sql = "update t_emp set ename=?,salary=?,age=? where id=?";
			ps = conn.prepareStatement(sql);
			ps.setString(1, e.getEname());
			ps.setDouble(2, e.getSalary());
			ps.setInt(3, e.getAge());
			ps.setInt(4, e.getId());
			ps.executeUpdate();
		} catch (SQLException e1) {
			e1.printStackTrace();
		} finally {
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
		}

		return count;
	}

	/**
	 * 根据id删除雇员
	 */
	public void deleteEmployee(int id) {
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			conn = ds.getConnection();
			String sql = "delete from t_emp where id=?";
			ps = conn.prepareStatement(sql);
			ps.setInt(1, id);
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

	}

}

异常类的定义

package cn.ems.service;
/**
 * 	应用异常类
 * @author 86182
 *
 */
public class AppException extends RuntimeException{
	public AppException() {
		
	}
	public AppException(String message) {
		super(message);
	}
}

业务层

package cn.ems.service;

import cn.ems.entity.User;
/**
 * 业务层接口
 * @author 86182
 *
 */
public interface LoginService {
	public User checkLogin(String uname,String pwd);
	public void addUser(User user);
}

package cn.ems.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.ems.dao.UserDAO;
import cn.ems.entity.User;
/**
 * 业务层实现类
 * @author 86182
 *
 */
@Service("loginService")
public class LoginServiceImpl implements LoginService {

	@Resource(name = "userDAO")
	UserDAO dao;
	public User checkLogin(String uname, String pwd) {
		User user=dao.findByUsername(uname);
		if(user==null) {
			/*
			 * 抛出应用异常:
			 * 	因为用户错误的操作引起的异常,
			 *  需要明确提示用户采取正确的操作。
			 */
			throw new AppException("用户不存在");
		}
		if(!user.getPassword().equals(pwd)) {
			throw new AppException("密码错误");
		}
		return user;
	}
	public void addUser(User user) {
		dao.addUser(user);
	}

}

package cn.ems.service;

import java.util.List;

import cn.ems.entity.Employee;

public interface EmpService {
	public List<Employee>findAll();
	public void addEmployee(Employee e);
	public Employee findEmployeeById(int id);
	public int updateEmployee(Employee e);
	public void deleteEmployee(int id);
}

package cn.ems.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.ems.dao.EmployeeDAO;
import cn.ems.entity.Employee;

@Service("empService")
public class EmpServiceImpl implements EmpService {

	@Resource(name = "employeeDAO")
	EmployeeDAO dao;

	public List<Employee> findAll() {
		List<Employee> employees = dao.findAll();
		return employees;
	}

	public void addEmployee(Employee e) {
		dao.addEmployee(e);
	}

	public Employee findEmployeeById(int id) {
		return dao.findEmployeeById(id);
	}

	public int updateEmployee(Employee e) {
		return dao.updateEmployee(e);
	}

	public void deleteEmployee(int id) {
		dao.deleteEmployee(id);
	}

}

控制层定义

package cn.ems.controller;

import javax.annotation.Resource;

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 cn.ems.entity.User;
import cn.ems.service.AppException;
import cn.ems.service.LoginService;

@Controller
public class LoginController {
	@Resource(name = "loginService")
	LoginService loginService;

	@RequestMapping("/toLogin")
	public String toLogin() {
		return "login";
	}
	@RequestMapping("/login")
	public String login(String uname,String pwd,Model model) {
		//将登录请求分发给业务层的对象来处理
		try {
			User user=loginService.checkLogin(uname, pwd);
		}catch(Exception e) {
			e.printStackTrace();
			if(e instanceof AppException) {
				model.addAttribute("login_failed",e.getMessage());
				return "login";
			}
			//系统异常
			return "error";
		}
		//登录成功,重定向到首页
		return "redirect:toIndex";
	}
	@RequestMapping("/toIndex")
	public String toIndex() {
		return "index";
	}
	@RequestMapping("/regesit")
	public String regesit() {
		return "regesit";
	}
	@RequestMapping("/addUser")
	public String addUser(User user) {
		loginService.addUser(user);
		System.out.println("新增"+user.getName()+"成功!");
		return "redirect:toLogin";
	}
}

package cn.ems.controller;

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

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.ems.entity.Employee;
import cn.ems.service.EmpService;

@Controller
public class EmpController {
	@Resource(name = "empService")
	private EmpService empService;
	
	@RequestMapping("/list")
	public String list(Model model) {
		List<Employee>employees=new ArrayList<Employee>();
		try {
			employees=empService.findAll();
		}catch(Exception e) {
			e.printStackTrace();
			return "error";
		}
		model.addAttribute("employees",employees);
		return "empList";
	}
	@RequestMapping("/toAdd")
	public String toAdd() {
		return "addEmp";
	}
	@RequestMapping("/add")
	public String add(Employee e) {
		empService.addEmployee(e);
		return "redirect:list";
	}
	@RequestMapping("/load")
	public String load(int id,Model model) {
		Employee emp=empService.findEmployeeById(id);
		model.addAttribute("emp",emp);
		return "updateEmp";
	}
	@RequestMapping("/update")
	public String update(Employee e) {
		int count=empService.updateEmployee(e);
		System.out.println("更新了"+count+"条数据");
		return "redirect:list";
	}
	@RequestMapping("/delete")
	public String delete(int id) {
		empService.deleteEmployee(id);
		return "redirect:list";
	}
}

表示层

页面的展示

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
	<form action="add" method="post">
		<fieldset>
			<legend>添加员工</legend>
			姓名:<input name="ename"><br>
			 薪水:<input name="salary"><br>
			年龄:<input name="age"><br> 
			<input type="submit" value="添加">
		</fieldset>
	</form>
</body>
</html>
<%@ page pageEncoding="utf-8" 
contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>员工管理</title>
		<link rel="stylesheet" 
		type="text/css" href="css/style.css" />
	</head>
	<body>
		<div id="wrap">
			<div id="top_content"> 
				<%@ include file="header.jsp" %>
				<div id="content">
					<p id="whereami">
					</p>
					<h1>
						员工列表
					</h1>
					<table class="table">
						<tr class="table_header">
							<td>
								ID
							</td>
							<td>
								姓名
							</td>
							<td>
								薪水
							</td>
							<td>
								年龄
							</td>
							<td>
								操作
							</td>
						</tr>
						<c:forEach items="${employees}" var="e" 
						varStatus="s">
						<tr class="row${s.index % 2 + 1}">
							<td>
								${e.id}
							</td>
							<td>
								${e.ename}
							</td>
							<td>
								${e.salary}
							</td>
							<td>
								${e.age}
							</td>
							<td>
								<a href="delete?id=${e.id}" 
								onclick="return confirm('确定删除${e.ename}');">删除</a>&nbsp;
								<a href="load?id=${e.id}">修改</a>
							</td>
						</tr>
						</c:forEach>
					</table>
					<p>
						<input type="button" class="button" 
						value="添加员工" 
						onclick="location='toAdd'"/>
					</p>
				</div>
			</div>
			<%@ include file="footer.jsp" %>
		</div>
	</body>
</html>

<%@page pageEncoding="utf-8" 
contentType="text/html; charset=utf-8" %>
<html>
	<head></head>
	<body style="font-size:30px;">
		系统繁忙,稍后重试
	</body>
</html>

<div id="footer">
	<div id="footer_bg">ABC@126.com</div>
</div>
<%@page import="java.util.Date,java.text.SimpleDateFormat"%>
<div id="header">
	<div id="rightheader">
		<p>
			<%
			Date date=new Date();
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			String now=sdf.format(date);
			%>
			<%=now %>
			<br />
		</p>
	</div>
	<div id="topheader">
		<h1 id="title">
			<a href="#">main</a>
		</h1>
	</div>
	<div id="navigation"></div>
</div>
<%@page pageEncoding="utf-8" 
contentType="text/html; charset=utf-8" %>
<html>
	<head></head>
	<body style="font-size:30px;">
		首页
	</body>
</html>

<%@ page pageEncoding="utf-8" 
contentType="text/html; charset=utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>登录</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css"
			href="css/style.css" />
	</head>

	<body>
		<div id="wrap">
			<div id="top_content">
					<div id="header">
						<div id="rightheader">
							<p>
								2020/04/13
								<br />
							</p>
						</div>
						<div id="topheader">
							<h1 id="title">
								<a href="#">main</a>
							</h1>
						</div>
						<div id="navigation">
						</div>
					</div>
				<div id="content">
					<p id="whereami">
					</p>
					<h1>
						登录
					</h1>
					<form action="login" method="post">
						<table cellpadding="0" cellspacing="0" border="0"
							class="form_table">
							<tr>
								<td valign="middle" align="right">
									用户名:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" 
									name="uname" />
									<span style="color:red;font-size:24px;">
										${login_failed}
									</span>
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									密码:
								</td>
								<td valign="middle" align="left">
									<input type="password" class="inputgri" 
									name="pwd" />
								</td>
							</tr>
						</table>
						<p>
							<input type="submit" class="button" 
							value="确定" />
						</p>
					</form>
				</div>
			</div>
			<div id="footer">
				<div id="footer_bg">
					ABC@126.com
				</div>
			</div>
		</div>
	</body>
</html>

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
	<form action="addUser" method="post">
		<fieldset>
			<legend>注册账号</legend>
			账号:<input name="username"><br>
			 名称:<input name="name"><br>
			密码:<input name="password" type="password"><br> 
			性别:
			男<input type="radio" name="gender" value=""><input type="radio" name="gender" value=""><br>
			<input type="submit" value="添加">
		</fieldset>
	</form>
</body>
</html>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
	<form action="update" method="post">
		<fieldset>
			<legend>员工信息的修改</legend>
			<input type="hidden" value="${emp.id }" name="id">
			姓名:<input name="ename" value="${emp.ename }"><br>
			 薪水:<input name="salary" value="${emp.salary }"><br>
			年龄:<input name="age" value="${emp.age }"><br> 
			<input type="submit" value="修改">
		</fieldset>
	</form>
</body>
</html>

源码下载

源码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值