最近学习spring框架,学习中总是磕磕绊绊的,出现这样或者那样的问题,于是就像写一篇笔记,将spring,springmvc,hibernate框架整合的过程,以及简单的实现记录下来,一来加深印象,二来一遍以后忘记好找资料(...)当然,初学者也可以借鉴一下。废话不多说,直接上干货!
平台:eclipse
1.首先看看我整个项目的结构
2.项目开始:开始配置配置文件,主要有web.xml, applicationContext.xml, springmvc这三个文件
web.xml文件如下(主要是配置spring IOC容器,springmvc的dispacherServlet, 编码的格式化:防止出现乱码,SessionFilter过滤器:防止session异常。这里主要注意的是路径问题,由于楼主的配置文件是放在src下的config包中的,所以配置的时候用classpath:包名/配置文件名.xml的形式;如果放在WebContext下,直接写文件名就行, WEB-INF下就是/WEB-INF/文件名.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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>springmvc_1</display-name>
<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>
<!-- 配置spring ioc容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/applicationContext.xml</param-value>
</context-param>
<!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置springmvc 的DispatcherServlet -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<