gpt4 book ai didi

java - 使用 Spring web-flow 中的链接在 Web 流中进行数据传输

转载 作者:行者123 更新时间:2023-12-01 23:29:25 25 4
gpt4 key购买 nike

我正在尝试创建 Spring Web Flow 应用程序。我有以下情况:

flow1.xml

<var name="user" class="com.test.User" />

<view-state id="signup" model="user">
<transition on="loginCredentialsEntered" to="lookupUser" />
</view-state>

<decision-state id="lookupUser">
<if test="myActionBean.lookupUser(user)"
then="userRegistered" else="registerUser" />
</decision-state>

signup.jsp:

<html xmlns:form="http://www.springframework.org/tags/form">
<body>
<form action="&_eventId=loginCredentialsEntered" method="post">
<input type="hidden" name="_flowExecutionKey" value=""/>
<table>
<tr>
<td>Login Name:</td>
<td><input type="text" name="loginName"/></td>
</tr>
</table>
<input type="submit" value="Login" />
</form>
</body>
</html>

在方法 myActionBean.lookupUser(user) 中,我可以看到正在传递在表单中输入的 user.loginName。

但是,如果我使用链接而不是按钮来提交表单

<a href="${flowExecutionUrl}&_eventId=loginCredentialsEntered">Login</a>

我可以看到 user.loginName 为 null。

谁能解释一下原因和解决方法

提前致谢

最佳答案

那是因为表单没有提交到任何地方。
Form 标记更改为:

<form action="${flowExecutionUrl}&_eventId=loginCredentialsEntered" 
method="post">

它会起作用的。

顺便说一句,您不应该像这样使用 URL 传递参数,最好执行与 _flowExecutionKey 相同的操作:

<form action="${flowExecutionUrl}" method="post"> 
<input type="hidden" name="_eventId" value="loginCredentialsEntered" />
...

关于java - 使用 Spring web-flow 中的链接在 Web 流中进行数据传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19558150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com