SSM,bootstrap模块,解决controller访问不了的问题,查询,登录注册功能【诗书画唱】
概括:
组合分页查询的效果
UserinfoSqlMap.xml
解决eclipse因为窗口开太多等的切换文件卡的问题
边看教程视频边做的学习记录
代码例子
Oracle数据库部分
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(pattern="yyyy-MM-dd")
/*其实private userCountAllService userCountAllService;
写成private userCountAllService UserCountAllService;
也可以,最好是UserCountAllService的重命名
字母拼写一样,防止报错,Ssm框架做些处理时不会找不到
其内容。
* */
如果访问controller访问不了就是扫描@Controller注解的部分错了
springmvc-servlet.xml中的
<context:component-scan
base-package="com.SSHC.controller">
的base-package的内容写错了
一般一些类的重命名习惯都用小写,比如拼写一样,但首字母是小写
applicationContext.xml是写“扫描”等部分的配置的


@Resource
@RequestMapping("RequestMappingLogin")
@ModelAttribute("SpringWeb")
运行效果





解决eclipse因为窗口开太多等的切换文件卡的问题 START

解决eclipse因为窗口开太多等的切换文件卡的问题 END
边看教程视频边做的学习记录 START




边看教程视频边做的学习记录 END
代码例子 START
Oracle数据库部分:
--drop table Userinfo
create table Userinfo(
id number primary key,
act varchar2(30) not null,
pwd varchar2(30) not null,
birth date
);
--drop sequence seq_Userinfo
create sequence seq_Userinfo
start with 1 --起始值是1
increment by 1 --增长的值
maxvalue 999999999 --序列号的最大值
minvalue 1 --序列号的最小值
nocycle --是否循环
cache 10; --预存
insert into Userinfo values(seq_Userinfo.nextval,'黑黑','pwd1',to_date('2020-06-06','yyyy-mm-dd'));
insert into Userinfo values(seq_Userinfo.nextval,'红红','pwd2',to_date('2020-06-07','yyyy-mm-dd'));
insert into Userinfo values(seq_Userinfo.nextval,'蓝蓝','pwd3',to_date('2020-06-08','yyyy-mm-dd'));
insert into Userinfo values(seq_Userinfo.nextval,'666','pwd4',to_date('2020-06-06','yyyy-mm-dd'));
insert into Userinfo values(seq_Userinfo.nextval,'999','pwd5',to_date('2020-06-10','yyyy-mm-dd'));
insert into Userinfo values(seq_Userinfo.nextval,'888','pwd6',to_date('2020-06-11','yyyy-mm-dd'));
insert into Userinfo values(seq_Userinfo.nextval,'诗书画唱','pwd4',to_date('2020-06-06','yyyy-mm-dd'));
insert into Userinfo values(seq_Userinfo.nextval,'三连','pwd5',to_date('2020-06-10','yyyy-mm-dd'));
insert into Userinfo values(seq_Userinfo.nextval,'关注','pwd6',to_date('2020-06-11','yyyy-mm-dd'));
insert into Userinfo values(seq_Userinfo.nextval,'诗书画唱1','pwd4',to_date('2020-06-06','yyyy-mm-dd'));
insert into Userinfo values(seq_Userinfo.nextval,'诗书画唱2','pwd4',to_date('2020-06-06','yyyy-mm-dd'));
--select * from Userinfo


