开发者

Spring MVC - Web Flow Controller

I have a j2ee application developed using spring framework and spring webflow. Currently all of my url requests go through the Web Flow. What I want is to be able to choose whether to direct it to Web Flow or an ordinary spring mvc controller. I have no idea how to direct it to custom controllers. How do I do this?

I tried having this in my web.xml but i can't direct it to the bean controller specified in mytest2-servlet.xml

<servlet>
    <servlet-name>mytest</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet>
    <开发者_如何学JAVAservlet-name>mytest2</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation2</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>


<servlet-mapping>
    <servlet-name>mytest</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>mytest2</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/web-application-config.xml
</param-value>
</context-param>

<context-param>
    <param-name>contextConfigLocation2</param-name>
    <param-value>
        /WEB-INF/mytest2-servlet.xml
</param-value>
</context-param>


Try this in your end state

<end-state id="exit" view="externalRedirect:controllerURL" />

where 'controllerURL' is the URL that your controller listens to/


The simplest way to mix both Web Flows and plain Spring MVC Controllers is to simply register the plain Controllers at URL paths outside any of your flow paths.

For instance, here are some excerpts from our configuration files, loaded from web.xml by the single instance of the DispatchServlet:

<!-- Simple URL-view mapping without controller (or flow) -->
<mvc:view-controller path="/selectLanguage" view-name="selectLanguage"/>

<!-- Maps request paths to flows in the flowRegistry;
     e.g. a path of /hotels/booking looks for a flow with id "hotels/booking". -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping" p:order="-1">
    <property name="flowRegistry" ref="flowRegistry" />
    <property name="interceptors">
        <list>
            <!-- for each flow, if a param lang=xx is added, switch locales -->
            <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
                  p:paramName="lang"/>
        </list>
    </property>
</bean>

<!-- The registry of executable flow definitions -->
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF">
    <!-- Flows created from all -flow.xml files, with the flow ID being the path name -->
    <webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>

So WebFlow will register all URL paths that correspond to a WEB-INF/**/something-flow.xml file, and all other URL paths, like /selectLanguage above, can be handled by a regular Controller.


write a dispatcher-sevlet.xml or configuration file, write a separate configuration file ( for convenience ) for Spring Flows just import the files in dispatcher-servlet.xml.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