RequestDispatcher rd = request.getRequestDispatcher("이동위치");
rd.forward(request, response);
response.sendRedirect("이동위치");=============================코드=============================
<%@ 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>
<div align = "center">
<hr width = "30%" color = "red">
<h2>페이지 이동 관련 내용</h2>
<hr width = "30%" color = "red">
<br/> <br/>
<h3>페이지 이동(forward)</h3>
<form method = "post" action = "Ex06_01.jsp">
<p>아이디 : <input type = "text" name = "id"></p>
<p>비밀번호 : <input type = "password" name = "pwd"></p>
<input type = "submit" value = "로그인">
</form>
<br/>
<hr width = "30%" color = "red">
<br/>
<h3>페이지 이동(redirect)</h3>
<form method = "post" action = "Ex06_02.jsp">
<p>아이디 : <input type = "text" name = "id"></p>
<p>비밀번호 : <input type = "password" name = "pwd"></p>
<input type = "submit" value = "로그인">
</form>
</div>
</body>
</html>

=============================코드=============================
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String user_id = request.getParameter("id").trim();
String user_pwd = request.getParameter("pwd").trim();
/*
원래는 DB의 회원 관리 테이블 폼에서 입력한 아이디와
입력한 비밀번호가 일치하는지 확인을 하여 회원이면 메인 페이지로 이동
*/
String db_id = "hong";
String db_pwd = "1234";
if(user_id.equals(db_id)){
// 아이디가 존재하는 경우
if(user_pwd.equals(db_pwd)){
// 회원인 경우 ==> 메인 페이지로 이동 => 페이지 이동
// 특정한 정보를 넘겨주고 싶은 경우
request.setAttribute("Name", "홍길동");
request.setAttribute("Phone", "010-1111-1234");
RequestDispatcher rd = request.getRequestDispatcher("Ex07.jsp");
// 실제 페이지 이동
rd.forward(request, response);
}else {
// 아이디는 일치하나 비밀번호는 다른 경우
}
}else {
// 아이디가 테이블에 없거나 아니면 아이디가 잘못 입력된 경우
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
</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>
<div align = "center">
<hr width = "30%" color = "marmoon">
<h3>메인 페이지</h3>
<hr width = "30%" color = "marmoon">
<br/> <br/>
<h3>
<%=request.getAttribute("Name") %> 님 환영합니다! <br/>
연락처 : <%=request.getAttribute("Phone") %>
</h3>
<h4>
입력받은 아이디 : <%=request.getParameter("id").trim() %> <br/>
입력받은 비밀번호 : <%=request.getParameter("pwd").trim() %>
</h4>
</div>
</body>
</html>

Ex07의 경로가 보이지 않음! 보안성이 좋다는 뜻~!

=============================코드=============================
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String user_id = request.getParameter("id").trim();
String user_pwd = request.getParameter("pwd").trim();
/*
원래는 DB의 회원 관리 테이블 폼에서 입력한 아이디와
입력한 비밀번호가 일치하는지 확인을 하여 회원이면 메인 페이지로 이동
*/
String db_id = "hong";
String db_pwd = "1234";
if(user_id.equals(db_id)){
// 아이디가 존재하는 경우
if(user_pwd.equals(db_pwd)){
// 회원인 경우 ==> 메인 페이지로 이동 => 페이지 이동
// 특정한 정보를 넘겨주고 싶은 경우
request.setAttribute("Name", "홍길동");
request.setAttribute("Phone", "010-1111-1234");
// 페이지 이동
response.sendRedirect("Ex08.jsp");
}else {
// 아이디는 일치하나 비밀번호는 다른 경우
System.out.println("비밀번호가 틀립니다!");
}
}else {
// 아이디가 테이블에 없거나 아니면 아이디가 잘못 입력된 경우
System.out.println("아이디가 틀리거나 회원이 아닙니다!!");
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
</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>
<div align = "center">
<hr width = "30%" color = "marmoon">
<h3>메인 페이지</h3>
<hr width = "30%" color = "marmoon">
<br/> <br/>
<h3>
<%=request.getAttribute("Name") %> 님 환영합니다! <br/>
연락처 : <%=request.getAttribute("Phone") %>
</h3>
<h4>
<%-- null 값이 넘어오기 때문에 error
입력받은 아이디 : <%=request.getParameter("id").trim() %> <br/>
입력받은 비밀번호 : <%=request.getParameter("pwd").trim() %>
--%>
</h4>
</div>
</body>
</html>
redirect 방식

로그인 클릭!
