Spring MVC - Could not get RequestDispatcher [dupl

2019-07-23 15:33发布

问题:

This question already has an answer here:

  • How does the DispatcherServlet, Resolver and Controllers interact? 2 answers

I got a problem on my Spring MVC application.

The problem only happens on the linux server, on local (windows 7 + eclipse), everything works fine.

When I access my page, the controller is called but when the server has to serve the jsp page, i've got :

HTTP Status 500 - Could not get RequestDispatcher for [/WEB-INF/pages/index.jsp]: Check that the corresponding file exists within your web application archive!

The file exist, the path is fine.

Here an extract from my web.xml

    <servlet>
    <servlet-name>cms-admin-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>cms-admin-dispatcher</servlet-name>
        <url-pattern>/do/*</url-pattern>
  </servlet-mapping>


  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/cms-admin-dispatcher-servlet.xml</param-value>
  </context-param>

and my servlet dispatcher :

<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/pages/" />
    <property name="suffix" value=".jsp" />
</bean>

I tried to replace my /do/* pattern by *.html but there is no change. I also tried to put my jsp outside WEB-INF.

I tried :

<servlet>
        <servlet-name>jsp</servlet-name>
    <jsp-file>/WEB-INF/pages/index.jsp</jsp-file>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>

</servlet>

<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>/toto</url-pattern>
</servlet-mapping>

That works, the jsp page is loaded but not resources.

Other thing, I am unable to access any js file directly (resources/js/logs.js, outside the WEB-INF). I get a 404, on local I get my file.

I have pretty no idea where this is coming from, again, it works perfectly on my local. The tomcat config is pretty common. so thanks for advance for any ideas.

回答1:

The Tomcat unable to find jsp in war file post give me the problem.

The default web.xml (on the $CATALINA_BASE/conf/web.xml) was missing. The result was that default operation and servlet wasn't properly made up.

http://tomcat.apache.org/tomcat-7.0-doc/default-servlet.html

I just added it to the conf folder of my tomcat to fix the problem.