Spring MVC - Web 流控制器

发布于 2024-08-18 06:01:20 字数 1741 浏览 9 评论 0原文

我有一个使用 spring 框架和 spring webflow 开发的 j2ee 应用程序。目前我的所有 url 请求都经过 Web Flow。我想要的是能够选择是将其定向到Web Flow还是普通的spring mvc控制器。我不知道如何将其定向到自定义控制器。我该怎么做?

我尝试将其放在 web.xml 中,但无法将其定向到 mytest2-servlet.xml 中指定的 bean 控制器

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情绪少女 2024-08-25 06:01:20

在最终状态下尝试此操作

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

,其中“controllerURL”是控制器侦听的 URL/

Try this in your end state

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

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

你的呼吸 2024-08-25 06:01:20

混合 Web Flow 和普通 Spring MVC 控制器的最简单方法是在任何流路径之外的 URL 路径注册普通控制器。

例如,以下是我们的配置文件的一些摘录,由 DispatchServlet 的单个实例从 web.xml 加载:

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

因此,WebFlow 将注册与WEB-INF/**/something-flow.xml 文件和所有其他 URL 路径(如上面的 /selectLanguage)可以由常规控制器处理。

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.

时间你老了 2024-08-25 06:01:20

编写一个dispatcher-sevlet.xml或配置文件,为Spring Flows编写一个单独的配置文件(为了方便)只需导入dispatcher-servlet.xml中的文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文