아이디 중복체크 없으면 그 아이디 입력창에 나타내기

김태림·2021년 6월 10일
0

spring

목록 보기
4/4

컨트롤러

@GetMapping("/joinIdDupChk")
	public String joinIdDupChk(String id, Model model) {
		int rowCount = memberService.getCountById(id);
		
		boolean isIdDup = (rowCount == 1) ? true : false;
		
		// model 객체에 View(JSP)에서 사용할 데이터를 저장하기
		// 스프링이 request.setAttribute(키, 값); 호출로 옮겨줌
		model.addAttribute("isIdDup",isIdDup);
		model.addAttribute("id",id);
		
		return "member/joinIdDupChk";
	}

jsp

<c:choose>
	<c:when test="${ isIdDup eq true }">
		<p>아이디가 중복, 사용중인 아이디 입니다. </p>
	</c:when>
	<c:otherwise>
		<p>
			사용가능한 아이디 입니다.
			<button type="button" id="btnUseId">아이디 사용</button>
		</p>
	</c:otherwise>
</c:choose>


<form action="/member/joinIdDupChk" method="get" name="wfrm">
	<input type="text" name="id" value="${id}">
	<button type="submit">아이디 중복확인</button>

</form>

<script>
	var btnUseId = document.querySelector('#btnUseId');
	btnUseId.addEventListener('click', function(){
		
		//window생략가능
		//현재 창의 id 입력값을 부모창의 id 입력상자에 배치하기
		window.opener.document.frm.id.value = wfrm.id.value;
		
		window.close(); 
	});
	
</script>

로그인 화면 jsp밑에 자바스크립트

<script>
		$('#btnIdDupChk').on('click', function(){
			var inputId = $('#member_id').val();
			
			if(inputId.length == 0 ) { //inputId == '' 
				alert('아이디를 입력하세요.');
				$('#member_id').focus();
				return;
			}
			//새로운 자식창(브라우저) 열기
			var childWindow = window.open('/member/joinIdDupChk?id='+inputId, 'joinIdDupChk', 'width=500,height=400');
			
			
		});
	</script>

0개의 댓글