Notice
Recent Posts
Recent Comments
Link
«   2026/03   »
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 31
Tags
more
Archives
Today
Total
관리 메뉴

ALLYES

[2022년 청년친화형 기업 ESG지원 사업 - 30] 본문

ESG

[2022년 청년친화형 기업 ESG지원 사업 - 30]

Allyes_99 2022. 10. 14. 17:50

일시 : 2022.10.14

시간 : 9:00 ~ 18:00


오전/오후 : JSP


  • out 객체
    • Servlet class에서 getWriter 메소드를 호출해서 얻은 PrinterWriter 객체와 비슷한 역할
    • out.print(" ")
  • request 객체
    • Client가 Server로 요청할 때 HTTP Message로 구성해 여러 정보를 사용할 수 있도록 저장하고 관리하는 내장객체
  • response 객체
    • JSP page의 실행결과를 Web Browser로 되돌려줄 때 사용하는 내장객체
      • response.sendRedirect() 
        • 현재 실행중인 JSP page의 실행을 중단하고 다른 Web page가 대신 호출되도록 만드는 기능
        • response.sendRedirect("이동할 주소");
        • redirect 방식으로 페이지 이동

  • response.sendRedirect()
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<h1>내장 객체 Response</h1>
	
	<%
		// response.sendRedirect("이동할 주소");
		// redirect 방식으로 페이지 이동
		
		// redirect : ??		
		response.sendRedirect("http://www.naver.com/");
	
	%>
</body>
</html>

  • 페이지 이동 - moveUrl.html
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<form action="Ex10moveUrl.jsp">
		<select name="select">
			<option value = "https://www.naver.com">네이버</option>
			<option value = "https://www.daum.net">다음</option>
			<option value = "https://www.google.com">구글</option>
		</select> 
		<input type="submit" value="페이지로 이동">
	</form>
</body>
</html>
  • 페이지 이동 - moveUrl.jsp 
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<% 
	String url = request.getParameter("select");
	response.sendRedirect(url);
	%>
	
	<%-- 다른 방법
		String site = "";
		if(url.equals("네이버")){
			site = "http://www.naver.com/";
		}
		else if(url.equals("구글")){
			site = "http://www.google.co.kr/";
		}
		else if(url.equals("다음")){
			site = "http://www.daum.net/";
		}
		// 3.페이지 이동
		// 페이지 이동하는 코드는 한 파일에서 한번만 실행 되어야 한다.
		response.sendRedirect(url);
	 --%>
	
</body>
</html>

  • 로그인 페이지 - html
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<h1>로그인</h1>
	<form action="Ex11login.jsp">
		<input type ="text" name = "ID" placeholder = "ID를 입력하세요." ><br>
		<input type ="password" name = "PW" placeholder = "PW를 입력하세요."><br>
		<input type ="submit" value ="로그인">
	</form>
</body>
</html>
  • 로그인 페이지 - login.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<%
	
	String id = request.getParameter("ID");
	String pw = request.getParameter("PW");
	
	String result = "";
	if(id.equals("smart") && pw.equals("1234")){
		result = "Ex11loginTrue.jsp";
	}
	else{
		result = "Ex11loginFalse.jsp";
	}
	response.sendRedirect(result);
	%>
</body>
</html>
  • 로그인 페이지 - loginTrue.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<h2>Smart님 환영합니다!</h2>
</body>
</html>
  • 로그인 페이지 - loginFalse.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<h2>로그인 정보를 다시 확인해 주세요</h2>
	<a href ="Ex11login.html">로그인페이지</a>
