loginForm.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>로그인(form)</title>

<style>

table, tr, td {

margin:1px;

padding:1px;

border:1px solid gray;

}

</style>

</head>

<body>

<form action="login" method="post">

<table>

<tr>

<td colspan="2">로그인</td>

</tr>

<tr>

<td>아이디</td>

<td><input type="text" name="userid" id="userid"></td>

</tr>

<tr>

<td>비밀번호</td>

<td><input type="password" name="userpwd" id="userpwd"></td>

</tr>

<tr>

<td colspan="2">

<input type="submit" value="로그인">

<input type="reset" value="취소">

</td>

</tr>

</table>

</form>

</body>

</html>



---------------------------------------------------------------------------------------------------


LoginServlet.java   ->  (서블릿...)

package com.web3.login;


import java.io.IOException;

import java.io.PrintWriter;


import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


/**

 * Servlet implementation class LoginServlet

 */

@WebServlet("/login")

public class LoginServlet extends HttpServlet {

private static final long serialVersionUID = 1L;


    public LoginServlet() {

        super();

    }


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//요청 처리후 응답을 위한 마임타임과 문자셋 설정

response.setContentType("text/html;charset=utf-8");

//응답 결과를 클라이언트에게 보내기 위해서 문자스트림을 생성

PrintWriter out = response.getWriter();

//파라미터 받아오기

String uid = request.getParameter("userid");

String pwd = request.getParameter("userpwd");

//DB에 Access해서 userid, password 일치 여부를 체크해야함....

if(uid.equals("admin") && pwd.equals("a1234")){

response.sendRedirect("./loginSuccess.jsp");

} else {

response.sendRedirect("./loginFail.jsp");

}


}


}



---------------------------------------------------------------------------------------------------


loginSuccess.jsp   ->  (성공 페이지)

<%@ page contentType="text/html; charset=utf-8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>로그인 성공!!</title>

<style type="text/css">

body {

color:blue;

}

</style>

</head>

<body>

로그인 성공했습니다.<br>

님 환영합니다!!<br>

</body>

</html>



---------------------------------------------------------------------------------------------------


loginFail.jsp   ->  (실패 페이지)

<%@ page contentType="text/html; charset=utf-8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>로그인 실패!!</title>

<style type="text/css">

body {

color:red;

}

</style>

</head>

<body>

로그인 실패했습니다.<br>

아이디가 존재하지 않거나, 비밀번호 오류입니다.<br>

</body>

</html>


+ Recent posts