我有一個Tomcat部署,其中包含一個生活在web/WEB-INF
內的webapp。下面是我實例化Spring容器的方式:Spring無法解析JSP視圖
<servlet>
<servlet-name>report</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/report-servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>report</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
的report-servlet.xml
文件中找到,加載並正確解析。
但是,我的JSP視圖無法解析。這裏是我的解析:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
我有根URL映射到/歡迎:
<!-- Forwards requests to the "/" resource to the "welcome" view -->
<mvc:view-controller path="/" view-name="welcome"/>
這種觀點是發現和委託時,我要求http://localhost/
的InternalResourceViewResolver
,但這個.jsp不發現:
[org.springframework.web.servlet.view.InternalResourceView] (http-11080-1) Rendering view with name 'welcome' with model null and static attributes {}
[org.springframework.web.servlet.view.InternalResourceView] (http-11080-1) Forwarding to resource [/WEB-INF/views/welcome.jsp] in InternalResourceView 'welcome'
[org.springframework.web.servlet.DispatcherServlet] (http-11080-1) Bound request context to thread: [email protected]
[org.springframework.web.servlet.DispatcherServlet] (http-11080-1) DispatcherServlet with name 'report' processing GET request for [//WEB-INF/views/welcome.jsp]
[org.springframework.web.servlet.DispatcherServlet] (http-11080-1) Testing handler map [org.springframe[email protected]4ab83be0] in DispatcherServlet with name 'report'
[org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (http-11080-1) No handler mapping found for [/WEB-INF/views/welcome.jsp]
[org.springframework.web.servlet.DispatcherServlet] (http-11080-1) Testing handler map [[email protected]2c1533c8] in DispatcherServlet with name 'report'
[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (http-11080-1) No handler mapping found for [/WEB-INF/views/welcome.jsp]
[org.springframework.web.servlet.DispatcherServlet] (http-11080-1) Testing handler map [[email protected]4268cc6] in DispatcherServlet with name 'report'
[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (http-11080-1) No handler mapping found for [/WEB-INF/views/welcome.jsp]
和WEB-INF的內容/觀點:
# ls -l WEB-INF/views/welcome.jsp
-rw-r--r-- 1 user group 1.2K 2011-05-24 15:43 WEB-INF/views/welcome.jsp
爲什麼容器沒有問題找到包含我的bean的Spring xml文件,但無法解析包含我的JSP的目錄?
你使用的是什麼網址? http:// localhost:8080/welcome?我認爲你需要讓你成爲url-pattern/*,而不是/。 – Kevin 2011-05-25 00:39:51
@Kevin:我更新了我的帖子以包含更多信息。找到根URL並將其映射到解析器,但解析器不加載我的JSP。 – purecharger 2011-05-25 00:47:28