Question

Selon l'API du framework Spring

Le but de UrlFilenameViewViewController est:

  

Transforme le chemin virtuel d'une URL en un nom de vue et renvoie cette vue

Si je demande pour /info.xhtml, son nom de vue logique est info

Voir UrlFilenameViewController documentation

Le fichier web.xml et le contrôleur sont mappés conformément à

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

Mon application smac se déploie correctement.

Donc, si je demande un http://127.0.0.1:8080/smac/info .xhtml , Spring-MVC devrait renvoyer /WEB-INF/output/info.jsp. Mais j'ai vu dans la console ce qui suit:

  

Aucun mappage trouvé pour la requête HTTP avec l'URI [/smac/info.xhtml] dans DispatcherServlet avec le nom 'controller'

Quelqu'un pourrait-il m'aider?

salutations

Était-ce utile?

La solution

Vous devez configurer un HandlerMapping . La valeur par défaut est BeanNameUrlHandlerMapping , qui ne fera que ce que vous voulez si vous liez le bean de votre contrôleur sous le nom correspondant à votre URI. Vous voulez probablement le SimpleUrlHandlerMapping à la place:

<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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top