열심히 끝까지

디바이스 융합 자바(Java) day52 - 팀프로젝트 작업 및 frontController 질문 및 답변 본문

디바이스 융합 자바(Java)기반 풀스택 개발자 양성과정(수업내용)

디바이스 융합 자바(Java) day52 - 팀프로젝트 작업 및 frontController 질문 및 답변

노유림 2022. 8. 24. 18:24

창 닫기 

>> 다시 연결하여 창 닫기 진행할 것

 

>> 두가지 닫기 (글자, 버튼) 둘 다 잘 작동

 

>> 코드

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>회원가입 성공</title>
</head>
<body>
<h2 style="text-align:'center';">회원가입 완료</h2>
<p style="margin:auto;">회원가입을 완료했습니다.</p>
<p style="margin:auto;">닫기를 눌러 돌아가세요.</p>
<span onclick="window.close();" style="cursor:pointer;">닫기</span>
<input type="button" value="닫기" onclick="window.close();">

</body>
</html>

 

 

> script사용

   >> (브라우저)마다 해석 방식이 다름
   >> ajex를 써서 비밀번호가 유효하지 않음.. 이라고 출력하는 것이 더 빠름
   >> 글자를 띄우는 것이 더 흔함
> js는 브라우저마다 해석이 다름
> .html, .jsp, .ajex 등등 -> View를 위한 언어

   >> Model, Controller에서는 다루지 않는 것이 맞음

 

 

>> forward.setRedirect();

if(dao.insert(vo)) {
	forward= new ActionForward();
	forward.setPath("main.do");
	forward.setRedirect(true);
}
if(dao.insertReply(vo)) {
	forward= new ActionForward();
	forward.setPath("main.do");
	forward.setRedirect(false);
}

true : board가 들어가는 건 대부분 true
false : reply는 false

 

if(forward!=null) {
	// 디스패쳐 만들어서 타겟페이지로 이동
	if(forward.isRedirect()) { // ActionForward의 redirect값을 묻는 것
		response.sendRedirect(forward.getPath());
	}
	else {
		RequestDispatcher dispatcher=request.getRequestDispatcher(forward.getPath());
		dispatcher.forward(request, response); // 정확하게 언급 했을 때 수행
	}
}


>> 둘의 차이는?

    > setRedirect(T) => if(forward.isRedirect())
       -> response.
       -> 원래 첫 화면으로 
    > setRedirect(F) => else
       -> forward/디스패쳐
       -> 페이지 상태를 유지하기 위해

>> setContentType을 지정해주지 않아서 alert에 글자가 깨짐!
    >> response.setContentType("text/html; charset=UTF-8"); 넣기