안효원 안효원 2021-08-17
JSPDay4End
@c15da364041d36ffb73b5a9c34848e9852cf8b22
202108/.classpath
--- 202108/.classpath
+++ 202108/.classpath
@@ -1,13 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+	<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
 	<classpathentry kind="src" path="src/main/java"/>
-	<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0">
+	<classpathentry exported="true" kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0">
 		<attributes>
 			<attribute name="owner.project.facets" value="jst.web"/>
 		</attributes>
 	</classpathentry>
 	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
 	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
+	<classpathentry exported="true" kind="lib" path="C:/project/mariadb-java-client-2.7.3.jar"/>
 	<classpathentry kind="output" path="build/classes"/>
 </classpath>
 
202108/src/main/java/Action.java (added)
+++ 202108/src/main/java/Action.java
@@ -0,0 +1,49 @@
+
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Servlet implementation class Action
+ */
+@WebServlet("/Action")
+public class Action extends HttpServlet {
+	private static final long serialVersionUID = 1L;
+       
+    /**
+     * @see HttpServlet#HttpServlet()
+     */
+    public Action() {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+	/**
+	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
+	 */
+	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		
+		response.getWriter().append("Served at: ").append(request.getContextPath());
+		String id = request.getParameter("userId");
+		String pw = request.getParameter("userPw");
+		
+		PrintWriter out = response.getWriter();
+		out.println("\n\n"+"Id : "+id);
+		out.println("\n"+"P/W : "+pw);
+	}
+
+	/**
+	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
+	 */
+	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		// TODO Auto-generated method stub
+		doGet(request, response);
+	}
+
+}
 
202108/src/main/java/study/DB.java (added)
+++ 202108/src/main/java/study/DB.java
@@ -0,0 +1,32 @@
+package study;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+public class DB {
+	
+	// 데이터베이스 연결 관련 변수 선언
+	Connection conn = null;
+	PreparedStatement pstmt = null;
+	ResultSet ps = null;
+	
+	// 데이터베이스 연결관련 정보를 문자열로 선언
+	String driver = "org.mariadb.jdbc.Driver";
+	String url = "jdbc:mariadb://localhost:3306/mydb";
+	
+	
+	public void conn() {
+		try {
+			Class.forName(driver);
+			conn = DriverManager.getConnection(url, "root", "1234");
+			System.out.println("Database Connect Success!!");
+		} catch (Exception e) {
+			e.printStackTrace();
+			System.out.println("Database Connects Fail!!");
+		}
+		
+	}
+
+}
 
202108/src/main/java/study/DBTest.java (added)
+++ 202108/src/main/java/study/DBTest.java
@@ -0,0 +1,43 @@
+package study;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Servlet implementation class DBTest
+ */
+@WebServlet("/DBTest")
+public class DBTest extends HttpServlet {
+	private static final long serialVersionUID = 1L;
+       
+    /**
+     * @see HttpServlet#HttpServlet()
+     */
+    public DBTest() {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+	/**
+	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
+	 */
+	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		
+		DB db = new DB();
+		db.conn();
+		
+	}
+
+	/**
+	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
+	 */
+	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		// TODO Auto-generated method stub
+		doGet(request, response);
+	}
+
+}
 
202108/src/main/webapp/0813/form.html (added)
+++ 202108/src/main/webapp/0813/form.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+	<form action="/202108/Action">
+		Id : <input type="text" name="userId"><br />
+		P/W : <input type="password" name="userPw"><br />
+		<input type="submit" value="Send">
+		<input type="reset" value="Reset">
+	</form>
+</body>
+</html>(No newline at end of file)
 
202108/src/main/webapp/0817/forward_action.jsp (added)
+++ 202108/src/main/webapp/0817/forward_action.jsp
@@ -0,0 +1,6 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<% request.setCharacterEncoding("UTF-8");  %>
+<jsp:forward page="response_result.jsp">
+	<jsp:param value="010-1111-2222" name="tel"/>
+</jsp:forward>(No newline at end of file)
 
202108/src/main/webapp/0817/redirect_action.jsp (added)
+++ 202108/src/main/webapp/0817/redirect_action.jsp
@@ -0,0 +1,1 @@
+<%response.sendRedirect("response_result.jsp"); %>(No newline at end of file)
 
202108/src/main/webapp/0817/request.html (added)
+++ 202108/src/main/webapp/0817/request.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html lang="ko">
+<head>
+<meta charset="UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+	<h2>Request Test Form</h2>
+	<form action="request.jsp" method="post">
+		이름 : <input type="text" name="username"><br />
+		직업 : <select name="job">
+			<option value="무직">무직</option>
+			<option value="회사원">회사원</option>
+			<option value="전문직">전문직</option>
+			<option value="학생">학생</option>
+		</select><br />
+ 		관심분야 :
+ 		<label><input type="checkbox" name="favorite" value="정치"> 정치</label>
+ 		<label><input type="checkbox" name="favorite" value="사회"> 사회</label>
+ 		<label><input type="checkbox" name="favorite" value="정보통신"> 정보통신</label><br /><br />
+ 		<input type="submit"value="확인">
+ 		<input type="submit"value="취소">
+	</form>
+</body>
+</html>(No newline at end of file)
 
202108/src/main/webapp/0817/request.jsp (added)
+++ 202108/src/main/webapp/0817/request.jsp
@@ -0,0 +1,36 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<%
+	request.setCharacterEncoding("utf-8");
+	String name = request.getParameter("username");
+	String job = request.getParameter("job");
+	/* 다중 checkBox로 인한 변수 배열화 */
+	String[] favorite = request.getParameterValues("favorite");
+%>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+	<h2>Request Test Form <em>client</em></h2>
+	<hr />
+	<%
+		out.println("이름 : " + name + "<br>");
+		out.println("직업 : " + job + "<br>");
+		out.println("관심분야 :");
+		for(int i = 0; i < favorite.length; i++){
+			out.println(favorite[i] + ",");	
+		}
+	%>
+	<br /><br /><br />
+	Client IP Address : <%=request.getRemoteAddr() %> <br />
+	Client IP Port : <%=request.getRemotePort() %> <br />
+	Request Method : <%=request.getMethod() %> <br />
+	Request Protocol : <%=request.getProtocol() %> <br />
+
+	
+	
+</body>
+</html>(No newline at end of file)
 
202108/src/main/webapp/0817/response.jsp (added)
+++ 202108/src/main/webapp/0817/response.jsp
@@ -0,0 +1,20 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Response 내장 객체 Test</title>
+</head>
+<body>
+	<h2>Forward, sendRediect Test</h2>
+	<form action="forward_action.jsp" method="post">
+		forward Action : <input type="text" name="username">
+		<input type="submit" value="Send">
+	</form>
+	<form action="redirect_action.jsp" method="post">
+		sendRediect Action : <input type="text" name="username">
+		<input type="submit" value="send">
+	</form>
+</body>
+</html>(No newline at end of file)
 
202108/src/main/webapp/0817/response_result.jsp (added)
+++ 202108/src/main/webapp/0817/response_result.jsp
@@ -0,0 +1,15 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<!DOCTYPE html>
+<html lang="ko">
+<head>
+<meta charset="UTF-8">
+<title>Response Result print Page</title>
+</head>
+<body>
+	지금 보이는 화면은 response_result.jsp에서 출력한 결과입니다.
+	<hr />
+	이름 : <%=request.getParameter("username") %> <br />
+	전화번호 : <%=request.getParameter("tel") %>
+</body>
+</html>(No newline at end of file)
 
202108/src/main/webapp/0817/session.jsp (added)
+++ 202108/src/main/webapp/0817/session.jsp
@@ -0,0 +1,22 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Session 내장 객체 Test</title>
+</head>
+<body>
+	<h2>session 내장 객체</h2>
+	<hr />
+	<%
+		if(session.isNew()){
+			out.println("<script>alert('세션이 해제되어 다시 설정합니다.')</script>");
+			session.setAttribute("login", "risker");
+		}
+	%>
+	<%=session.getAttribute("login") %>님 환영합니다.!! <br />
+	세션 아이디 : <%=session.getId() %> <br />
+	세션 유지기간 : <%=session.getMaxInactiveInterval() %>
+</body>
+</html>(No newline at end of file)
 
