JSP 내장 객체와 속성관리, 간단 예제
Posted 2008/10/30 14:15, Filed under: 학과수업들/JSP<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" %> <html> <head> <title> login.jsp </title> </head> <body> <center> <h2>로그인</h2> <form name="form1" method="post" action="selProduct.jsp"> <input type="text" name="username"/> <input type="submit" value="로그인"/> </form> </center> </body> </html>
<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" %>
<html>
<head>
<title> selProduct.jsp </title>
</head>
<body>
<%
//HTML 폼에서 전달된 데이터의 한글 인코딩
request.setCharacterEncoding("euc-kr");
//session에 username 이름으로 HTML 폼의 <input type="text" name="username" />에 입력된 값을 저장함.
session.setAttribute("username",request.getParameter("username"));
%>
<center>
<h2>상품 선택</h2>
<hr>
<%=session.getAttribute("username") %>님이 로그인한 상태입니다.
<form name="form1" method="post" action="add.jsp">
<select name="product">
<option>사과</option>
<option>귤</option>
<option>파인애플</option>
<option>자몽</option>
<option>레몬</option>
</select>
<input type="submit" value="추가"/>
</form>
<a href="checkOut.jsp">계산</a>
</center>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" import="java.util.ArrayList" %>
<html>
<head>
<title> add.jsp </title>
</head>
<body>
<%
//HTML 폼에서 전달된 데이터의 한글 인코딩
request.setCharacterEncoding("euc-kr");
String productname = request.getParameter("product");
ArrayList list = (ArrayList) session.getAttribute("productlist");
if(list == null){
list = new ArrayList();
}
list.add(productname);
session.setAttribute("productlist",list);
%>
<script>
alert("<%=productname %>이(가) 추가되었습니다!!");
history.go(-1);
</script>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=euc-kr" pageEncoding="euc-kr" import="java.util.ArrayList" %>
<html>
<head>
<title> checkOut.jsp </title>
</head>
<body>
<center>
<h2>계산</h2>
선택한 상품 목록
<hr>
<%
ArrayList list = (ArrayList) session.getAttribute("productlist");
if(list == null){
out.println("선택한 상품이 없습니다.!!!");
}
else {
for(Object productname:list){
out.println(productname+"<br>");
}
}
%>
</body>
</html>
Response :
0 Trackback
,
0 Comment
Trackback URL : http://mysilpir.net/trackback/329
