问题
I am doing on Java Struts 2 framework.
Normally, I can get data from my JSP through the get set method in Form.java
(action class). Below is my example :
In main.jsp
file:
<html:text property="campaignName" size="50" maxlength="50" />
thus, I can get this text box name by get set method in the action class, the below is code from
mainForm.java
:
private String campaignName = null;
public String getCampaignName() {
return campaignName;
}
public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
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" />
.
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?
回答1:
<s:textfield name="campaignName" size="50" maxlength="50" />
or
<input type="text" name="campaignName" size="50" maxlength="50" />
The name need to be matched with the field name
回答2:
The simple usage of that textbox is to use s:textfield
tag.
<s:textfield name="campaignName" size="50" maxlength="50" />
回答3:
You can use <s:textfield name="campaignName" size="50" maxlength="50" />
and add struts tag to your jsp ( at the top ):
<%@ taglib prefix="s" uri="/struts-tags"%>
来源:https://stackoverflow.com/questions/18587695/how-to-get-data-from-jsp-to-action-class-by-id-instead-of-property-in-struts-2