<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Cookie cookie = new Cookie("language", request.getParameter("language"));
cookie.setMaxAge(6000);
response.addCookie(cookie);
%>
<script>
location.href="cooki.jsp";
</script>
-----------------------------------------------------------------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String language="korea";
String cookie = request.getHeader("cookie");
if(cookie != null){
Cookie cookies[] = request.getCookies();
for(int i = 0; i < cookies.length; i++){
if(cookies[i].getName().equals("language")){
language=cookies[i].getValue();
}
}
}
%>
<!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>Insert title here</title>
</head>
<body>
<%if(language.equals("korea")){
%><h3>안녕하세요. 이것은 쿠키 예제입니다.</h3>
<%}else {%>
<h3>Hello. This is Cooki example.</h3>
<%} %>
<form action="cookieExample2.jsp" method="post">
<input type="radio" name="language" value="korea"
<%if(language.equals("korea")){ %>checked<%} %>>한국어 페이지 보기
<input type="radio" name="language" value="english"
<%if(language.equals("english")){ %>checked<%} %>>영어 페이지 보기
<input type="submit" value="설정">
</form>
</body>
</html>
'WebStudy' 카테고리의 다른 글
캐시 막는 법. (0) | 2015.06.30 |
---|---|
JSTL forEach, FroToken 속성 (0) | 2015.06.26 |
jstl tag (0) | 2015.06.23 |
DB싱글톤 방식, ConnectionPool (0) | 2015.06.23 |
session 에 관한 ... (0) | 2015.06.22 |