zoukankan      html  css  js  c++  java
  • struts数据回显

    数据回显,必须要用struts标签!

    Action中:

    // 进入修改页面
        public String viewUpdate() {
            // 模拟一个对象(先获取一个id,再根据id调用service查询,把查到的结果保存到域)
            User userInfo = new User();
            userInfo.setUserName("Jack");
            userInfo.setEmail("loaderman@163.com");
            
            ActionContext ac = ActionContext.getContext();
    //        Map<String,Object> request = (Map<String, Object>) ac.get("request");
    //        request.put("userInfo", userInfo);
            
            /************* 数据回显***************/
            // 获取值栈
            ValueStack vs = ac.getValueStack();
            vs.pop();// 移除栈顶元素
            vs.push(userInfo);  // 入栈
            
            
            // 进入修改页面
            return "viewUpdate";
        }
        

    JSP页面:

    <body>
          <%@taglib uri="/struts-tags" prefix="s" %>
          
          
          <br/>
          <!-- 在页面文本框内,显示要修改记录的数据 -->
          
          <!-- 手动通过value设置显示的值 
          <s:form action="#">
              
              用户名: <s:textfield name="user.userName" value="%{#request.userInfo.userName}"></s:textfield>   <br/>
              
              邮箱: <s:textfield name="user.email" value="%{#request.userInfo.email}"></s:textfield>     <br/>
          </s:form>
          -->
          
          <!-- 数据回显技术:s:textfield会自动查找根元素数据(Ognl表达式语言取值)  -->
          <s:form action="#">
              
              用户名: <s:textfield name="userName"></s:textfield>   <br/>
              
              邮箱: <s:textfield name="email"></s:textfield>     <br/>
          </s:form>
          
          <s:debug></s:debug>
      </body>
  • 相关阅读:
    When to Partition a Table and an Index
    Hello, world
    提交
    SubmitOncePage:解决刷新页面造成的数据重复提交问题
    压缩ASP.NET中的ViewState
    asp.net千奇百怪的日历
    ICallbackEventHandler实现
    xml數據
    CrystalReports
    [转]Microsoft Visual Studio 2005中使用水晶报表
  • 原文地址:https://www.cnblogs.com/loaderman/p/10036443.html
Copyright © 2011-2022 走看看