JSP/연습

JSP로 회원가입 폼 만들어보기

SEOKIHOUSE 2023. 6. 8. 16:21

 

  • 헷갈린부분
  • button은 기본타입이 submit이라 중복체크 누르니까 다음페이지로 넘어갔다;; 까먹었음;;..  (type= button)으로 해줬다
  • 오늘 배운 request.getRequestDispatcher로 넘기는건가? 해서 이걸 썼더니 회원가입 페이지도 안뜨고 로그인페이지로 바로 넘어가버렸다.. 공부를 더 하자;; 

↓↓순서대로 해놨다↓↓

<%@ 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>

<script>
		window.onload = function() {
			const idcheck = document.querySelector("#idcheck");
			let ids = document.querySelector("input[name=id]");
			let idcheckdiv = document.querySelector("#idcheckdiv");
			
			idcheck.addEventListener("click", check);
			function check() {
				if(ids.value =="흰둥이") {
					alert("중복된 아이디");		
				}
			}
			
			
			
		}
	</script>
</head>
<body>
	<h1>회원가입페이지</h1>
	<hr>
	<div id=idcheckdiv></div>
	<div>
		<form action="0608registsucess.jsp" method="get">
			아이디 <input type="text" name="id" placeholder="input id" required >
			<button type="button" id="idcheck">중복확인</button>
			<br>
			비밀번호 <input type="password" name="pw" placeholder="input pw"required><br>
			폰 번호 <input type="text" name="phoneNum" placeholder="input phoneNum"required><br> 
			<input type="submit" value="회원가입 하기">
		</form>
	</div>

</body>
</html>
<%@page import="vo.MemberVo2"%>
<%@ 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>
<% 
	String id = request.getParameter("id");
	String pw = request.getParameter("pw");
	String phone = request.getParameter("phoneNum");
	
	application.setAttribute("ids", id);
	application.setAttribute("pws" , pw);
	
%>
	<h1>회원가입 성공</h1>
	<a href ="0608loginpage.jsp">로그인페이지 가기</a>
</body>
</html>
<%@ 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>
	<script>
		
	</script>
</head>
<body>

	<h1>로그인페이지</h1>
	<hr>
	<form action="0608logincheck.jsp" method="get">
		아이디 <input type ="text" name="id" required>
		비밀번호 <input type="password" name="pw" required>
		<input type="submit" value="로그인">
	</form>
	
	
</body>
</html>
<%@ 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>
<%
	String loginId = request.getParameter("id");
	String loginPw = request.getParameter("pw");
	
	String storeId =(String)application.getAttribute("ids");
	String storePw =(String)application.getAttribute("pws");
	
	if(storeId.equals(loginId) && storePw.equals(loginPw)) {
		response.sendRedirect("0608loginsucesspage.jsp");
	}else {
		request.getRequestDispatcher("0608loginfailpage.jsp").forward(request, response);
		//response.sendRedirect("0608loginfailpage.jsp");
	}
%>
</body>
</html>
<%@ 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>
	<h1>로그인성공!!!</h1>
</body>
</html>
<%@ 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>
	<h1>로그인 실패</h1>
	<a href="0608loginpage.jsp">로그인페이지가기</a>
</body>
</html>