gpt4 book ai didi

java - 从数据库中检索值。如何从Action类设置为Action Form和JSP?

转载 作者:行者123 更新时间:2023-12-01 12:08:59 24 4
gpt4 key购买 nike

我在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;
}
}

Action 类:

    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}"/>

关于java - 从数据库中检索值。如何从Action类设置为Action Form和JSP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27379691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com