주요 기본 객체




※println()쓰는 이유
HTML소스코드 줄바꿈 되서 브라우져 소스보기에 출력되기 때문에



영역객체(Scope Object


PAGE 영역 - 하나의 JSP 페이지를 처리할 때 사용되는 영역

REQUEST 영역 - 하나의 HTTP 요청을 처리할 때 사용되는 영역

SESSION 영역 - 하나의 웹 브라우저와 관련된 영역(한 사람의 아이디 비번 ,구매한 물건의 갯수,가격 공유안됨)

APPLICATION 영역 - 하나의 웹 어플리케이션과 관련된 영역




속성(Attribute)





속성의 활용











<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
	pageContext.setAttribute("myData", "페이지영역에 저장된 데이타");
%>
<!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=EUC-KR">
<title>Page Scope Test</title>
</head>
<body>
<%=pageContext.getAttribute("myData") %>
</body>
</html>






loginForm.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>로그인 폼</title>
</head>
<body>
<form action="loginProc.jsp" method="post">
<table>
<tr><th>아이디</th><td><input type="text" name="id"></td></tr>
<tr><th>비	번</th><td><input type="password" name="pwd"></td></tr>
<tr><td colspan="2"><input type="submit" value="로그인"></td></tr>
</table>
</form>
</body>
</html>
loginProc.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
	String id= request.getParameter("id");
	String pwd= request.getParameter("pwd");
	if(id.length()> 0&& pwd.length()>0){%>
		<jsp:forward page="loginSuccess.jsp"/>		
 <%}else{%>
		<jsp:forward page="loginFail.jsp"/>
<%}
%>

loginSuccess.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>로그인 성공</title>
</head>
<body>
<h1>로그인에 성공했습니다.</h1>
<%=request.getParameter("id") %><br/>
<%=request.getParameter("pwd") %><br/>
</body>
</html>
loginFail.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!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=EUC-KR">
<title>로그인 실패</title>
</head>
<body>
<h1>로그인에 실패하셨습니다.</h1>
</body>
</html>



012



camera.jsp
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
	if(session.getAttribute("cart")== null){
		session.setAttribute("cart", new java.util.ArrayList<String>());
	}

	ArrayList<String> cart = (ArrayList<String>)session.getAttribute("cart");
	cart.add("Camera,Canon DSLR 450,1000000");
%>
<!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=EUC-KR">
<title>카메라 구입 페이지</title>
</head>
<body>
<h1>카메라를 장바구니에 담았습니다.</h1>
<a href="notebook.jsp">노트북 매장 가기</a>
</body>
</html>
notebook.jsp
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
	if(session.getAttribute("cart")==null){
		session.setAttribute("cart", new java.util.ArrayList<String>());
	}

	ArrayList<String> cart = (ArrayList<String>)session.getAttribute("cart");
	cart.add("Notebook,Apple MacBook Pro,1200000");
%>
<!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=EUC-KR">
<title>노트북 구입 페이지</title>
</head>
<body>
<h1>노트북을 장바구니에 담았습니다.</h1>
<a href="car.jsp">자동차 매장 가기</a>
</body>
</html>
car.jsp
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
	if(session.getAttribute("cart")==null){
		session.setAttribute("cart", new java.util.ArrayList<String>());
	}

	ArrayList<String> cart = (ArrayList<String>)session.getAttribute("cart");
	cart.add("자동차,현대 소나타,8200000");
%>
<!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=EUC-KR">
<title>자동차 구입 페이지</title>
</head>
<body>
<h1>자동차를 장바구니에 담았습니다.</h1>
<a href="showCart.jsp">장바구니 내용보기</a>
</body>
</html>
showCart.jsp
<%@ page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
	ArrayList<String> cart = (ArrayList<String>)session.getAttribute("cart");
%>
<!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=EUC-KR">
<title>장바구니 보기</title>
</head>
<body>
<h1>장바구니 내용</h1>
<ol>
<%
	for(int i=0;i<cart.size();i++){
		String item = cart.get(i);%>
		<li><%=item %>
 <%}
%>

</ol>
</body>
</html>




<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
	if(application.getAttribute("count")==null){
		application.setAttribute("count",0);
	}
	int cnt =(Integer)application.getAttribute("count");
	cnt++;
	application.setAttribute("count",cnt);
%>
<!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=EUC-KR">
<title>방문자 수</title>
</head>
<body>
<h1>현재까지의 클릭한 수</h1>
<%=application.getAttribute("count") %>
</body>
</html>


reflash 할때 마다 클릭수가 바뀐다~

+ Recent posts