UrlFilenameViewController does not return View (Spring-MVC)

来源:互联网 发布:费列罗巧克力淘宝 编辑:程序博客网 时间:2024/06/07 19:48

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 theSimpleUrlHandlerMapping 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>

0 0