我在jsp中有复选框。我想根据从数据库中检索的值设置其值。
我已经检索了操作类中的值,但我无法将此值从操作类设置为 jsp 页面。
我是新手。谁能告诉如何做到这一点。
.JSP:
<html:form action="faxDownloadSettings">
<html:hidden property="checkMe"/>
<input type=checkbox name="pdf" property="checkMe" checked="checked"> <bean:message key="com.console.asPDF"/>
<console:button name="save" script="save();">
<console:label><bean:message key="com.console.save"/></console:label>
</console:button>
行动形式:
public class FaxDownloadSettingsForm extends ActionForm {
private boolean checkMe;
public void setCheckMe(boolean checkMe){
this.checkMe = checkMe;
}
public boolean getCheckMe(){
return checkMe;
}
}
操作类:
public class FaxDownloadSettingsAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FaxDownloadSettingsForm form = (FaxDownloadSettingsForm) actionForm;
boolean isFaxtopdf = enumResponse.getFaxtopdf();
request.setAttribute("checkFax", isFaxtopdf);
form.setCheckMe(true); //It also not works
}
return mapping.findForward("success");
}
在操作的执行方法中,在请求级别设置属性,如下所示:
request.setAttribute("vehicleSelected", getVehicleFromDB());
在你的jsp中,你可以做这样的事情:
<input type="checkbox" name="vehicle" value="${vehicleSelected}"/>