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

时间:2014-12-09 13:07:13

标签: java jsp struts-1

我在jsp中有Checkbox。我想根据从数据库中检索的值设置其值。

我已在动作类中检索了该值,但我无法将此值从动作类设置为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");


    }

1 个答案:

答案 0 :(得分:1)

在动作的执行方法中,在请求级别设置属性,如:

request.setAttribute("vehicleSelected", getVehicleFromDB());

在你的jsp中,你可以做类似的事情:

<input type="checkbox" name="vehicle" value="${vehicleSelected}"/>