问题描述
我正在使用Java Struts 2框架。
I am doing on Java Struts 2 framework.
通常情况下,我可以通过 Form.java中的get set方法从我的JSP获取数据
(动作类) 。以下是我的例子:
Normally, I can get data from my JSP through the get set method in Form.java
(action class). Below is my example :
在 main.jsp
文件:
<html:text property="campaignName" size="50" maxlength="50" />
因此,我可以通过动作类中的get set方法获取此文本框名称,下面是代码来自
thus, I can get this text box name by get set method in the action class, the below is code from
mainForm.java
:
mainForm.java
:
private String campaignName = null;
public String getCampaignName() {
return campaignName;
}
public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
但是,由于我想使用jQuery做某事,我不再使用< html:text>
作为文本框,但我使用< input type =textid =datepicker/>
。
However, because of I want to use jQuery to do something, I no longer use <html:text>
as text box, but I use <input type="text" id="datepicker" />
.
由于此文本框中没有属性属性,我无法从此文本框中获取值。我试图在文本框中添加 property =something
,但在 mainForm.java
中获取set方法返回 null
。
Because of without property attribute inside this text box, I cant get the value from this text box. I have tried to add property="something"
inside the text box also, but get set method in mainForm.java
is return null
.
我想问一下,如何通过此文本框获取值?
I would like to ask, how can I get the value by this text box?
推荐答案
<s:textfield name="campaignName" size="50" maxlength="50" />
或
<input type="text" name="campaignName" size="50" maxlength="50" />
名称需要与字段名称匹配
The name need to be matched with the field name
这篇关于如何通过id而不是Struts 2中的属性从JSP获取数据到Action类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!