package com.SSHC.bean;
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;
public class Userinfo {
private Integer id;
private String act;
private String pwd;
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(pattern="yyyy-MM-dd")
private Date birth;
private Integer page;
private Integer rows;
private Integer start;
private Integer end;
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(pattern="yyyy-MM-dd")
private Date sbirth;
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(pattern="yyyy-MM-dd")
private Date ebirth;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAct() {
return act;
}
public void setAct(String act) {
this.act = act;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getStart() {
return start;
}
public void setStart(Integer start) {
this.start = start;
}
public Integer getEnd() {
return end;
}
public void setEnd(Integer end) {
this.end = end;
}
public Date getSbirth() {
return sbirth;
}
public void setSbirth(Date sbirth) {
this.sbirth = sbirth;
}
public Date getEbirth() {
return ebirth;
}
public void setEbirth(Date ebirth) {
this.ebirth = ebirth;
}
}


package com.SSHC.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import com.SSHC.bean.Userinfo;
import com.SSHC.service.PublicService;
@Controller
public class LoginController {
@Resource
private PublicService publicService;
@RequestMapping("RequestMappingLogin")
public String doLogin(@ModelAttribute("SpringWeb") Userinfo u
,HttpSession session,Model m){
u = publicService.login(u);
if(u != null && u.getId() > 0) {
session.setAttribute("_user", u);
return "index";
} else {
m.addAttribute("msg","登录失败");
return "login";
}
}
}


package com.SSHC.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import com.SSHC.bean.Userinfo;
import com.SSHC.service.PublicService;
@Controller
public class RegisterController {
@Resource
private PublicService publicService;
@RequestMapping("RequestMappingRegister")
public String doRegister(@ModelAttribute("SpringWeb") Userinfo u
,HttpSession session,Model m){
Integer count= publicService.register(u);
System.out.println("count:"+count);
if(count != null ) {
m.addAttribute("msg","注册成功!");
return "login";
} else {
m.addAttribute("msg","注册失败!");
return "register";
}
}
}


package com.SSHC.controller;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.SSHC.bean.Userinfo;
import com.SSHC.service.UserCountAllService;
@Controller
public class UserController {
@Resource
private UserCountAllService userCountAllService;
@RequestMapping(value = "ld",method = RequestMethod.GET)
public @ResponseBody Map<String,Object>loadData
(@ModelAttribute("SpringWeb") Userinfo u){
System.out.println("每页显示:" + u.getRows());
System.out.println("显示第" + u.getPage() + "页的数据");
System.out.println("输入的查询账号是:" + u.getAct());
System.out.println(u.getSbirth());
System.out.println(u.getEbirth());
//乱码处理
String act = u.getAct();
try {
if(act != null) {
act = new String(act.getBytes("iso8859-1"),"utf-8");
System.out.println(act);
act = "%" + act + "%";
u.setAct(act);
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Map<String,Object>map = new HashMap<String,Object>();
List<Userinfo>list = userCountAllService.loadAll(u);
map.put("rows", list);
map.put("total", userCountAllService.countAll(u));
return map;
}
}


package com.SSHC.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.SSHC.bean.Userinfo;
@Repository
public interface UserinfoDao {
List<Userinfo> selectAll(Userinfo u);
Userinfo selectByActAndPwd(Userinfo u);
List<Userinfo> totalAll(Userinfo u);
Integer add(Userinfo u);
}


<?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">
<!-- namespace不能乱写,必须写成IUserinfoDao接口的全路径 -->
<mapper namespace="com.SSHC.dao.UserinfoDao">
<sql id="query">
<where>
<if test="act != null and act.length() > 0">
and act like #{act}
</if>
<if test="sbirth != null">
and birth >= #{sbirth}
</if>
<if test="ebirth != null">
and birth <= #{ebirth}
</if>
</where>
</sql>
<resultMap type="Userinfo" id="rmUserinfo">
<id property="id" column="ID"/>
<result property="act" column="ACT"/>
<result property="pwd" column="PWD"/>
<result property="birth" column="BIRTH"/>
</resultMap>
<select id="selectAll" resultMap="rmUserinfo" parameterType="Userinfo">
select * from
(
select t1.*,rownum rn from
(select * from userinfo
<include refid="query"></include>
) t1
where rownum <= #{end}
)
where rn >= #{start}
</select>
<!-- List<Userinfo> totalAll(Userinfo u) -->
<select id="totalAll" resultMap="rmUserinfo" parameterType="Userinfo">
select * from userinfo
<include refid="query"></include>
</select>
<!-- Userinfo selectByActAndPwd(String act,String pwd) -->
<select id="selectByActAndPwd" resultMap="rmUserinfo"
parameterType="Userinfo">
select * from userinfo where act = #{act}
and pwd = #{pwd}
</select>
<insert id="add" parameterType="Userinfo">
insert into Userinfo values
(seq_Userinfo.nextval,#{act},#{pwd},#{birth})
</insert>
</mapper>


package com.SSHC.service;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.SSHC.bean.Userinfo;
import com.SSHC.dao.UserinfoDao;
@Service
@Transactional
public class PublicService {
//属性名就是接口名的首字母改成小写
@Resource
private UserinfoDao userinfoDao;
//登录方法
public Userinfo login(Userinfo u){
return userinfoDao.selectByActAndPwd(u);
}
public Integer register(Userinfo u){
Integer count=userinfoDao.add(u);
return count;
}
}


package com.SSHC.service;
import java.util.List;
import com.SSHC.bean.Userinfo;
public interface UserCountAllService {
List<Userinfo>loadAll(Userinfo u);
Integer countAll(Userinfo u);
}


package com.SSHC.service;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.SSHC.bean.Userinfo;
import com.SSHC.dao.UserinfoDao;
@Service
@Transactional
public class UserService implements UserCountAllService {
@Resource
private UserinfoDao userinfoDao;
@Override
public List<Userinfo> loadAll(Userinfo u) {
// TODO Auto-generated method stub
//处理分页参数
Integer page = u.getPage();
Integer rows = u.getRows();
Integer start = (page - 1) * rows + 1;
Integer end = page * rows;
u.setStart(start);
u.setEnd(end);
return userinfoDao.selectAll(u);
}
@Override
public Integer countAll(Userinfo u) {
// TODO Auto-generated method stub
List<Userinfo>list = userinfoDao.totalAll(u);
return list.size();
}
}


oracle_drivername=oracle.jdbc.driver.OracleDriver
oracle_url=jdbc:oracle:thin:@localhost:1521:orcl
oracle_username=X
oracle_password=sshcPwd


log4j.rootLogger=DEBUG,Console
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d[%t] %-5p [%c] - %m%n
log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

<?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.SSHC.bean"/>
</typeAliases>
</configuration>



$(function(){
var oTable = new TableInit();
oTable.init();
//给查询按钮绑定点击事件
$('#btn_query').click(function(){
//刷新表格(会进行分页)
$("#tb_userinfo").bootstrapTable('refresh');
});
})
var TableInit = function(){
var objTable = {};
//定义表格的初始化的方法
objTable.init = function(){
$('#tb_userinfo').bootstrapTable({
url: 'ld', //请求后台的URL(*)
method: 'get', //请求方式(*)
contentType: "application/x-www-form-urlencoded",
dataType:'json',//返回的数据类型必须是json对象
toolbar: '#toolbar', //工具按钮用哪个容器
striped: true, //是否显示行间隔色
cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
pagination: true, //是否显示分页(*)
sortable: false, //是否启用排序
sortOrder: "asc", //排序方式,asc是升序,desc是降序
queryParams: function(params) {
//获取查询输入的条件
var act = $('#s_act').val();
var startBirth = $('#s_birth_start').val();
var endBirth = $('#s_birth_end').val();
var temp = { //这里的键的名字和控制器的变量名必须一致,这边改动,控制器也需要改成一样的
rows: params.limit, //页面大小
page: (params.offset / params.limit) + 1, //页码
act: act,
sbirth: startBirth,
ebirth: endBirth
};
return temp;
}, //传递参数的方法(*)
sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
pageNumber: 1, //初始化加载第一页,默认第一页
pageSize: 5, //每页的记录行数(*)
pageList: [2, 3, 5, 10], //可供选择的每页的行数(*)
search: true, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
strictSearch: true,
showColumns: true, //是否显示所有的列
showRefresh: true, //是否显示刷新按钮
minimumCountColumns: 2, //最少允许的列数
clickToSelect: true, //是否启用点击选中行
height: 700, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度
uniqueId: "ID", //每一行的唯一标识,一般为主键列
showToggle: true, //是否显示详细视图和列表视图的切换按钮
cardView: false, //是否显示详细视图
detailView: false, //是否显示父子表
onClickRow: function (row) {//点击表格中的某一行时触发这个函数
console.log(row);
},
columns: [{
checkbox: true
}, {
field: 'id',
title: '编号'
}, {
field: 'act',
title: '账号'
}, {
field: 'birth',
title: '生日'
}]
});
}
return objTable;
}


<?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"
xmlns:tx="http://www.springframework.org/schema/tx"
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-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- 配置扫描注解,不扫描带有@Controller注解的类 -->
<context:component-scan base-package="com.SSHC">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 引入db.properties文件 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:db.properties"/>
</bean>
<!--数据库连接池配置-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${oracle_drivername}"/>
<property name="url" value="${oracle_url}"/>
<property name="username" value="${oracle_username}"/>
<property name="password" value="${oracle_password}"/>
</bean>
<!-- 创建sqlSessionFactory对象 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 指定数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- 指定mybatis框架主配置文件的位置 -->
<property name="configLocation" value="classpath:mybatis.xml"/>
<!-- 自动扫描mapping.xml文件,**表示迭代查找 ,,也可在mybatis.xml中单独指定xml文件 -->
<property name="mapperLocations" value="classpath:com/SSHC/dao/*.xml"/>
</bean>
<!-- 自动扫描com/SSHC/dao下的所有dao接口,并实现这些接口,
可直接在程序中使用dao接口,不用再获取sqlsession对象 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- basePackage 属性是映射器接口文件的包路径。
你可以使用分号或逗号 作为分隔符设置多于一个的包路径-->
<property name="basePackage" value="com/SSHC/dao"/>
<!-- 因为会自动装配 SqlSessionFactory和SqlSessionTemplate
所以没有必要去指定SqlSessionFactory或 SqlSessionTemplate
因此可省略不配置;
但是,如果你使用了一个以上的 DataSource,那么自动装配可能会失效。
这种情况下,你可以使用sqlSessionFactoryBeanName或sqlSessionTemplateBeanName属性
来设置正确的 bean名称来使用 -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 使用声明式事务 transaction-manager:引用上面定义的事务管理器 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>


<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/bootstrap-table.css">
<script type="text/javascript" srcc="js/jquery-1.11.0.js"></script>
<script type="text/javascript" srcc="js/bootstrap.js"></script>
<script srcc="js/bootstrap-table.js"></script>
<script srcc="js/bootstrap-table-zh-CN.js"></script>
<script type="text/javascript" srcc="selfjs/index.js"></script>
</head>
<body>
<div class="panel-body" style="padding-bottom:0px;">
<!-- 查询面板 -->
<div class="panel panel-default">
<div class="panel-heading">查询条件</div>
<div class="panel-body">
<form id="formSearch" class="form-horizontal">
<div class="form-group" style="margin-top:15px">
<label class="control-label col-sm-1" for="s_act">账号</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="s_act">
</div>
<label class="control-label col-sm-1" for="s_birth">生日起始</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="s_birth_start">
</div>
<label class="control-label col-sm-1" for="s_birth">到</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="s_birth_end">
</div>
<div class="col-sm-3" style="text-align:left;">
<button type="button" style="margin-left:50px" id="btn_query" class="btn btn-primary">查询</button>
</div>
</div>
</form>
</div>
</div>
<!-- 表格上方的工具栏 -->
<div id="toolbar" class="btn-group">
<button id="btn_add" type="button" class="btn btn-default">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
</button>
<button id="btn_edit" type="button" class="btn btn-default">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
</button>
<button id="btn_delete" type="button" class="btn btn-default">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
</button>
</div>
<!-- 数据展示 -->
<table id="tb_userinfo"></table>
</div>
</body>
</html>


<style type="text/css">
*{
font-size: 50px;
}
</style>
</head>
<body>
<form action="RequestMappingLogin" method="post">
<label>账号:</label><input type="text" name="act"/>
<br>
<label>密码:</label><input type="password" name="pwd"/>
<br>
<input type="submit" value="登录" />
还没有注册?
<a href="http://localhost:8080/Ssmbootstrap1/toRegister">注册</a>
</form>
<div>${msg }</div>
</body>
</html>


<style type="text/css">
*{
font-size: 50px;
}
</style>
</head>
<body>
<form action="RequestMappingRegister" method="post">
<label>账号:</label><input type="text" name="act"/>
<br>
<label>密码:</label><input type="password" name="pwd"/>
<br>
<label>生日:</label><input type="date" name="birth"/>
<br>
<input type="submit" value="注册" />
已经注册?
<a href="http://localhost:8080/Ssmbootstrap1/toLogin">登录</a>
</form>
<div>${msg }</div>
</body>
</html>


<?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-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!-- 扫描@Controller注解 -->
<context:component-scan base-package="com.SSHC.controller">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 默认注册RequestMappingHandlerMapping和RequestMappingHandlerAdapter类 -->
<mvc:annotation-driven />
<!-- jsp引用外部js,css等静态资源的解决方法(和上面的标签必须同时出现,否则无法访问url) -->
<mvc:default-servlet-handler />
<!-- 配置视图名称解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<!-- 前缀 -->
<!-- 将所有的jsp文件存放在/WEB-INF/my/目录下 -->
<property name="prefix" value="/WEB-INF/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
<!-- 优先级设定 -->
<property name="order" value="10"></property>
</bean>
<!-- http://localhost:8080/Ssmbootstrap1/toLogin -->
<mvc:view-controller path="/toLogin" view-name="login"/>
<!-- http://localhost:8080/Ssmbootstrap1/toRegister -->
<mvc:view-controller path="/toRegister" view-name="register"/>
<!-- http://localhost:8080/Ssmbootstrap1/toIndex -->
<mvc:view-controller path="/toIndex" view-name="index"/>
</beans>

<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Ssmbootstrap1</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

运行效果:
登录:http://localhost:8080/Ssmbootstrap1/toLogin
注册:http://localhost:8080/Ssmbootstrap1/toRegister
主页:http://localhost:8080/Ssmbootstrap1/toIndex
主页:http://localhost:8080/Ssmbootstrap1/index.jsp









