旅游后台管理系列——SSM框架Web表现层

整合web层

表现层就一个springmvc框架!由springmvc来管理controller,配置文件内容有:

  1. 需要扫描controller
  2. 配置注解驱动
  3. 配置视图解析器

配置完spring-mvc之后不要忘了在web.xml中添加配置:

  1. Spring容器的配置
  2. Springmvc前端控制器的配置
  3. Post乱码过滤器

1)配置spring-mvc.xml文件

<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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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.2.xsd
        http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/mvc 
 		http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
 		
   	
  	<context:component-scan base-package="com.oak.xiyuyou.controller"/>
  	
    
    <mvc:annotation-driven/>
    
    
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        
        <property name="prefix" value="/WEB-INF/"/>
        
        <property name="suffix" value=".jsp"/>
    bean>
beans>

我们springmvc.xml文件中配置的扫描包是com.taotao.controller,因此我们需要创建这么一个目录,并且从视图解析器的配置中可以看出,我们还要在WEB-INF目录下新建一个jsp目录:
旅游后台管理系列——SSM框架Web表现层_第1张图片

2)在web.xml中配置前端控制器和编码过滤器


<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>netctoss0702_ssm_demo05display-name>
  <welcome-file-list>
    <welcome-file>index.htmlwelcome-file>
    <welcome-file>index.htmwelcome-file>
    <welcome-file>index.jspwelcome-file>
    <welcome-file>default.htmlwelcome-file>
    <welcome-file>default.htmwelcome-file>
    <welcome-file>default.jspwelcome-file>
  welcome-file-list>
	  
      <filter>
        <filter-name>encodingFilterfilter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
        <init-param>
            <param-name>encodingparam-name>
            <param-value>UTF-8param-value>
        init-param>
    filter>
    <filter-mapping>
        <filter-name>encodingFilterfilter-name>
        <url-pattern>/*url-pattern>
    filter-mapping>
	
      
	<context-param>
	    <param-name>contextConfigLocationparam-name>
	    <param-value>classpath:spring/applicationContext-*.xmlparam-value>
	context-param>
	<listener>
	    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
	listener>
	
   
   <servlet>
       <servlet-name>springmvcservlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
       <init-param>
           
           <param-name>contextConfigLocationparam-name>
           <param-value>classpath:spring/spring-mvc.xmlparam-value>
       init-param>
   servlet>
   <servlet-mapping>
       <servlet-name>springmvcservlet-name>
       <url-pattern>/url-pattern>
   servlet-mapping>
web-app>

启动项目访问测试即可。

你可能感兴趣的:(旅游后台管理系列——SSM框架Web表现层)