当前位置: 代码迷 >> J2EE >> eclipse 如何配置spring MVC,新手 求指导
  详细解决方案

eclipse 如何配置spring MVC,新手 求指导

热度:80   发布时间:2016-04-17 23:34:22.0
eclipse 怎么配置spring MVC,新手 求指导
如题,求告诉指教,小弟初学。
------解决思路----------------------
看这个行不——http://wenku.it168.com/d_001267834.shtml
------解决思路----------------------
http://blog.csdn.net/hankaibo/article/details/7238556   我这正确的配置,进去看看,手把手交你,分给我吧。、
------解决思路----------------------
web.xml

 <!-- SpringMVC配置 -->
  <servlet>
   <servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    <init-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath*:spring/springmvc-servlet.xml</param-value>  
    </init-param>  
   <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
   <servlet-name>springmvc</servlet-name>
   <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <!-- SpringMVC配置 -->
   
  <!-- 指定spring bean的配置文件所在目录,默认配置在WEB-INF目录下 -->
   <!-- 加载所有配置文件 -->
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath*:spring/spring-*.xml</param-value>
  </context-param>
  <!-- 指定spring bean的配置文件所在目录,默认配置在WEB-INF目录下 -->
  
  <!-- spring配置监听 -->
  <listener>
   <listener-class> org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
   <!-- spring配置监听 -->
   
  
  
    <!-- 配置字符集(ps:在提交汉字时用utf-8,不出现乱码) -->  
  <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>  
    <init-param>  
        <param-name>forceEncoding</param-name>  
        <param-value>true</param-value>  
    </init-param>  
  </filter>  
  <filter-mapping>  
    <filter-name>encodingFilter</filter-name>  
    <url-pattern>/*</url-pattern>  
  </filter-mapping>  
    <!-- 配置字符集(ps:在提交汉字时用utf-8,不出现乱码) -->  
  

springmvc-servlet.xml



    <!-- 开启注解 -->
    <mvc:annotation-driven/>
    <!-- 注解扫描包 -->
     <context:component-scan base-package="com.king" />  
  
    <!-- 定义视图解析器 -->    
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/king/"></property>  
        <property name="suffix" value=".jsp"></property>  
    </bean>  

------解决思路----------------------
引用:
web.xml

 <!-- SpringMVC配置 -->
  <servlet>
   <servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    <init-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath*:spring/springmvc-servlet.xml</param-value>  
    </init-param>  
   <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
   <servlet-name>springmvc</servlet-name>
   <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <!-- SpringMVC配置 -->
   
  <!-- 指定spring bean的配置文件所在目录,默认配置在WEB-INF目录下 -->
   <!-- 加载所有配置文件 -->
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath*:spring/spring-*.xml</param-value>
  </context-param>
  <!-- 指定spring bean的配置文件所在目录,默认配置在WEB-INF目录下 -->
  
  <!-- spring配置监听 -->
  <listener>
   <listener-class> org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
   <!-- spring配置监听 -->
   
  
  
    <!-- 配置字符集(ps:在提交汉字时用utf-8,不出现乱码) -->  
  <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>  
    <init-param>  
        <param-name>forceEncoding</param-name>  
        <param-value>true</param-value>  
    </init-param>  
  </filter>  
  <filter-mapping>  
    <filter-name>encodingFilter</filter-name>  
    <url-pattern>/*</url-pattern>  
  </filter-mapping>  
    <!-- 配置字符集(ps:在提交汉字时用utf-8,不出现乱码) -->  
  

springmvc-servlet.xml



    <!-- 开启注解 -->
    <mvc:annotation-driven/>
    <!-- 注解扫描包 -->
     <context:component-scan base-package="com.king" />  
  
    <!-- 定义视图解析器 -->    
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/king/"></property>  
        <property name="suffix" value=".jsp"></property>  
    </bean>  

<servlet-mapping>
      <servlet-name>springmvc</servlet-name>
      <url-pattern>/</url-pattern>
  </servlet-mapping>

我一般这么配
  相关解决方案