Struts2:我不希望用户在不单击提交按钮的情况下访问成功页面
我的设置是:
用户转到操作 1st >显示注册用户> (register.jsp)
当用户单击提交按钮时,用户将被引导至操作 >注册用户> (register.jsp)
现在,show 方法已从验证中排除,因此页面是干净的(即没有验证错误) 当用户单击“提交”时,将执行验证(如果有任何错误,则会显示在页面上)
我的要求是,如果用户直接点击“注册用户”页面(而不是单击“提交”) 那么他们应该被重定向到 showRegisterUser 操作。
由于验证失败,我无法在执行中编写任何代码,因此执行中的代码永远不会被触及
请有人指出我正确的方向
谢谢
my setup is as:
users goto to the action 1st > showRegisterUser > (register.jsp)
when users click submit button the user is directed to action > RegisterUser > (register.jsp)
Now, the show method is exculded from validation so the page is clean (ie without validation errors)
when user clicks on submit the validations are performed (if any error, are displayed on the page)
My requirement is that if a user directly hits the RegisterUser page (not by clicking submit)
then they should be redirected to the showRegisterUser action.
I can't write any code in execute as the validations fail so the code in execute is never touched
Please can somebody point me in the right direction
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当验证失败时,它默认为 INPUT 响应。如果您有一个执行和一个输入方法,那么您可以将您的操作连接为:
将您的“输入”响应指向“空白/干净”形式,因为您拥有其他所有内容。
When validation fails it defaults to the INPUT response. If you you have an execute and an input method then you can wire up your action as:
Point your "input" response to the 'blank/clean' form everything else as you have it.
在验证器中,您可以设置指示验证成功的会话属性。在 RegisterUser 页面上,您可以检查此会话属性并根据需要进行重定向。
当您到达 RegisterUser 页面时,您需要取消设置“有效”会话属性,或者如果您不想接受会话中的多个注册,请在 showRegisterUser 上检查它并重定向回 RegisterUser 页面(如果存在)已设置。
Struts 使用控制器。 validate.xml 文件与输入字段进行比较,但它不会自行运行:控制器类正在运行实际的比较。在控制器类中,您可以决定输入是否有效,并且可以决定从那里转到哪个视图。
In your validator, you can set a session attribute indicating successful validation. On your RegisterUser page, you can check for this session attribute and redirect if needed.
You'll want to unset the "valid" session attribute when you reach the RegisterUser page, or if you don't want to accept more than one registration from a session check for it on the showRegisterUser and redirect back to the RegisterUser page if it is set.
Struts uses controllers. The validate.xml file is compared with the input fields, but it doesn't run itself: a controller class is running the actual comparison. In the controller class, you decide whether or not the input is valid, and can decide which view to go to from there.
在表单中添加隐藏字段
现在将此字段的值更改为 true
onclick
提交按钮。现在,在您的验证方法中检查此字段的值,如果其
false
则跳过验证并重定向到所需的showRegisteredUser
操作或其他操作Add a hidden field in your form
Now change this field's value to true
onclick
of submit button.Now in your validation method check the value of this field, if its
false
then skip the validation and redirect to the desiredshowRegisteredUser
action or whatever