【发布时间】:2017-01-21 11:12:04
【问题描述】:
我正在使用 struts MVC。我想通过 struts ActionForm 访问控制器中的标签值。在控制器中,我可以通过 ActionForm 访问文本字段值的值,因为它具有“名称”字段。但在标签中,只有“id”。所以请帮助我通过 ActionForm 访问控制器的标签值.
jsp
<html:form action="action.do">
<label id="labelvalue">label_Value</label>
</html:form>
控制器
public ActionForward defaultMethod(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
try{
StrutsActionForm actform;
actform= (StrutsActionForm) form;
String labelvalue=actform.getLabelValue();//now it shows null.I want to get the value from the label field
return "success";
}catch(Exception e){
return null;
}
}
StrutsActionForm
publi class StrutsActionForm extends ActionForm{
private String labelvalue;
public String getLabelValue() {
return labelvalue;
}
public void setLabelValue(String labelvalue) {
this.labelvalue= labelvalue;
}
}
struts-config.xml
<form-beans>
<form-bean name="strutsActionForm" type="com.StrutsActionForm"></form-bean>
</form-beans>
<action-mappings>
<action path="/action" name="strutsActionForm" input="/index.jsp"
type="com.Controller">
<forward name="success" path="/successWindow" />
</action>
</action-mappings>
【问题讨论】: