일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- #C언어#숫자비교#삼항연산자
- #C언어#성적처리#점수#등급
- #자바스크립트#시계#실시간시계
- #자바스크립트#alert
- #db#데이터베이스#select
- #C언어#사각형
- #C언어#switch#case#계산기#함수
- #C언어#scanf#fflush
- #클릭#숨기기#보이기
- #자바스크립트#텍스트#알람#alert
- #db#where
- #html#테이블#table
- #alert#자바스크립트#checkbox#alert
- #증감#연산자
- #C언어#타입#printf
- #html#프레임
- #C언어#do#while#계산기
- #getElementById#id
- #C언어#do#while#계산기#함수
- #select#from#distinct
- #C언어#if
- #자바스크립트#접속시간#시간
- #C언어#for#간단#예제
- #db#froup#by
- #자바스크립트#만년달력#달력
- #자바스크립트#회원가입#유효성#검사
- #db#join#inner#cross
- #jQuery#mouse#over
- #db#order#by
- #alert#자바스크립트#radio#check
- Today
- Total
선택장애
JSP - 장바구니(물건추가, 로그아웃)Session 본문
login.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>Insert title here</title>
</head>
<body>
<form name ="form1" action="setProduct.jsp" method="post">
<h1>로그인</h1>
<input type="text" name="name" >
<input type="submit" name="login" value = "로그인">
</body>
</html>
///////////////////////////////////////////////
setProduct.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">
<%
request.setCharacterEncoding("euc-kr");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<% String name = request.getParameter("name");
//앞에서 입력한 name값을 받아서 뿌려준다.
%>
<%if(name == null){
out.println("<script>alert('로그인 하세요'); history.go(-1); </script>");
}
//name이 비었을 때 다음페이지로 넘어갈려고할때의 예외처리
%>
<%= name%>님이 로그인 한 상태 입니다.<br><br><br>
<form name="form2" action="add.jsp" method="post">
<select name="fruit3">
<option value="사과">사과</option>
<option value="배">배</option>
<option value="오렌지">오렌지</option>
<option value="키위">키위</option>
</select>
<input type="submit" name="add" value="추가버튼">
</form>
<br><br>
<a href="checkOut.jsp">계산<>
</body>
</html>
/////////////////////////////////////////////
add.jsp
<%@page import="java.util.ArrayList"%>
<%@ 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>add.jsp</title>
</head>
<body>
<%
request.setCharacterEncoding("EUC-KR");
String productname = request.getParameter("fruit3");
ArrayList list = (ArrayList)session.getAttribute("productlist");
if(list == null){
list = new ArrayList();
session.setAttribute("productlist", list);
}
list.add(productname);
%>
<%if(productname == null){
out.println("<script>alert('과일을 고르세요'); history.go(-1); </script>");
} %>
<script>
alert("<%=productname %>이(가) 추가되었습니다!!");
history.go(-1);
</script>
</body>
</html>
//////////////////////////////////
checkOut.jsp
<%@page import="java.util.ArrayList"%>
<%@ 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>checkOut.jsp</title>
</head>
<body>
<div align="center">
<h2>계산</h2>
선택한 상품 목록
<hr>
<%
ArrayList list = (ArrayList)session.getAttribute("productlist");
if(list == null){
out.println("선택한 상품이 없습니다.!!");
} else {
for(Object productname:list){
out.println(productname+"<br>");
}
}
session.invalidate();
%>
</div>
<form action="logout.jsp">
<input type="submit" value="로그아웃"/>
</form>
</body>
</html>
/////////////////////////////////////////////
로그아웃시 session을 죽여주는 클래스
logout.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">
<%session.invalidate();
response.sendRedirect("login.jsp");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
'JSP' 카테고리의 다른 글
JSP - Application(name이름넘기기, count값 올리기) (0) | 2017.08.14 |
---|---|
JSP - Sesstion(alert) (0) | 2017.08.14 |
JSP - request사용하기 (select와 checkbox값받기) (0) | 2017.08.14 |
JSP - Forward_Action, response.sendRedirect (0) | 2017.08.14 |