我有一个使用Spring Web Flow的应用程序。这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
</web-app>
servlet-context.xml中我的流程的定义:
<beans:bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<beans:property name="mappings">
<beans:value>inicio.do=flowController</beans:value>
</beans:property>
<beans:property name="alwaysUseFullPath" value="true"></beans:property>
</beans:bean>
<beans:bean id="flowcontroller" class="org.springframework.webflow.mvc.servlet.FlowController">
<beans:property name="flowExecutor" ref="flowExecutor"></beans:property>
</beans:bean>
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/>
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location id="inicio" path="/WEB-INF/flujos/flujo.xml"/>
</webflow:flow-registry>
<webflow:flow-builder-services id="flowBuilderServices"
view-factory-creator="viewFactoryCreator"/>
<beans:bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<beans:property name="viewResolvers">
<beans:list>
<beans:ref bean="viewResolver"/>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<beans:property name="flowExecutor" ref="flowExecutor"></beans:property>
</beans:bean>
该流程由另一个JSP与重定向相关联。当用户点击应该导致流程的链接时,&#34; startflow.jsp&#34;被调用,它有一个重定向到流,这样:
<c:redirect url="inicio.do"></c:redirect>
现在,我收到一个404错误页面,说myapp / inicio.do不可用。我做错了什么?有谁能够帮我?谢谢。
答案 0 :(得分:0)
您的调度程序servlet appServvlet映射到 * .action (请参阅web.xml中的.action扩展名),其中您映射到 inicio.do 的SimpleUrlHandlerMapping中。
这是它的工作原理:
1)服务器知道哪个servlet应该处理请求,具体取决于请求url和web.xml中的servlet映射。
2)DispatcherServlet接收请求并检查HandlerMapping并调用与请求关联的Controller。
3)如果定义了FlowController,dispactherServlet将根据处理程序映射配置向其委托请求。
但是没有与您的请求匹配的servletmapping,因为没有映射到* .do。
因此,请将重定向更改为:
<c:redirect url="/inicio.action"></c:redirect>
并映射到:
<beans:value>inicio.action=flowController</beans:value>