202108/src/main/webapp/WEB-INF/lib/mariadb-java-client-2.7.3.jar (Binary) (added)
+++ 202108/src/main/webapp/WEB-INF/lib/mariadb-java-client-2.7.3.jar
Binary file is not shown
 
202108/src/main/webapp/shopping/add.jsp (added)
+++ 202108/src/main/webapp/shopping/add.jsp
@@ -0,0 +1,33 @@
+<%@page import="java.util.ArrayList"%>
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<%
+	request.setCharacterEncoding("UTF-8");
+	String product = request.getParameter("product");
+	
+	/*세션에 저장되 있는 list가져오기*/
+	ArrayList list = (ArrayList)session.getAttribute("productlist");
+					/*Casting*/
+	
+	/*만약 세션에 저장되 있는 list가 없다면 새로운 list를 세션에 저장*/
+	if(list == null){
+		list = new ArrayList(); /*새로운 list 저장*/
+		session.setAttribute("productlist", list); //세션에 list 저장
+	}
+	list.add(product);   //list에 장바구니 물품 추가
+%>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>add Cart</title>
+</head>
+<body>
+	<script>
+		alert("<%=product %> was added!");
+		
+		/*뒤로가기*/
+		history.go(-1);
+	</script>
+</body>
+</html>(No newline at end of file)
 
202108/src/main/webapp/shopping/check.jsp (added)
+++ 202108/src/main/webapp/shopping/check.jsp
@@ -0,0 +1,33 @@
+<%@page import="java.util.ArrayList"%>
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<%
+	
+%>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Cart List</title>
+</head>
+<body>
+	<h2>Calculating</h2>
+	selected Product List
+	<hr />
+	<%
+		/* 세션에 저장되어 있는 productlist를 arraylist에 저장 */
+		ArrayList list = (ArrayList)session.getAttribute("productlist");
+		
+		/* 세션에 productlist가 없으며 */
+		if(list == null){
+			out.println("None selected product!!!");
+		}else{
+			
+			/* productname이라는 이름으로 list에서 값을 하나씩 꺼냄 */
+			for(Object productname:list){
+				out.println(productname+"<br>");
+			}
+		}
+	%>
+</body>
+</html>(No newline at end of file)
 
202108/src/main/webapp/shopping/login.jsp (added)
+++ 202108/src/main/webapp/shopping/login.jsp
@@ -0,0 +1,16 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Login</title>
+</head>
+<body>
+	<h2>Login</h2>
+	<form action="selProduct.jsp" method="post">
+		<input type="text" name="username">
+		<input type="submit" value="Login">
+	</form>
+</body>
+</html>(No newline at end of file)
 
202108/src/main/webapp/shopping/selProduct.jsp (added)
+++ 202108/src/main/webapp/shopping/selProduct.jsp
@@ -0,0 +1,36 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<%
+	request.setCharacterEncoding("UTF-8");
+	session.setAttribute("username", request.getParameter("username"));
+%>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Product List</title>
+<style>
+	#page {width: 720px; margin: 0 auto;}
+</style>
+</head>
+<body>
+	<div id="page">
+		<h2>Select Product</h2>
+		<hr />
+		
+		<%=session.getAttribute("username") %> was login
+		<hr />
+		<form action="add.jsp" method="post">
+			<select name="product">
+				<option value="hood">Hood</option>
+				<option value="jean">Jean</option>
+				<option value="coat">Coat</option>
+				<option value="padding">Padding</option>
+				<option value="short">Short</option>
+			</select>
+			<input type="submit" value="add Cart">
+		</form>
+		<a href="check.jsp">Calculating</a>
+	</div>
+</body>
+</html>(No newline at end of file)
Add a comment
List