</body>
</html>

 

 


 

  • cookie & session
    • client의 정보를 지속적으로 유지하기 위한 방법
  • Cookie
    • 전달할 데이터를 Web Browser(Client)로 보냈다가 Web Server로 되돌려 받는 방법
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<%
		// Cookie & Session - Client의 정보를 지속적으로 유지하기 위한 방법
		// Cookie - 저장할 데이터를 Client의 Browser에 저장하는 방법
		
		// Cookie 저장 흐름
		// 1.쿠키를 맛있게 굽는다(생성한다)
		// 2.쿠키안에 사랑의 메세지(전달또는 저장하고싶은 내용)를 작성한다
		// 3.Client에게 몰래 전달(전송)하면 성공
		Cookie cookie = new Cookie("id", "pbk");
		// 쿠키의 나이 설정
		cookie.setMaxAge(60*60*24*365);
		
		response.addCookie(cookie);
			
		// id : key값
		// pbk : 전달하고 싶은 message
		
		// Cookie의 특징
		// 1.쿠키는 Text 형태의 자료만 저장할 수 있다
		// 2.쿠키의 나이를 따로 설정할 수 있으니 나이를 설정안하면
		//		브라우저 종료시 쿠키는 만료된다.
		// 3.쿠키는 무한정으로 생성이 불가능 하며 한 도메인당 20개,
		// 		쿠키 하나당 총 4KB까지 생성이 가능하다
		
	%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<%
		Cookie cookie1 = new Cookie("name1", "박병관");
		Cookie cookie2 = new Cookie("name2", "이수환");
		Cookie cookie3 = new Cookie("name3", "안현진");

		response.addCookie(cookie1);
		response.addCookie(cookie2);
		response.addCookie(cookie3);
		
		// Client가 가지고 있는 Cookie 꺼내기
		Cookie[] cookies = request.getCookies();
		for(int i =0; i< cookies.length; i++){
			out.print("쿠키 이름: ");
			out.print(cookies[i].getName());
			out.print(" &nbsp; 쿠키값 : ");
			out.print(cookies[i].getValue());
			out.print("<br>");
		}
	%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<%
		// 쿠키를 삭제하는 방법
		// - 동일한 이름을 가진 쿠키를 생성해서 Client에게 보내면
		// 	 최근에 생성한 쿠키로 덮어씌여짐
		//   그렇다면 삭제하고 싶은 이름의 쿠키를 생성해서
		//   나이를 0으로 하고 보내면 쿠키가 삭제가 된다.
		Cookie cookie = new Cookie("id", "");
		cookie.setMaxAge(0);
		response.addCookie(cookie);

	%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
	pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
	href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script
	src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script
	src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style type="text/css">
img {
	width: 150px;
	height: 100px;
}

table {
	width: 100%;
	text-align: center;
}

input[type="checkbox"] {
	width: 15px;
	height: 15px;
}
</style>
</head>
<body>
	<form action="MarketAddItem" method="post">
		<div class="container">
			<h2>ESG-C반 마켓 홈페이지</h2>
			<div class="panel panel-default">
				<div class="panel-heading">
					원하시는 상품을 골라주시길 바랍니다.
					<button type = "submit" class="btn btn-sm btn-primary">담기</button>
					<button type = "reset" class="btn btn-sm btn-primary">취소</button>
				</div>
				<div class="panel panel-default"
					style="position: fixed; right: 0px; top: 200px; width: 200px; height: 300px; text-align: center;">
					<h4>내가 고른 상품</h4>

				</div>


				<div class="panel-body">
					<table>
						<tr>
							<td><label for="img1"><img class="img-circle"
									src="img/img1.jpg"></label></td>
							<td><label for="img2"><img class="img-circle"
									src="img/img2.jpg"></label></td>
							<td><label for="img3"><img class="img-circle"
									src="img/img3.jpg"></label></td>
							<td><label for="img4"><img class="img-circle"
									src="img/img4.jpg"></label></td>
						</tr>
						<tr>
							<td><input value = "뉴발" name = "goods" id="img1" type="checkbox"></td>
							<td><input value = "삼선" name = "goods" id="img2" type="checkbox"></td>
							<td><input value = "나이키" name = "goods" id="img3" type="checkbox"></td>
							<td><input value = "휠라" name = "goods" id="img4" type="checkbox"></td>
						</tr>
						<tr>
							<td>뉴발</td>
							<td>삼선</td>
							<td>나이키</td>
							<td>휠라</td>
						</tr>
						<tr>
							<td><label for="img5"><img class="img-circle"
									src="img/img5.jpg"></label></td>
							<td><label for="img6"><img class="img-circle"
									src="img/img6.jpg"></label></td>
							<td><label for="img7"><img class="img-circle"
									src="img/img7.jpg"></label></td>
							<td><label for="img8"><img class="img-circle"
									src="img/img8.jpg"></label></td>
						</tr>
						<tr>
							<td><input value = "네셔널지오그래픽" name = "goods" id="img5" type="checkbox"></td>
							<td><input value = "팔도비빔면" name = "goods" id="img6" type="checkbox"></td>
							<td><input value = "삼양라면" name = "goods" id="img7" type="checkbox"></td>
							<td><input value = "악어 " name = "goods" id="img8" type="checkbox"></td>
						</tr>
						<tr>
							<td>네셔널지오그래픽</td>
							<td>팔도비빔면</td>
							<td>삼양라면</td>
							<td>악어</td>
						</tr>

					</table>
				</div>
				<div class="panel-footer">담장자 : 가가 연락처 : 010-1111-1111</div>
			</div>
		</div>
	</form>
</body>
</html>