您的位置:首页 > 编程语言 > Java开发

UrlFilenameViewController does not return View (Spring-MVC)

2015-03-18 13:52 330 查看
According to Spring framework API

UrlFilenameViewController's purpose is:

Transforms the virtual path of a URL into a view name and returns that view

If i request for /info.xhtml, its logical view name is info

See
UrlFilenameViewController documentation

Both web.xml and controller is mapped according to

/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8">
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>smac</display-name>
<servlet>
<servlet-name>controller</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>controller</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>

/WEB-INF/controller-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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean class="org.springframework.web.servlet.view.InternalViewResolver">
<property name="prefix" value="/WEB-INF/output/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
</beans>

My smac app deploys fine.

So, if i request for http://127.0.0.1:8080/smac/info.xhtml, Spring-MVC should return /WEB-INF/output/info.jsp. But i have seen in console the following:

No mapping found for HTTP request with URI [/smac/info.xhtml] in DispatcherServlet with name 'controller'

Could anyone help me ?

regards,

You need to configure a
HandlerMapping. Default one is
BeanNameUrlHandlerMapping
which will only do what you want if you bind your controller bean under the name matching your URI. You probably want the
SimpleUrlHandlerMapping
instead:

<bean name="myController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/**/*.xhtml=myController
</value>
</property>
</bean>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring mvc spring java