mvc:view-controller 导致 Spring Tiles2 中的 PageNotFound
我有一个基于 Spring 3.0.6 的 web 应用程序,它在 Tomcat 7.0 上运行良好。
web.xml
定义调度程序如下:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
调度程序以通常的方式定义视图解析器:
<bean id="tilesViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles-def.xml</value>
</list>
</property>
</bean>
我有一个用 @RequestMapping("/home")
注释的控制器,并且在 tiles-def.xml
中定义的 "home"
视图。当我将浏览器指向 /myapp/home.html
时,Tiles 页面将打开。
如果我添加
或
到我的调度程序 xml 文件,将浏览器指向 /myapp/home.html
结果是 404。日志显示:
21:34:22,128 WARN PageNotFound:947 – No mapping found for HTTP request with URI [/myapp/home.html] in DispatcherServlet with name 'dispatcher'
What am我做错了吗?
多谢
I have a webapp based on Spring 3.0.6 which works fine on Tomcat 7.0.
The web.xml
defines the dispatcher as following:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
The dispatcher defines the view resolver in the usual way:
<bean id="tilesViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles-def.xml</value>
</list>
</property>
</bean>
I have a controller annotated with @RequestMapping("/home")
and a "home"
view defined in tiles-def.xml
. When I point my browser to the /myapp/home.html
, the Tiles page is opened.
If I add <mvc:resources mapping="/resources/**" location="/resources/" />
or <mvc:view-controller path="/" view-name="home.html"/>
to my dispatcher xml file, pointing the browser to /myapp/home.html
results in a 404. The log says:
21:34:22,128 WARN PageNotFound:947 – No mapping found for HTTP request with URI [/myapp/home.html] in DispatcherServlet with name 'dispatcher'
What am I doing wrong?
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的应用程序中的问题是由于自动视图名称解析造成的。我的
@Controller
中带注释的方法返回了void
,并且框架尝试使用请求路径猜测图块视图名称。我将带注释的方法修改如下,返回一个
String
:通过此更改,一切正常。
The problem in my application was due to the automatic view name resolution. My annotated method in my
@Controller
returnedvoid
, and the framework tried to guess the tiles view name using the request path.I modified my annotated method as following, returning a
String
:With this change, everything works fine.