spring mvc框架 遇到的问题

web.xml配置文件代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <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>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext*.xml</param-value>
    </context-param>
    <!-- 启动spring  通过ContextLoaderListener去管理bean的注入 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>    
    <!-- spring dispatcher配置    下面的[servlet-name]会被用到-->
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>    
    <!-- spring dispatcher配置 -->
</web-app>

需要说明的是配置了servlet,在WEB-INF目录下应该有个[servlet-name]-servlet.xml文件,用于配置controller
之前一直出现找不到/WEB-INF/spring-servlet.xml错误,是因为把它和applicationContext.xml放到了一起,编译过后出现在了WEB-INF/classes文件夹下面
开始还以为是jar包错了...... 不过总算是解决了,先记下来,再遇到这个错误就知道咋回事儿了

需要说明的是spring mvc 默认在WEB-INF目录查找[servlet-name]-servlet.xml文件。

也可以是用如下代码配置

    <!-- spring mvc -->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/conf/springmvc-servlet.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

 

http://www.blogjava.net/pengo/archive/2010/11/28/339229.html

http://pan.baidu.com/share/link?shareid=1678697094&uk=3003533519

posted @ 2013-09-21 15:21  流转的岁月  阅读(381)  评论(0编辑  收藏  举报