Spring
Spring就像是整个项目中装配bean的大工厂,在配置文件中可以指定使用特定的参数去调用实体类的构造方法来实例化对象。也可以称之为项目中的粘合剂。
Spring的核心思想是IoC(控制反转),即不再需要程序员去显式地new
一个对象,而是让Spring框架帮你来完成这一切。
SpringMVC
SpringMVC在项目中拦截用户请求,它的核心Servlet即DispatcherServlet承担中介或是前台这样的职责,将用户请求通过HandlerMapping去匹配Controller,Controller就是具体对应请求所执行的操作。SpringMVC相当于SSH框架中struts。
mybatis
mybatis是对jdbc的封装,它让数据库底层操作变的透明。mybatis的操作都是围绕一个sqlSessionFactory实例展开的。mybatis通过配置文件关联到各实体类的Mapper文件,Mapper文件中配置了每个类对数据库所需进行的sql语句映射。在每次与数据库交互时,通过sqlSessionFactory拿到一个sqlSession,再执行sql命令。
页面发送请求给控制器,控制器调用业务层处理逻辑,逻辑层向持久层发送请求,持久层与数据库交互,后将结果返回给业务层,业务层将处理逻辑发送给控制器,控制器再调用视图展现数据。
1:数据库文件
2:项目整体结构
3:在pom.xml文件中添加如下内容
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ssm</groupId>
<artifactId>ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ssm Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<junit.version>4.10</junit.version>
<spring.version>4.1.3.RELEASE</spring.version>
<mybatis.version>3.2.8</mybatis.version>
<mybatis.spring.version>1.2.2</mybatis.spring.version>
<mysql.version>5.1.32</mysql.version>
<druid.version>1.1.6</druid.version>
<slf4j.version>1.6.4</slf4j.version>
<jstl.version>1.2</jstl.version>
<servlet-api.version>2.5</servlet-api.version>
<jsp-api.version>2.0</jsp-api.version>
<jackson.version>2.4.2</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!--这个jar文件包含对Spring对JDBC数据访问进行封装的所有类 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 整合log4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- Servlet/JSP/JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<!-- 整合mybatis框架 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- druid连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
</dependencies>
<build>
<finalName>ssm</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
4:编写ssm配置文件
在resources下新建个配置文件jdbc.properties,内容如下:
db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql:///chu?characterEncoding=utf-8
db.username=root
db.password=root
在resources下新建个配置文件log4j.properties,内容如下:
log4j.rootLogger=INFO,A1
log4j.logger.cn.yhmis.mapper =DEBUG
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n
在spring下新建个配置文件applicationContext.xml,内容如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<!-- 0.测试spring的运行环境
将Door类的对象的创建交给spring容器 -->
<bean id="user" class="chu.entity.User"></bean>
<!-- 1.加载jdbc.properties文件的位置 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 2.配置druid连接池 ,id是固定值,class是druid连接池类的全路径 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<!-- 配置连接数据库的基本信息 -->
<property name="driverClassName" value="${db.driverClassName}"></property>
<property name="url" value="${db.url}"></property>
<property name="username" value="${db.username}"></property>
<property name="password" value="${db.password}"></property>
</bean>
<!-- 3.整合spring和mybatis框架 将SqlSession等对象的创建交给Spring容器id值(sqlSessionFactory)是固定值
-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 3.1.指定mybatis核心配置文件的位置 -->
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
<!-- 3.2.配置连接池(数据源) ref指向连接池bean对象的id值 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 3.3、扫描所有的 XxxMapper.xml映射文件,读取其中配置的SQL语句 -->
<property name="mapperLocations" value="classpath:mybatis/mapper/*.xml"/>
</bean>
<!-- 4、定义mapper接口扫描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 扫描所有XxxMapper接口,将接口实例的创建交给spring容器 -->
<property name="basePackage" value="chu.dao"/>
</bean>
<!-- 5.配置需要扫描的包(service层):spring自动去扫描 base-package下的类,如果扫描到的类上有 @Controller、@Service、@Component等注解,将会自动将类注册为bean(即由spring创建实例)
@Service
-->
<context:component-scan base-package="chu.service"></context:component-scan>
</beans>
在spring下新建个配置文件springmvc-config.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!-- 1.配置前端控制器放行静态资源(html/css/js等,否则静态资源将无法访问) -->
<mvc:default-servlet-handler/>
<!-- 2.配置注解驱动,用于识别注解(比如@Controller) -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 3.配置需要扫描的包:spring自动去扫描 base-package 下的类,如果扫描到的类上有 @Controller、@Service、@Component等注解,将会自动将类注册为bean -->
<context:component-scan base-package="chu.controller"></context:component-scan>
<!-- 4.配置内部资源视图解析器prefix:配置路径前缀suffix:配置文件后缀-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
在mapper下新建个配置文件mybatis-config.xml,内容如下:
<?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">
<!-- MyBatis的全局配置文件 -->
<configuration>
<!-- 1.配置开发环境 -->
<!-- 这里可以配置多个环境,比如develop,test等 -->
<!-- 1.1.配置事务管理方式:JDBC:将事务交给JDBC管理(推荐) -->
<!-- 1.2.配置数据源,即连接池方式:JNDI/POOLED/UNPOOLED -->
<!-- 2.加载Mapper配置文件,路径以斜杠间隔: xx/xx/../xx.xml -->
<!-- 以上配置移动到spring的配置文件中 -->
</configuration>
web.xml文件
<?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" id="WebApp_ID" version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 0.配置500异常跳转到的友好提示页面 -->
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/error/500.jsp</location>
</error-page>
<!-- 0.配置404跳转到的友好提示页面 -->
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/error/404.jsp</location>
</error-page>
<!-- 配置springmvc的前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置spring、springmvc核心配置文件的位置 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/*.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!-- 将所有请求(除了访问jsp的请求) 交给springmvc的前端控制器 -->
<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>
<!-- 将访问指定规则的文件, 交给tomcat中默认的Servlet来处理
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>-->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
<url-pattern>*.jpg</url-pattern>
<url-pattern>*.gif</url-pattern>
<url-pattern>*.html</url-pattern>
<url-pattern>*.css</url-pattern>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
</web-app>
controller层代码
package chu.controller;
import chu.entity.User;
import chu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/userList")
public String userList(Model model) {
List<User> list = userService.findAll();
model.addAttribute("list", list);
return "user_list";
}
@RequestMapping("/userAdd")
public String userAdd(User user, Model model) {
userService.addUser(user);
return "redirect:/userList";
}
@RequestMapping("/userDelete")
public String userDelete(Integer id) {
userService.deleteById( id );
return "redirect:/userList";
}
@RequestMapping("/userInfo")
public String userInfo(Model model, Integer id) {
User user = userService.findById( id );
model.addAttribute("user",user);
return "user_update";
}
@RequestMapping("/userUpdate")
public String userUpdate(User user) {
userService.updateById(user);
return "redirect:/userList";
}
@RequestMapping("/{page}")
public String page(@PathVariable String page) {
return page;
}
}
service层代码
package chu.service;
import chu.entity.User;
import java.util.List;
public interface UserService {
public List<User> findAll();
public void addUser(User user);
public void deleteById(Integer id);
public User findById(Integer id);
public void updateById(User user);
}
package chu.service;
import chu.dao.UserMapper;
import chu.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public List<User> findAll() {
return userMapper.findAll();
}
@Override
public void addUser(User user) {
userMapper.addUser(user);
}
@Override
public void deleteById(Integer id) {
userMapper.deleteById(id);
}
@Override
public User findById(Integer id) {
return userMapper.findById(id);
}
@Override
public void updateById(User user) {
userMapper.updateById(user);
}
}
dao层代码
package chu.dao;
import chu.entity.User;
import java.util.List;
public interface UserMapper {
public List<User> findAll();
public void addUser(User user);
public void deleteById(Integer id);
public User findById(Integer id);
public void updateById(User user);
}
mapping层代码
<?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="chu.dao.UserMapper">
<select id="findAll" resultType="chu.entity.User">
select * from user
</select>
<update id="addUser">
insert into user values
( #{id}, #{username}, #{password}, #{age} );
</update>
<update id="deleteById">
delete from user where id=#{id}
</update>
<select id="findById" resultType="chu.entity.User">
select * from user where id=#{id}
</select>
<update id="updateById">
update user set username=#{username},password=#{password}, age=#{age}
where id=#{id}
</update>
</mapper>
entity层代码
package chu.entity;
public class User {
private Integer id;
private String username;
private String password;
private Integer age;
@Override
public String toString() {
return "User{" +
"id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
", age=" + age +
'}';
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
user_add页面
<%@ page pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
<head>
<title>新增用户</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
body{ font-family: "微软雅黑"; background-color: #EDEDED; }
h2{ text-align: center;font-size:26px; }
table{ margin: 30px auto; text-align: center; border-collapse:collapse; width:50%; }
td, th{ padding: 7px;font-size:18px;}
hr{ margin-bottom:20px; border:1px solid #aaa; }
input,select,textarea{ width:284px; height:30px; background:#EDEDED; border:1px solid #999; text-indent:5px; font-size:18px; }
input[type='submit']{ width:130px; height:36px; cursor:pointer; border-radius:5px 5px 5px 5px; background:#ddd; }
select{text-indent:0px;}
textarea{height:100px;font-size:22px;}
</style>
</head>
<body><!-- body-start -->
<h2>新增用户</h2>
<hr/>
<form action="userAdd" method="POST">
<table border="1">
<tr>
<td width="30%">用户编号</td>
<td>
<input type="text" name="id"/>
</td>
</tr>
<tr>
<td>用户名</td>
<td>
<input type="text" name="username"/>
</td>
</tr>
<tr>
<td>密码</td>
<td>
<input type="text" name="password"/>
</td>
</tr>
<tr>
<td>年龄</td>
<td>
<input type="text" name="age"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提 交"/>
</td>
</tr>
</table>
</form>
</body><!-- body-end -->
</html>
user_list页面
<%@ page pageEncoding="utf-8"%>
<%-- 引入JSTL标签库 --%>
<%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<html>
<head>
<title>用户列表</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
body{ font-family: "微软雅黑"; background-color: #EDEDED; }
h2{ text-align: center;}
table{ width:96%; margin: 0 auto; text-align: center; border-collapse:collapse; font-size:16px;}
td, th{ padding: 5px;}
th{ background-color: #DCDCDC; width:120px; }
th.width-40{ width: 40px; }
th.width-70{ width: 70px; }
th.width-80{ width: 80px; }
hr{ margin-bottom:20px; border:1px solid #aaa; }
#add-user{text-align:center;font-size:20px;}
</style>
</head>
<body><!-- body-start -->
<h2>用户列表</h2>
<div id="add-user">
<a href="user_add" target="rightFrame">新增用户</a>
</div>
<hr/>
<table border="1">
<tr>
<th class="width-40">编号</th>
<th>用户名</th>
<th class="width-80">密码</th>
<th>年龄</th>
<th class="width-80">操 作</th>
</tr>
<!-- 模版数据 -->
<c:forEach items="${ list }" var="user" varStatus="status">
<tr>
<td>${ status.count }</td>
<td>${ user.username }</td>
<td>${ user.password}</td>
<td>${ user.age}</td>
<td>
<a href="userDelete?id=${ user.id }">删除</a>
|
<a href="userInfo?id=${ user.id }">修改</a>
</td>
</tr>
</c:forEach>
</table>
</body><!-- body-end -->
</html>
user_update页面
<%@ page pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
<head>
<title>修改用户信息</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
body{ font-family: "微软雅黑"; background-color: #EDEDED; }
h2{ text-align: center;font-size:26px; }
table{ margin: 30px auto; text-align: center; border-collapse:collapse; width:50%; }
td, th{ padding: 7px;font-size:18px;}
hr{ margin-bottom:20px; border:1px solid #aaa; }
input,select,textarea{ width:284px; height:30px; background:#EDEDED; border:1px solid #999; text-indent:5px; font-size:18px; }
input[type='submit']{ width:130px; height:36px; cursor:pointer; border-radius:5px 5px 5px 5px; background:#ddd; }
select{text-indent:0px;}
textarea{height:100px;font-size:22px;}
</style>
</head>
<body><!-- body-start -->
<h2>修改用户</h2>
<hr/>
<form action="userUpdate" method="POST">
<!-- hidden隐藏域,在提交表单时连door.id一起提交 -->
<input type="hidden" name="id" value="${ user.id }"/>
<table border="1">
<tr>
<td width="30%">用户名</td>
<td>
<input type="text" name="username" value="${ user.username }"/>
</td>
</tr>
<tr>
<td>密码</td>
<td>
<input type="text" name="password" value="${ user.password }"/>
</td>
</tr>
<tr>
<td>年龄</td>
<td>
<input type="text" name="age" value="${user.age }"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提 交" />
</td>
</tr>
</table>
</form>
</body><!-- body-end -->
</html>
404页面
<%@ page pageEncoding="utf-8"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<style>
#err-code{ width:100%; }
#msg,#code,#youcan{
color:#72AAB4;
text-align:center;
font-family:"微软简隶书";
font-weight:bolder;
}
#msg{
font-size:50px;
font-family:"幼圆";
margin-top:50px;
}
#emoji{
display: inline-block;
width:80px;
height:80px;
background:url('e.png') no-repeat center;
background-size:80px 80px;
}
span{ vertical-align: middle; }
#code{
font-size:200px;
font-family:"幼圆";
margin-top:30px;
}
#youcan{
width:50%;
text-align:left;
font-size:30px;
font-family:"幼圆";
margin:0 auto;
margin-top:20px;
}
#youcan a{
display: inline-block;
text-align:center;
width:130px;
height:30px;
font-size:26px;
color:#fff;
text-decoration:none;
background:#9AC1C9;
border:2px solid #72AAB4;
border-radius:25px;
cursor: pointer;
}
</style>
<script>
window.onload = function(){
var a = document.getElementById("index");
a.onclick=function(){
window.location.href="http://localhost:8080/ssm/userList";
/* 防止页面嵌套 */
if (window.top != window.self) {
top.location.href = "http://localhost:8080/ssm/userList";
}
};
}
</script>
</head>
<body>
<div id="err-code">
<div id="msg">
<span id="emoji"></span>
<span>对不起亲,您访问的网页去了火星...</span>
</div>
<div id="code">
404
</div>
<div id="youcan">
您还可以:
<a id="index">返回用户列表</a>
</div>
</div>
</body>
</html>
505页面
<%@ page pageEncoding="utf-8"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<style>
#err-500{ width:100%; }
#msg,#code,#youcan{
color:#72AAB4;
text-align:center;
font-family:"微软简隶书";
font-weight:bolder;
}
#msg{
font-size:50px;
font-family:"幼圆";
margin-top:50px;
}
#emoji{
display: inline-block;
width:80px;
height:80px;
background:url('e.png') no-repeat center;
background-size:80px 80px;
}
span{ vertical-align: middle; }
#code{
font-size:200px;
font-family:"幼圆";
margin-top:30px;
}
#youcan{
width:50%;
text-align:left;
font-size:30px;
font-family:"幼圆";
margin:0 auto;
margin-top:20px;
}
#youcan a{
display: inline-block;
text-align:center;
width:130px;
height:30px;
font-size:26px;
color:#fff;
text-decoration:none;
background:#9AC1C9;
border:2px solid #72AAB4;
border-radius:25px;
cursor: pointer;
}
</style>
<script>
window.onload = function(){
var a = document.getElementById("index");
a.onclick=function(){
window.location.href="http://localhost:8080/ssm/userList";
/* 防止页面嵌套 */
if (window.top != window.self) {
top.location.href = "http://localhost:8080/ssm/userList";
}
};
}
</script>
</head>
<body>
<div id="err-500">
<div id="msg">
<span id="emoji"></span>
<span>对不起亲,服务器内部出错了哦...</span>
</div>
<div id="code">
500
</div>
<div id="youcan">
您还可以:
<a id="index">返回用户列表</a>
</div>
</div>
</body>
</html>
index页面
<%@ page pageEncoding="utf-8"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<style>
#err-500{ width:100%; }
#msg,#code,#youcan{
color:#72AAB4;
text-align:center;
font-family:"微软简隶书";
font-weight:bolder;
}
#msg{
font-size:50px;
font-family:"幼圆";
margin-top:50px;
}
#emoji{
display: inline-block;
width:80px;
height:80px;
background:url('e.png') no-repeat center;
background-size:80px 80px;
}
span{ vertical-align: middle; }
#code{
font-size:200px;
font-family:"幼圆";
margin-top:30px;
}
#youcan{
width:50%;
text-align:left;
font-size:30px;
font-family:"幼圆";
margin:0 auto;
margin-top:20px;
}
#youcan a{
display: inline-block;
text-align:center;
width:130px;
height:30px;
font-size:26px;
color:#fff;
text-decoration:none;
background:#9AC1C9;
border:2px solid #72AAB4;
border-radius:25px;
cursor: pointer;
}
</style>
<script>
window.onload = function(){
var a = document.getElementById("index");
a.onclick=function(){
window.location.href="http://localhost:8080/ssm/userList";
/* 防止页面嵌套 */
if (window.top != window.self) {
top.location.href = "http://localhost:8080/ssm/userList";
}
};
}
</script>
</head>
<body>
<div id="err-500">
<div id="msg">
<span id="emoji"></span>
<span>SSM实现增删改查</span>
</div>
<div id="youcan">
<a id="index">用户列表</a>
</div>
</div>
</body>
</html>
用户列表页面
新增用户页面
用户修改页面
404页面
405页面