这是我的表格
<s:form action="changeStatus">
<s:div class="table">
<s:textfield name="custId" label="CUSTOMER ID" />
<s:textfield name="lifewardsCard" label="LIFE WARDS CARD NUMBER"
size="20" />
<s:textfield name="clientNo" label="CLIENT NUMBER" />
<s:textfield name="custName" label="CUSTOMER NAME" />
<s:textfield name="cardExpiryDate" label="CARD EXPIRY DATE(MMYYYY)" />
<s:select name="status" label="CARD STATUS"
list="#{'1':'Active', '2':'Inactive'}" />
<tr>
<td><s:submit value="search" theme="simple" /></td>
<td><s:submit value="save" theme="simple" /></td>
<td><s:submit type="button" theme="simple"
onclick="clear();return false;" value="clear" /></td>
</tr>
</s:div>
</s:form>
用户将输入字段 custID 并单击搜索按钮我能够从数据库中获取值并在页面上显示它们但我想要做的是在显示数据后他可以编辑数据并且应该能够通过以下方式保存数据点击保存按钮。这是我的xml配置
<action name="changeStatus" class="com.struts.lifewardscard.ChangeAction">
<result name="input">ChangeCardStatus.jsp</result>
<result name="success">ChangeCardStatus.jsp</result>
</action>
这是我的动作课
public class ChangeAction extends ActionSupport implements ModelDriven {
CardStatusForm cardSform=new CardStatusForm();
public String execute() throws Exception{
String clientId=null;
HttpServletRequest request = ServletActionContext.getRequest();
getCardHolderDetails();
return "success";
}
private void getCardHolderDetails() {
Connection c = null;
Boolean empty = true;
DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S");
// Format date into output format
DateFormat outputFormat = new SimpleDateFormat("dd-MMM-yyyy");
try {
c = Conexion.getConnection();
CallableStatement cst = c
.prepareCall("{call P_GET_CARD_DETAIILS(?,?)}");
cst.setString(1, cardSform.getCustId());
cst.registerOutParameter(2, OracleTypes.CURSOR);
cst.executeUpdate();
ResultSet rs = (ResultSet) cst.getObject(2);
while (rs.next()) {
cardSform.setLifewardsCard(rs.getString(1));
cardSform.setClientNo(rs.getString(2));
if(rs.getString(3).equalsIgnoreCase("active"))
{
cardSform.setStatus(1);
}else
{
cardSform.setStatus(2);
}
cardSform.setCustName(rs.getString(4));
cardSform.setCardExpiryDate(rs.getString(5));
System.out.println(inputFormat.parse(rs.getString(6)));
empty = false;
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public Object getModel() {
// TODO Auto-generated method stub
return cardSform;
}
}
即使我可以编写一个可以将数据保存在动作类中的方法,我也没有找到一种方法来调用该方法而不调用其他方法getCardHolderDetails()
。