zoukankan      html  css  js  c++  java
  • Struts2-修改数据

     1 <body>
     2 用户信息:<br><br>
     3 <%
     4 List<User> lu = (List<User>)request.getAttribute("userlist");
     5 %>
     6 <table>
     7 <tr>
     8 <th>用户名</th>
     9 <th>姓名</th>
    10 <th>性别</th>
    11 <th>生日</th>
    12 <th>操作</th>
    13 </tr>
    14 <%
    15 for(User u:lu){
    16     int a = u.getUserid();
    17     String b = u.getUsername();
    18     String c = u.getUsersex();
    19     Date d = u.getUserbirthday();
    20 %>
    21 <tr>
    22 <td><%out.print(a); %></td>
    23 <td><%out.print(b); %></td>
    24 <td><%out.print(c); %></td>
    25 <td><%out.print(d); %></td>
    26 <td><a href="deleteUser?userid=<%out.print(a); %>">删除</a>/
    27 <a href="updateUser?userid=<%out.print(a); %>">修改</a></td>
    28 </tr>
    29 <%
    30 }
    31 %>
    32 </table>
    33 </body>

     1 <body>
     2 <%
     3 User u = (User)request.getAttribute("user");
     4 out.print(u);
     5 %>
     6 <form action="delete" method="post">
     7 用户名:<input type="text" value="<%out.print(u.getUserid());%>" name="user.userid"><br><br>
     8 姓名:<input type="text" value="<%out.print(u.getUsername());%>" name="user.username"><br><br>
     9 性别:<input type="text" value="<%out.print(u.getUsersex());%>" name="user.usersex"><br><br>
    10 生日:<input type="text" value="<%out.print(u.getUserbirthday());%>" name="user.userbirthday"><br><br>
    11 <input type="submit" value="提交">
    12 </form>
    13 
    14 </body>

    1 <!-- 修改用户 -->
    2 <action name="updateUser" class="com.hq.action.UserAction" method="selectDan">
    3 <result>WEB-INF/pages/delete.jsp</result>
    4 <result name="fail">WEB-INF/pages/fail.jsp</result>
    5 </action>
    6 <action name="delete" class="com.hq.action.UserAction" method="updateDan">
    7 <result type="redirectAction">selectUser</result>
    8 <result name="fail">WEB-INF/pages/fail.jsp</result>
    9 </action>
     1     public String selectDan(){
     2         String rtn = "fail";
     3         try{
     4             HttpServletRequest hsr = ServletActionContext.getRequest();
     5             String uid = hsr.getParameter("userid");
     6             int userid = Integer.parseInt(uid);
     7             User u = new UserService().selectDan(userid);
     8             hsr.setAttribute("user", u);
     9             rtn = "success";
    10         }catch(Exception e){
    11             e.printStackTrace();
    12         }
    13         return rtn;
    14     }
    15     public String updateDan(){
    16         String rtn ="fail";
    17         try{
    18             u1 = new UserService().updateUser(user);
    19             rtn = "success";
    20         }catch(Exception e){
    21             e.printStackTrace();
    22         }
    23         return rtn;
    24     }
    1     // 修改
    2     public User updateUser(User user){
    3         return new UserDao().update(user);
    4     }
    5     // 单查
    6     public User selectDan(int userid){
    7         return new UserDao().selectUser(userid);
    8     }
        public User update(User user){
            init();
            User u = (User)se.get(User.class, user.getUserid());
            u.setUsername(user.getUsername());
            u.setUsersex(user.getUsersex());
            u.setUserbirthday(user.getUserbirthday());
            desory();
            return u;
        }
  • 相关阅读:
    .net core读取appsettings.config中文乱码问题
    vs2017错误:当前页面的脚本发生错误
    VS Code中无法识别npm命令
    Visual Studio报错/plugin.vs.js,行:1074,错误:缺少标识符、字符串或数字
    记录一次在生成数据库服务器上出现The timeout period elapsed prior to completion of the operation or the server is not responding.和Exception has been thrown by the target of an invocation的解决办法
    Java集合框架
    java hash表
    Java Dictionary 类存储键值
    java数据结构 栈stack
    java封装
  • 原文地址:https://www.cnblogs.com/jingzhenhua/p/6072352.html
Copyright © 2011-2022 走看看