• 每日日报8月22日


    1.今天学习了

    编写添加用户的 Servlet
    1. package edu.swpu.web.servlet;
    2.  
       
    3.  
      import edu.swpu.domain.User;
    4.  
      import edu.swpu.service.UserService;
    5.  
      import edu.swpu.service.impl.UserServiceImpl;
    6.  
      import org.apache.commons.beanutils.BeanUtils;
    7.  
       
    8.  
      import javax.servlet.ServletException;
    9.  
      import javax.servlet.annotation.WebServlet;
    10.  
      import javax.servlet.http.HttpServlet;
    11.  
      import javax.servlet.http.HttpServletRequest;
    12.  
      import javax.servlet.http.HttpServletResponse;
    13.  
      import java.io.IOException;
    14.  
      import java.lang.reflect.InvocationTargetException;
    15.  
      import java.util.Map;
    16.  
       
    17.  
      @WebServlet("/addUserServlet")
    18.  
      public class AddUserServlet extends HttpServlet {
    19.  
      @Override
    20.  
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    21.  
      //1.设置编码
    22.  
      request.setCharacterEncoding("utf-8");
    23.  
      //2.获取参数
    24.  
      Map<String, String[]> map = request.getParameterMap();
    25.  
      //3.封装对象
    26.  
      User user = new User();
    27.  
      try {
    28.  
      BeanUtils.populate(user,map);
    29.  
      } catch (IllegalAccessException e) {
    30.  
      e.printStackTrace();
    31.  
      } catch (InvocationTargetException e) {
    32.  
      e.printStackTrace();
    33.  
      }
    34.  
      //4.调用Service保存
    35.  
      UserService service = new UserServiceImpl();
    36.  
      service.addUser(user);
    37.  
      //5.跳转到userListService,因为没有共享数据,所以使用重定向
    38.  
      response.sendRedirect(request.getContextPath()+"/userListServlet");
    39.  
       
    40.  
      }
    41.  
       
    42.  
      @Override
    43.  
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    44.  
      super.doGet(request, response);
    45.  
      }
    46.  
      }
    2.没有遇到问题
    3.明天打算学习
    修改用户信息列表 userlist.jsp
  • 相关阅读:
    avcodec_decode_video2少帧问题
    什么是I帧,P帧,B帧
    让Ubuntu可以压缩/解压缩RAR文件
    Linux 向文件末尾追加命令
    valgrind: failed to start tool 'memcheck' for platform 'amd64-linux': No such file or directory
    《王者之剑2》性能数据精讲
    Unity加载模块深度解析(纹理篇)
    Unity加载模块深度解析(Shader)
    Unity加载模块深度解析(网格篇)
    Unity将来时:IL2CPP是什么?
  • 原文地址:https://www.cnblogs.com/wanghaoning/p/13591736.html
Copyright © 2020-2023  润新知