struts2:将相同的表单提交给不同的操作时出现问题 [英] struts2 : Problem in submitting same form to different actions

查看:27
本文介绍了struts2:将相同的表单提交给不同的操作时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下场景.

有一个jsp(我们称之为user.jsp).

There is a jsp (let's call it user.jsp) .

user.jsp 包含 2 个按钮(提交和注册).这两个按钮指的是完全不同的操作(我们称之为 A 和 B).

The user.jsp contains 2 buttons (Submit and Register). The two buttons are referring to entirely different actions (let us call it A and B).

现在,当我单击注册"按钮时,由于提交了相同的表单,因此 A 中有某些属性不在 B 中.因此我收到一条错误消息,setter 方法不存在.

Now when I click on Register button , since the same form is submitted , there are certain attributes in A which are not in B . Therefore I get an error saying , setter methods are not present .

如何解决这种情况.

如果问题不清楚,请告诉我.

Please let me know if the question is not clear.

推荐答案

您始终可以添加虚拟设置器 - 甚至在提交之前在 javascript 中操作字段.但是您的实现问题指向了概念设计问题.我发现将具有相同输入字段的表单发送到两个操作在概念上令人反感,特别是如果某些字段仅适用于其中一个操作(有意义).

You can always add dummy setters -or even manipulate the fields in javascript before submiting. But your implementation problem points to a conceptual-design problem. I find conceptually objectionable to send a form with same inputs field to two actions, specially if some of the fields only apply (make sense) for one of the actions.

一般来说,在一个表单中有两个提交按钮指向不同的操作对我来说似乎是不正确的.标准的方法是让同一个表单中的不同提交按钮指向同一个动作中的不同方法.如果动作真的不相关,另一种选择是制作两种不同的形式.

In general, it doesn't seem right to me to have two submit buttons in a form pointing to different actions. The standard way is to make the different submits buttons in the same form point to different methods in the same action. The alternative, if the actions are really unrelated, is to make two different forms.

这篇关于struts2:将相同的表单提交给不同的操作时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