⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginaction.java

📁 JAVA Servlet2.3外文书籍源码
💻 JAVA
字号:
package forum;

import javax.servlet.http.*;

/**
 * Represents the logic behind logging a user into the system. This action
 * is responsible for checking the username and password are valid. If so,
 * the appropriate User instance is placed in the HTTP session object under
 * the name of "user".
 *
 * @author    Simon Brown
 */
public class LoginAction extends Action {

  /**
   * Peforms the processing associated with this action.
   *
   * @param request     the HttpServletRequest instance
   * @param response    the HttpServletResponse instance
   * @return  the name of the next view
   */
  public String process(HttpServletRequest request, HttpServletResponse response) {

    System.out.println("LoginAction : Processing request");

    String id = request.getParameter("id");
    String password = request.getParameter("password");
    String view;

    // does a user exist with the specified id and password
    if (Users.exists(id, password)) {
      request.getSession().setAttribute("user", Users.getUser(id));
      view = "/index.jsp";
    } else {
      view = "/login.jsp";
    }

    return view;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -