2014-12-09 63 views
0

我在jsp中有复选框。我想根据从数据库检索到的值来设置它的值。从数据库中检索值。如何从Action类设置为Action Form和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"); 


    } 
+0

你为什么不能初始化'ActionForm'正常吗? – 2014-12-09 17:11:09

回答

1

在你行动的执行方法,设定在要求的水平,如属性:

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

在你的JSP,你可以这样做:

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

由于它是Struts 1,所以最好使用现有的框架机制,例如'ActionForm'。 – 2014-12-09 17:10:40

+0

@DaveNewton我想要这样做。但表单在页面加载时会重置。发送相同的小代码快照。 – k00989 2014-12-10 06:24:00

+0

编辑该问题请检查。如果你发现错误.. – k00989 2014-12-10 06:33:10

相关问题