如何访问控制器上 Struts ActionForm 中的标签值
How to Access a label value in Struts ActionForm on controller
我正在使用 struts MVC。我想通过 struts ActionForm 访问控制器中的标签值。在控制器中,我可以通过 ActionForm 访问文本字段值的值,因为标签中有 'name' field.But,只有 'id' 是 there.So 请帮助我访问通过 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>
您可以使用此代码访问标签内的文本
<html>
<head>
<script>
function getLabelValue() {
alert(document.getElementById("labelvalue").innerText);
}
</script>
</head>
<body>
<html:form>
<label id="labelvalue">FOOOOOOO</label>
<input type="button" onclick="getLabelValue()"/>
</html:form>
</body>
</html>
现在将隐藏的 属性 添加到 JSP(Form class 中的一个属性)。提交时调用此 JS 函数
function setLabelValueToFormAttribute()
{
document.getElementById("hiddenProperty").value = document.getElementById("labelvalue").innerText;
}
可以用label字段添加一个隐藏字段,并将值设置为隐藏字段also.You可以将隐藏字段名称设置为该标签名称。
<html:form action="action.do">
<label id="labelvalue">label_Value</label>
<input type="hidden" name="labelvalue" value="label_Value"/>
</html:form>
我正在使用 struts MVC。我想通过 struts ActionForm 访问控制器中的标签值。在控制器中,我可以通过 ActionForm 访问文本字段值的值,因为标签中有 'name' field.But,只有 'id' 是 there.So 请帮助我访问通过 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>
您可以使用此代码访问标签内的文本
<html>
<head>
<script>
function getLabelValue() {
alert(document.getElementById("labelvalue").innerText);
}
</script>
</head>
<body>
<html:form>
<label id="labelvalue">FOOOOOOO</label>
<input type="button" onclick="getLabelValue()"/>
</html:form>
</body>
</html>
现在将隐藏的 属性 添加到 JSP(Form class 中的一个属性)。提交时调用此 JS 函数
function setLabelValueToFormAttribute()
{
document.getElementById("hiddenProperty").value = document.getElementById("labelvalue").innerText;
}
可以用label字段添加一个隐藏字段,并将值设置为隐藏字段also.You可以将隐藏字段名称设置为该标签名称。
<html:form action="action.do">
<label id="labelvalue">label_Value</label>
<input type="hidden" name="labelvalue" value="label_Value"/>
</html:form>