呵呵,楼主,刚才我看了struts的文档,html:checkbox里面好像没有这个属性呢,在jsp中好像是checked = true

解决方案 »

  1.   

    对对应的fromBean里的属性进行设置,试试
      

  2.   

    to:qjhaaaaa
    我也查过,没找到to:bdsc
    我在fromBean里给属性设置了值,但显示时还是没选中还有其它办法吗?
      

  3.   

    不一定整个页面都要用 Struts 来做吧?? (<- 新手)
      

  4.   

    这么小的问题,不可能叫我放弃struts吧?有点郁闷!
    期待你的高论!
      

  5.   

    用javaScript来实现:
    在页面的最后,</html>之前,加上:document.formname.checkname.checked=true;
      

  6.   

    <html:checkbox property="first" value="123"/>
    在action中将first属性付值为123就可以了。
    如果不指定value:
    <html:checkbox property="first"/>
    那么付值为on就可以。
      

  7.   

    把formaBean的first的值设定为"123"-->form.setFirst("123");
    页面的checkBox就会被选中
      

  8.   

    在JSP中:
    <html:html>
    <head>
    <title></title>
    <html:base/>
    </head>
    <body bgcolor="white">
    <html:form  action="/wcAction.do"    method="post">
          <html:text property="mybeanvariable1" />
          <html:checkbox  property="chec"  value="123" />
          <html:checkbox  property="chec"  value="444" />
          <html:submit value="提交" />
          <html:reset value="重写" />
      </html:form>
    </body>
    </html:html>/////////////
    在FormAction中:  private String chec="123";  //默认选中第一个check
            public String getChec()
            {
                return (this.chec);
            }        public void setChec(String chec)
            {
                this.chec=chec;
            }
    ///////////////////////////////
    在Action中:
     //函数定义:
        public ActionForward execute(ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
    throws Exception 
        {
    // Extract attributes and parameters we will need
    Locale locale = getLocale(request);
    MessageResources messages = getResources(request);
    HttpSession session = request.getSession();
    wcForm m_wcForm = (wcForm) form;
    String chec=m_wcForm.getChec();
    if(chec.equals("123"))
    {
        m_wcForm.setChec("123");
     }
     else
     {    m_wcForm.setChec("444");
     }
    ................
    /////////////////////////////
    第一次运行时默认选中了第一个check可实现两个checkbox的选中一个。本例在JSPStudio中试运行通过。