Spring MVC - Web 流控制器
我有一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在最终状态下尝试此操作
,其中“controllerURL”是控制器侦听的 URL/
Try this in your end state
where 'controllerURL' is the URL that your controller listens to/
混合 Web Flow 和普通 Spring MVC 控制器的最简单方法是在任何流路径之外的 URL 路径注册普通控制器。
例如,以下是我们的配置文件的一些摘录,由
DispatchServlet
的单个实例从web.xml
加载:因此,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 theDispatchServlet
: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.编写一个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.