将ContextLoaderListener添加到web.xml,然后我的jsp页面出现404错误

时间:2018-12-21 13:26:10

标签: java spring

当我添加

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

到web.xml,然后找不到index.jsp,但是当我删除ContextLoaderListener时,DispatcherServlet可以很好地工作:

<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/resource/spring/springmvc.xml</param-value>
    </init-param>
  </servlet>  

我的项目的完整结构:

enter image description here

和已使用的罐子:

enter image description here

即使我删除了applicationContext.xml中的所有代码,它也无法正常工作,并且tomcat也没有显示任何错误。

这些是web.xml文件中的代码:

 <display-name>schoolbus</display-name>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/resource/spring/applicationContext.xml</param-value>
  </context-param> 
 <!--  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>  -->  
   <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/resource/spring/springmvc.xml</param-value>
    </init-param>
  </servlet>  
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping> 
  <filter>
    <filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>  



  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>

0 个答案:

没有答案