Domanda

Secondo l'API del framework Spring

Lo scopo di UrlFilenameViewController è:

  

Trasforma il percorso virtuale di un URL in un nome di vista e restituisce tale vista

Se richiedo /info.xhtml, il nome della sua vista logica è info

Vedi UrlFilenameViewController documentazione

Sia web.xml che il controller sono mappati secondo

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

La mia app smac si installa bene.

Quindi, se richiedo http://127.0.0.1:8080/smac/info .xhtml , Spring-MVC dovrebbe restituire /WEB-INF/output/info.jsp. Ma ho visto in console quanto segue:

  

Nessun mapping trovato per la richiesta HTTP con URI [/smac/info.xhtml] in DispatcherServlet con nome 'controller'

Qualcuno potrebbe aiutarmi?

saluti,

È stato utile?

Soluzione

Devi configurare un HandlerMapping . Uno di default è BeanNameUrlHandlerMapping che farà solo quello che vuoi se leghi il tuo bean controller con il nome corrispondente al tuo URI. Probabilmente vuoi invece SimpleUrlHandlerMapping :

<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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top