SessionLoginServlet.java
페이지 정보
본문
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/sessionLogin")
public class SessionLoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public SessionLoginServlet() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
String id=request.getParameter("id");
String passwd = request.getParameter("passwd");
if(id.equals("java")&& passwd.equals("java")){
HttpSession session = request.getSession();
session.setAttribute("id", id);
request.setAttribute("pkt", "dance"); // ("변수명", "값") 값을 변수명에 담아 request 객체 menu.jsp 전달
// 1.Dispatcher 방법
RequestDispatcher dispatcher = request.getRequestDispatcher("menu.jsp");
dispatcher.forward(request, response);
// 2.Redirect방법
// response.sendRedirect("menu.jsp");
}
else{
out.println("<script>");
out.println("alert('아이디나 비밀번호가 일치하지 않습니다.');");
out.println("history.back();");
out.println("</script>");
}
}
}
- 이전글login2.jsp 21.07.15
- 다음글menu.jsp 21.07.15
댓글목록
등록된 댓글이 없습니다.