springmvc 在 web.xml配置

 

org.springframework.web.servlet.DispatcherServlet  指定springmvc配置文件mvc-servlet.xml

org.springframework.web.context.ContextLoaderListener  web上下文监听器初始化配置文件如数据源等

org.springframework.web.filter.CharacterEncodingFilter web自带的编码过滤器

  • 在web.xml 文件中

<!-- spring mvc 配置 -->
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<!-- 加载上下文 配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:base.xml
</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

 

<!-- spring编码过滤器 -->
<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>*.do</url-pattern>
</filter-mapping>

 

  • 在mvc-servlet.xml文件中

<!-- spring mvc 注解驱动 -->
<mvc:annotation-driven/>
<context:component-scan base-package="mvc.*"/>

<!-- 内部视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>

posted @ 2017-03-24 18:55  gnim  阅读(184)  评论(0编辑  收藏  举报