IT 공부/JSP

로그인 폼

toraa 2022. 7. 26. 11:21

 


html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<title>Insert title here</title> 
<style type="text/css">
	table {
		height: 30px;
		border-collapse: collapse;
	}
	input{
		height: 30px;
		width: 300px;
		border:0;
	}
	.btn{
		width:60px;
		background-color:#FAF0E6;
	}
</style>
</head>
<body>
	<div class="container-md mt-5 text-center ">
	<h3>로그인창</h3>
	<form action="jsp6.jsp" method="get">
		<table border="1" style="margin:0 auto">
			<tr>
				<td>아이디</td><td><input type="text" name="user_id"></td>
			</tr>
			<tr>
				<td>비밀번호</td><td><input type="password" name="user_pw"></td>
			</tr>
			<tr align="center">
				<td colspan="2">
					<input class="btn" type="submit" value="로그인">&nbsp;
					<input class="btn" type="reset" value="취소">
				</td>
			</tr>
		</table>
	</form>
	</div>
</body>
</html>

jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%	/* 요청문서를 utf-8로 인코딩처리 - POST 방식 */
		request.setCharacterEncoding("utf-8");
	
		/* 응답문서를 데이터타입은 html이고, 문자셋은 utf-8로 지정 */
		response.setContentType("text/html; charset=utf-8");
	
		/* form으로 전송된 파라미터값 가져오기 */
		String id = request.getParameter("user_id"); //getParameterValues()-체크/라디오,select
													 //getParameterNames()
		String pw = request.getParameter("user_pw");
		
		
		/* 아이디와 비번체크 */
		if(id != null && (id.length() != 0)){
			
			//관리자 일때
			if(id.equals("admin") && pw.equals("1234")){
				out.print("<font size='12'>관리자로 로그인하였습니다.</font><br>");
				out.print("<input type='button' value='회원정보 수정'><br>");
				out.print("<input type='button' value='회원삭제'><br>");
			}
			//일반회원
			else{
				out.print(id+"님! Guest계정으로 로그인하셨습니당");
				out.print("<a href='http://localhost:8080/Ch3/main.jsp'>메인창으로 이동</a>");
			}
		}
			//비정상 입력 - 유효성 검사
		else{
				out.print("ID와 비밀번호를 입력하세요");
				out.print("<br>");
				out.print("<a href='http://localhost:8080/Ch3/jsp6.html'>로그인창으로 이동</a>");
			}
		
	%>
</body>
</html>

'IT 공부 > JSP' 카테고리의 다른 글

내장객체  (0) 2022.07.28
Response(응답)  (0) 2022.07.28
JSP  (0) 2022.07.27
기본 처리 이론  (1) 2022.07.27
html -> jsp  (1) 2022.07.25