Spring WebFlow:如何在JSP中获取请求参数?

发布于 2024-10-27 22:05:31 字数 774 浏览 1 评论 0原文

我将 Spring WebFlow 与 Spring MVC 一起使用。当我请求页面时 http://localhost:8080/testapp/index.html?param=100 WebFlow 重定向到 http://localhost:8080/testapp/index.html ?execution=e3s1 并且无法在jsp中获取paramparam在某处丢失。如何让它发挥作用?

这种情况的另一个例子 - Spring Security 配置如下:

<security:form-login authentication-failure-url="/login.html?loginfail=1" login-page="/login.html" />

当登录失败时,我无法在 login.jsp 中获取 loginfail 参数。

<c:if test="${!empty param.loginfail}">Login error!</c:if>

我可以访问流中的请求参数,但是...我是否必须为所有请求参数设置视图/flowScope 变量,如下所示?

<set name="viewScope.loginfail" value="requestParameters.loginfail" />

I'm using Spring WebFlow together with Spring MVC. When i request page for example http://localhost:8080/testapp/index.html?param=100 WebFlow make redirect to http://localhost:8080/testapp/index.html?execution=e3s1 and can't get param in jsp, param lost somewhere. How to get this working ?

Another example of this situation - Spring Security configured like below:

<security:form-login authentication-failure-url="/login.html?loginfail=1" login-page="/login.html" />

When login fail, i can't get loginfail parameter in login.jsp.

<c:if test="${!empty param.loginfail}">Login error!</c:if>

I can access request parameters in flow, but... Do i have to set view/flowScope variables for all my request parameters like below ?

<set name="viewScope.loginfail" value="requestParameters.loginfail" />

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

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

发布评论

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

评论(2

剪不断理还乱 2024-11-03 22:05:31

回答有关 Spring WebFlow (SWF) 和请求参数的一般性问题:

收到您的第一个请求(包括请求参数)后,Spring WebFlow 会向您的浏览器发送 302 重定向,这会强制执行另一个 GET。此 GET 请求不包含您的原始请求参数。正如您所指出的,您可以使用流程逻辑中的 requestParameters 映射来访问这些参数。然后,您可以在 viewScope 或 requestScope 上设置请求参数,但您应该问自己为什么需要在 JSP 中获取这些请求参数。

您在视图层(JSP)中执行的逻辑是否确实应该在控制器层(Web 流)中执行?您是否需要绑定到模型对象(使用视图状态上的模型属性)?

如果您只处理单个参数,那么您可能可以将其设置在视图或请求范围中。但如果您有多个,也许您需要一个可用作模型属性的命令对象。 SWF 将处理将参数绑定到该对象,并将该对象公开给您重定向到的视图。

更具体地说,关于Spring Security/登录:

看来您可能正在尝试将登录页面实现为实际的Webflow...我会看一下SWF文档,它有一个简短的章节关于保护网络流。登录页面/流程不会定义为流程中的状态。

To answer your generic question about Spring WebFlow (SWF) and request parameters:

After receiving your first request (that includes the request parameter), Spring WebFlow is sending your browser a 302 redirect which forces another GET. This GET request does not include your original request parameters. Like you noted, you can access these parameters using the requestParameters map in your flow logic. You can then set request parameters on the viewScope or requestScope, but you should ask yourself why you need to get at these request parameters in your JSP.

Is there logic you are performing in your view layer (JSP), that should really be performed in the controller layer (web flow)? Do you need to be binding to a model object (using the model attribute on view-state)?

If you are only dealing with a single parameter, then you are probably ok to just set it in the view or request scope. But if you have several, maybe you need a command object that you can use as your model attribute. SWF would handle binding the parameters to this object, and would expose this object to the view that you are redirected to.

More specifically, regarding Spring Security/login:

It appears that you may be trying to implement your login page as an actual webflow... I would take a look at the SWF documentation, it has a short chapter about securing webflows. The login page/process would not be defined as a state in your flow.

倾`听者〃 2024-11-03 22:05:31

可以添加ie.

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/webflow
                          http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

    <input name="param" required="true" />

    <on-start>
        <evaluate expression="someAction.getSomething(param)" result="conversationScope.myParam"/>
    </on-start>
    ...

到您的流程。

You can add ie.

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/webflow
                          http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

    <input name="param" required="true" />

    <on-start>
        <evaluate expression="someAction.getSomething(param)" result="conversationScope.myParam"/>
    </on-start>
    ...

to your flow process.

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