在使用struts标签情况下<html:text property="uesrName"/>可以得到formbean中的值
但是页面如果不用html:text等struts标签,页面的<input type="text" name="userName"/>能否也得到formbean中的值
请哪位给点提示。。谢谢了 

解决方案 »

  1.   

    jstl<input type="text" name="userName" value="${userName}" />
      

  2.   

    可以用jsp带的标准标签,移植性比较高
      

  3.   

    <input type="text" name="userName" value="${userName}" />
    EL表达式
      

  4.   

    jstl
    <input type="text" name="userName" value="${userName}" />
    不行啊在action里修改formbean的值
    public ActionForward editUI(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) throws Exception {
        UserForm formbean=(UserForm)form;
        formbean.setUserName("XXXX");
        return mapping.findForward("edit");
    }
    在jsp里
    在使用struts标签情况下<html:text property="uesrName"/>可以得到formbean中的值
    但是如果不用html:text等struts标签,页面的
    <input type="text" name="userName" value="${userName}"/>得不到formbean中的值
      

  5.   

    你使用的是struts1.x
    如果你的formBean里有值的话,可以使用${formBean.userName} formBean:配置中你form的名字,userName当然是getUserName()方法了。
      

  6.   

    如果在action里这么写
    public ActionForward editUI(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) throws Exception {
      UserForm formbean=(UserForm)form;
      formbean.setUserName("XXXX");
      request.setAttribute("userform", formbean);
      return mapping.findForward("edit");
    }
    在jsp里
    <input type="text" name="userName" value="${userform.userName}"/>是可以得到formbean的值
    我想问的是一定写这么一句 request.setAttribute("userform", formbean) 吗?
      

  7.   

    jstl 比 struts 标签好。容易移植。
      

  8.   

    可用el+OGNL ------>>>   value="${userName}"
    楼主可能不理解OGNL是什么,最好去学习下。你现在不明白的就这个OGNL原理
     ps:有兴趣可以进这个群:Q<%="" %>Q:73419082 好多人都在那讨论,不一定都是高水平,可最少都是热心肠。
      

  9.   

    LZ,你要知道原理饿,所谓的formbean,其实是struts帮你把它封装起来,然后放在request里面。
    也就是说,所有从后台返回前台的数据都可以从request中获取哦。
    我写一段实例代码,你可以在JSP中试试看<% 
    DynaActionForm daf = (DynaActionForm)request.getAttribute("动态formbean名称");
    if(null != daf)
    System.out.println(daf.getString("formbean中的属性名称"));
    %>[