note

리다이렉트(Redirect)를 이용해서 페이지 이동하기2 본문

JSP/기본

리다이렉트(Redirect)를 이용해서 페이지 이동하기2

투한 2012. 2. 6. 10:45



login.jsp 실행시



login으로 넘어 갈경우







login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String id = request.getParameter("memberId");
	if (id != null && id.equals("era13")) {
		response.sendRedirect("/chap03/index.jsp");
	} else {
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>로그인 실패</title>
</head>
<body>
아이디가 era13이 아닙니다.
</body>
</html>
<%
	}
%>


index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>login</title>
</head>
<body>
아이디가 era13 입니다.
</body>
</html>



redirectEncodingTest.jsp실행 화면




redirectEncodingTest.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import ="java.net.URLEncoder" %>

<%
	String value = "자바";
	String encodedValue = URLEncoder.encode(value, "UTF-8");
	response.sendRedirect("/chap03/main.jsp?name=" + encodedValue);
%>


main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>main.jsp</title>
</head>
<body>
	<%
		request.setCharacterEncoding("UTF-8");
		String name = request.getParameter("name");
	%>

	<%=name%>
</body>
</html>