我一直在研究這一段時間,根本不知道有什麼問題。我在Tomcat 7上部署了一個Spring 3.1 MVC應用程序。通過查看DEBUG輸出,我可以看到1)MVC調度程序servlet獲取所有我需要的URL 2)任何映射到控制器註釋的URL都可以正常工作3)需要映射到JSP獲得一個404.另外,我正在使用JDK 1.7.0_09。我的JSP頁面位於/ WEB-INF/jsp /中。Spring mvc 3.1 tomcat 7 - 404沒有解析jsp,但是控制器註釋工作正常
在此先感謝您提供我可能會丟失的任何提示!
這裏是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
id="WebApp_ID"
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">
<display-name></display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
我試圖改變我的URL模式爲/,/ ,/。,。 「/」似乎是迄今爲止我最遠的地方。此外,我可能是錯的,但我不認爲這個URL是問題,因爲DEBUG日誌顯示所有的URL都會發送到調度程序servlet - 這正是我想要的。
這裏是我的調度員servlet.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!--Tell the servlet where to look for annotated methods-->
<context:component-scan base-package="com.test.web.mvc.ctrl" />
<!--Enables many annotations and searches for @Controller annotated methods etc.. -->
<context:annotation-config />
<!--JSR-303 (Bean validation) support will be detected on classpath and enabled automatically-->
<mvc:annotation-driven />
<!--This tag allows for mapping the DispatcherServlet to "/" (all extensions etc)-->
<mvc:default-servlet-handler/>
<!-- ControllerClassNameHandlerMapping -->
<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/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean class = "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />
</beans>
我試着寄過來的http://localhost:8080/hello
的URL。我的應用程序部署到「/」,儘管DEBUG日誌顯示它正確地確認「/ home」是傳入視圖,但解析器不會將「/ home」視圖映射到/WEB-INF/jsp/hello.jsp名稱。
http://localhost:8080/rest/user/bob_user
很好用,並映射到Controller註釋。
任何幫助將非常感謝!謝謝!
更新: 下面是http://localhost:8080/hello
調試日誌應該翻譯成/WEB-INF/jsp/hello.jsp
2012-11-23 03:45:50,089 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/hello]
2012-11-23 03:45:50,089 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework[email protected]5c9a010c] in DispatcherServlet with name 'dispatcher'
2012-11-23 03:45:50,089 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /hello
2012-11-23 03:45:50,093 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/hello]
2012-11-23 03:45:50,093 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler map [[email protected]49049c10] in DispatcherServlet with name 'dispatcher'
2012-11-23 03:45:50,093 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - No handler mapping found for [/hello]
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler map [or[email protected]17bd11ee] in DispatcherServlet with name 'dispatcher'
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping - No handler mapping found for [/hello]
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler map [[email protected]f212a54] in DispatcherServlet with name 'dispatcher'
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/hello] are [/**]
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/hello] are {}
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/hello] to HandlerExecutionChain with handler [org.spring[email protected]4a61f88e] and 1 interceptor
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler adapter [org.springframework[email protected]1a33f07b]
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler adapter [[email protected]f128ad]
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/hello] is: -1
2012-11-23 03:45:50,095 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
2012-11-23 03:45:50,095 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Cleared thread-bound request context: [email protected]
2012-11-23 03:45:50,095 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
2012-11-23 03:45:50,095 [http-bio-8080-exec-8] DEBUG org.springframework.web.context.support.XmlWebApplicationContext - Publishing event in WebApplicationContext for namespace 'dispatcher-servlet': ServletRequestHandledEvent: url=[/hello]; client=[127.0.0.1]; method=[GET]; servlet=[dispatcher]; session=[D81D9C8BE397827739EB48BC3BB7A35D]; user=[null]; time=[7ms]; status=[OK]
2012-11-23 03:45:50,095 [http-bio-8080-exec-8] DEBUG org.springframework.web.context.support.XmlWebApplicationContext - Publishing event in Root WebApplicationContext: ServletRequestHandledEvent: url=[/hello]; client=[127.0.0.1]; method=[GET]; servlet=[dispatcher]; session=[D81D9C8BE397827739EB48BC3BB7A35D]; user=[null]; time=[7ms]; status=[OK]
您是否啓用了日誌記錄功能?日誌說什麼? –
我將更新帖子以反映調試日誌... – avrao
並且控制器返回'「home」',對吧? –