SessionLoginServlet.java > MODEL

본문 바로가기

사이트 내 전체검색

뒤로가기 MODEL

SessionLoginServlet.java

페이지 정보

작성자 관리자 작성일 21-07-15 18:36 조회 405 댓글 0

본문

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>");

}

}

}


추천0

댓글목록 0

등록된 댓글이 없습니다.


Copyright © dancePKT. All rights reserved.
PC 버전으로 보기