Beispiel #1
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub
    response.setContentType("text/html; charset=UTF-8");
    request.setCharacterEncoding("UTF-8");
    // 取得自己的User对象
    User signinUser = (User) request.getSession().getAttribute("SigninUser");
    if (signinUser == null) {
      response.sendRedirect("./jsp/index.jsp");
      return;
    }
    // 取得被关注者的User ID
    int userId = Integer.parseInt(request.getParameter("uid"));

    UserRelationDAOImpl urdi = new UserRelationDAOImpl();
    try {
      if (urdi.unFollow(signinUser.getUID(), userId) == false) {
        request.setAttribute("UnFollowMsg", "UnFollow Faild!");
        request.getRequestDispatcher("./jsp/result.jsp").forward(request, response);
        return;
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    request.setAttribute("UnFollowMsg", "UnFollow success!");
    request.getRequestDispatcher("./jsp/result.jsp").forward(request, response);
    /*
     * 根据uid1,uid2
     * unFollow()删除记录
     */
  }
Beispiel #2
0
  @Override
  public User signin(String email, String password) throws Exception {
    // TODO Auto-generated method stub
    // 连接数据库
    DatabaseConnection dbc = new DatabaseConnection();
    Connection conn = dbc.getConnection();
    PreparedStatement pStatement = null;
    // 声明变量用于存取结果
    User user = new User();
    // 搜索语句
    String query = "select * from user where email= ? and password= ?";

    try {
      // 执行搜索
      pStatement = conn.prepareStatement(query);
      pStatement.setString(1, email);
      pStatement.setString(2, password);
      ResultSet rs = pStatement.executeQuery();

      while (rs.next()) {
        user.setMBID(rs.getInt("MBID"));
        user.setFullName(rs.getString("FullName"));
        user.setAvatarUrl(rs.getString("AvatarUrl"));
        user.setEmail(rs.getString("Email"));
        user.setPassWord(rs.getString("PassWord"));
        user.setUID(rs.getInt("UID"));
      }
      // 判断是否为空
      if (user.getUID() != 0) {
        System.out.println("Signin Successfully!");
      } else {
        System.out.println("Signin Faild!");
        user = null;
      }
      // 关闭连接,返回结果
      // rs.close();
      dbc.close();
      return user;
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return null;
  }
Beispiel #3
0
  @Override
  public User updateProfile(User user) throws Exception {
    // TODO Auto-generated method stub
    // 连接数据库
    DatabaseConnection dbc = new DatabaseConnection();
    Connection conn = dbc.getConnection();
    PreparedStatement pStatement = null;
    // 声明变量用于存取结果
    User updatedUser = new User();
    // 搜索语句
    String query =
        "UPDATE user SET Email = ?, FullName = ?, AvatarUrl = ?, Password = ? " + "WHERE  uid = ?";
    try {
      // 执行搜索
      pStatement = conn.prepareStatement(query);
      pStatement.setString(1, user.getEmail());
      pStatement.setString(2, user.getFullName());
      pStatement.setString(3, user.getAvatarUrl());
      pStatement.setString(4, user.getPassWord());
      pStatement.setInt(5, user.getUID());
      int row = pStatement.executeUpdate();

      // 判断是否为空
      if (row > 0) {
        updatedUser = user;
        System.out.println("updateProfile Successful!");
      } else {
        System.out.println("updateProfile No record satisfied!");
        user = null;
      }
      // 关闭连接,返回结果
      // rs.close();
      dbc.close();
      return updatedUser;
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return null;
  }