2014-12-09 45 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

相關問題