본문 바로가기
개발~/JSP

RequestDispatcher에 foward와 response.sendRedirect url차이

by 보배곰 2018. 4. 18.


notice.jsp 에서 삭제버튼 클릭시, delNotice.jsp에서 삭제를 처리하고 다시 notice.jsp로 돌아오는 구조. 


notice.jsp 


목록

notice.jsp에 있는 삭제버튼과 구현




function delNotice(id) {
	if(confirm("삭제하시겠습니까?")) {
		location.href="delNotice.jsp?id="+id;
	} else {
		return;
	}
}


delNotice.jsp


1. forward

RequestDispatcher rd = request.getRequestDispatcher("notice.jsp");
rd.forward(request, response);

그리고 삭제버튼 누르면 
url이 
http://127.0.0.1/jsp/admin/notice.jsp
-> 
http://127.0.0.1/jsp/admin/delNotice.jsp?id=7

이렇게 바뀜 


2. sendRedirect

response.sendRedirect("notice.jsp")


그리고 삭제버튼 누르면

url이

http://127.0.0.1/jsp/admin/notice.jsp

->

http://127.0.0.1/jsp/admin/notice.jsp


그대로. 



댓글