Struts 1:使用 bean:write 访问表单值

发布于 2024-09-26 12:00:46 字数 788 浏览 0 评论 0原文

您好,

我认为这是一个简单的问题,但它现在仍然困扰着我。

我有一个 TestForm 类,其中包含常用的 getters/setters...例如,我有一个带有“getId”和“setId”方法的“id”字段。

在将表单发送到具有以下代码的 jsp 页面之前,我的表单已正确填充在操作类中(我通过单步调试 Eclipse 调试器了解到这一点):

<html:form action="/AppropriateAction">  
<bean:define id="testFormA" name="TestForm" type="com.whatever.form.TestForm" />

form = <bean:write name="testFormA" />##  
id = <bean:write name="testFormA" property="id" />##  

</html:form>  

我的输出如下所示:

form = com.whatever.form.TestForm13a3x4 ##

id = ##

现在我知道由于输出的第一行,页面可以正确地看到表单,但如果是这种情况,那么为什么 id 从这个语句中显示为空:

id = <bean:write name="testFormA" property="id" />##  

我在做什么在这个jsp页面上访问我的表单的id字段是错误的?

非常感谢!

Greetings,

This is a simple question I believe, but nonetheless it is stumping me right now.

I have a TestForm class with your usual getters/setters...for example I have an "id" field with "getId" and "setId" methods.

My form is populated in an action class correctly (which I know from stepping through the Eclipse debugger) just before it is sent to the jsp page which has the code below:

<html:form action="/AppropriateAction">  
<bean:define id="testFormA" name="TestForm" type="com.whatever.form.TestForm" />

form = <bean:write name="testFormA" />##  
id = <bean:write name="testFormA" property="id" />##  

</html:form>  

My output looks like this:

form = com.whatever.form.TestForm13a3x4##

id = ##

Now I know that the page can see the form correctly due to the first line of the output, but if this is the case then why does the id show that it is empty from this statement:

id = <bean:write name="testFormA" property="id" />##  

What am I doing wrong to access the id field of my form on this jsp page?

Many thanks!

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

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

发布评论

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

评论(1

薯片软お妹 2024-10-03 12:00:46

使用 bean:write 从表单写入属性可以使用表单名称。在你的情况下,你可以使用以下代码:

form: <bean:write name="TestForm"/>##
id = <bean:write name="TestForm" property="id" />

我想这应该更好

writing properties from a form with bean:write is possible with using the form name. in your case you can use the following code:

form: <bean:write name="TestForm"/>##
id = <bean:write name="TestForm" property="id" />

This should work better i guess

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