I'开发者_开发技巧ve got a Tomcat deployment with a single webapp living inside web/WEB-INF
. Here is the way I'm instantiating the spring container:
<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>
The report-servlet.xml
file is found, loaded and parsed properly.
However, my JSP views do not resolve. Here is my resolver:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
I have the root URL mapped to /welcome:
<!-- Forwards requests to the "/" resource to the "welcome" view -->
<mvc:view-controller path="/" view-name="welcome"/>
And this view is found and delegated to the InternalResourceViewResolver
when I request http://localhost/
, but the .jsp is not found:
[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: org.apache.catalina.core.ApplicationHttpRequest@10ea443f
[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.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping@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 [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@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 [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@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]
And the contents of WEB-INF/views:
# 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
Why would the container have no problem finding the Spring xml file containing my beans, but not be able to resolve the directory containing my JSPs?
Following URL mapping will redirect all the requests to the report
servlet. But You must not have set up handlers for the JSP files in your dispatcher servlet configurations.
<servlet-mapping>
<servlet-name>report</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
To achieve what you want to you must specify the URl pattern that should be redirected to the report
servlet. This must exclude JSp files.
I will suggest you to specify something like a prefix to your URLs. Only those URLs will be handled by the Spring Dispatcher Servlet. As shown in the below example.
<servlet-mapping>
<servlet-name>report</servlet-name>
<url-pattern>/report/*</url-pattern>
</servlet-mapping>
Now, all the URlL with /report/<something>
will be handled by Spring webmvc. This servlet(report
) will bot be applied to the URLs ending with *.jsp.
I decided to answer my question rather than an edit to the OP or as a comment to an unrelated answer.
Turns out Tomcat was configured improperly. I did not have the JSP servlet configured (or the DefaultServlet for that matter), so the JSP views were not being rendered.
精彩评论