๋ชฉ์ฐจ
1. 2023.12.12(ํ)
F_WebApp07
ใด C:\WebStudy\WebApp07\WebContent
[โ ํฌ์๋ฉ / ๋ฆฌ๋ค์ด๋ ํธ ๊ด๋ จ ์ค์ํ ์ค์ต(forward ์ฒ๋ฆฌ) โ ]




ใดใดSend10.jsp_์ฌ์ฉ์ ์ต์ด ์์ฒญ ํ์ด์ง
<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Send10.jsp</title>
<!-- <link rel="stylesheet" type="text/css" href="css/main.css"> -->
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body class="section">
<div>
<h1>๋ฐ์ดํฐ ์ก์์ ์ค์ต 10</h1>
<hr>
</div>
<!-- โ โ โ ํฌ์๋ฉ / ๋ฆฌ๋ค์ด๋ ํธ ๊ด๋ จ ์ค์ํ ์ค์ต โ โ โ -->
<!-- โ ์ฌ์ฉ์ ์ต์ด ์์ฒญ ํ์ด์ง -->
<!-- ์ฌ์น ์ฐ์ฐ ์ํ์ ์ํ ์ ์ ์
๋ ฅ ํ์ด์ง ๊ตฌ์ฑ -->
<!-- ์ฐ์ฐ์๋ฅผ ํจ๊ป ์
๋ ฅ๋ฐ์ ์ ์๋๋ก ์ฒ๋ฆฌ -->
<!-- ์ ์1/ ์ ์2/ ์ฐ์ฐ์ -->
<!-- http://localhost:3306/WebApp07/Send10.jsp -->
<!-- โก ์ฐ์ฐ ์ ์ฉ ํ์ด์ง -->
<!-- ์คํฌ๋ฆฝํธ ์ฝ๋๋ง ์กด์ฌ (+ jsp:forward ์ก์
ํ๊ทธ) -->
<!-- -> ์ถํ ์ด ์ฝ๋๋ฅผ ๋
๋ฆฝ์ ์ธ java๋ก ๋ถ๋ฆฌ -> Servlet์ผ๋ก ๊ตฌ์ฑํ ์์ -->
<!-- http://localhost:3306/WebApp07/Forward10.jsp -->
<!-- โข ์ต์ข
๊ฒฐ๊ณผ ์ถ๋ ฅ ํ์ด์ง -->
<!-- ์ฐ์ฐ ์ ์ฉ ํ์ด์ง์์ ์ฒ๋ฆฌํ ๊ฒฐ๊ณผ๋ฅผ ๋๊ฒจ๋ฐ์ ํด๋ผ์ด์ธํธ์ ๋๋ฉดํ ํ์ด์ง๋ก ๊ตฌ์ฑ -->
<!-- -> ์ถํ ์ด ํ์ด์ง๋ jsp view ํ์ด์ง์ ์ญํ ์ ์ํํ ์์ -->
<!-- http://localhost:336/WebApp07/Receive10.jsp -->
<div class="layout">
<!-- JSP ์ก์
ํ๊ทธ ํ์ฉํ์ฌ forward ์ฒ๋ฆฌํ๋ ํ์ด์ง๋ก... -->
<!-- <form action="Forward10.jsp" method="post"> -->
<!-- JSP ์ก์
ํ๊ทธ ์์ด forward ์ฒ๋ฆฌํ๋ ํ์ด์ง๋ก ... -->
<form action="Forward10_1.jsp" method="post">
<div>
์ ์1
<input type="text" name="num1" class="txt" style="width: 60px;">
<select name="calResult">
<option selected="selected">์ฐ์ฐ์ ํ</option>
<option value="1">๋ํ๊ธฐ</option>
<option value="2">๋นผ๊ธฐ</option>
<option value="3">๊ณฑํ๊ธฐ</option>
<option value="4">๋๋๊ธฐ</option>
</select>
์ ์2
<input type="text" name="num2" class="txt" style="width: 60px;">
<button type="submit" class="btn control">ํ์ธ</button>
</div>
</form>
</div>
</body>
</html>
ใดใดForward10.jsp_์ฐ์ฐ ์ ์ฉ ํ์ด์ง
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// Forward10.jsp
// ์ด์ ํ์ด์ง(Send10.jsp)๋ก ๋ถํฐ ๋์ด์จ ๋ฐ์ดํฐ ์์
// -> num1, calResult, num2
String num1Str = request.getParameter("num1");
String num2Str = request.getParameter("num2");
String calResult = request.getParameter("calResult");
int num1 = 0;
int num2 = 0;
String result = "";
try
{
num1 = Integer.parseInt(num1Str);
num2 = Integer.parseInt(num2Str);
if(calResult.equals("1")) // ๋ํ๊ธฐ
result = String.format("%d + %d = %d", num1, num2, (num1+num2));
else if (calResult.equals("2")) // ๋นผ๊ธฐ
result = String.format("%d - %d = %d", num1, num2, (num1-num2));
else if (calResult.equals("3")) // ๊ณฑํ๊ธฐ
result = String.format("%d * %d = %d", num1, num2, (num1*num2));
else if (calResult.equals("4")) // ๋๋๊ธฐ
result = String.format("%d / %d = %.1f", num1, num2, (num1/num2));
}
catch(Exception e)
{
System.out.println(e.toString());
}
// ์์ฒญ์ ๋ด์ฉ ์ถ๊ฐ
request.setAttribute("resultStr", result);
// **ํ๋ผ๋ฏธํฐ๊ฐ์๋ ์์ฒญํ ๋ด์ฉ ๋ฟ ์๋๋ผ get ํ ๋ชจ๋ ๋ด์ฉ ์ฒ๋ฆฌ ๊ฐ๋ฅ**
// **๋งต ์๋ฃ๊ตฌ์กฐ. ๊ฐ์ฒด์ ํํ๋ก ๊ฐ์ ธ์ด**
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Forward10.jsp</title>
<!-- <link rel="stylesheet" type="text/css" href="css/main.css"> -->
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body class="section">
<!-- JSP ์ก์
ํ๊ทธ๋ฅผ ํ์ฉํ forward ์ฒ๋ฆฌ -->
<jsp:forward page="Receive10.jsp"></jsp:forward>
</body>
</html>
ใดใดForward10_1.jsp_์ฐ์ฐ ์ ์ฉ ํ์ด์ง
<%@ page contentType="text/html; charset=UTF-8"%> <!-- **JSP๋ผ๋ ์ ์ฒด์ฑ. ์ง์ฐ๋ฉด ์๋จ** -->
<%
// Forward10.jsp
// ์ด์ ํ์ด์ง(Send10.jsp)๋ก ๋ถํฐ ๋์ด์จ ๋ฐ์ดํฐ ์์
// -> num1, calResult, num2
String num1Str = request.getParameter("num1");
String num2Str = request.getParameter("num2");
String calResult = request.getParameter("calResult");
int num1 = 0;
int num2 = 0;
String result = "";
try
{
num1 = Integer.parseInt(num1Str);
num2 = Integer.parseInt(num2Str);
if(calResult.equals("1")) // ๋ํ๊ธฐ
result = String.format("%d + %d = %d", num1, num2, (num1+num2));
else if (calResult.equals("2")) // ๋นผ๊ธฐ
result = String.format("%d - %d = %d", num1, num2, (num1-num2));
else if (calResult.equals("3")) // ๊ณฑํ๊ธฐ
result = String.format("%d * %d = %d", num1, num2, (num1*num2));
else if (calResult.equals("4")) // ๋๋๊ธฐ
result = String.format("%d / %d = %.1f", num1, num2, (num1/num2));
}
catch(Exception e)
{
System.out.println(e.toString());
}
// ์์ฒญ์ ๋ด์ฉ ์ถ๊ฐ
request.setAttribute("resultStr", result);
// **ํ๋ผ๋ฏธํฐ๊ฐ์๋ ์์ฒญํ ๋ด์ฉ ๋ฟ ์๋๋ผ get ํ ๋ชจ๋ ๋ด์ฉ ์ฒ๋ฆฌ ๊ฐ๋ฅ**
// **๋งต ์๋ฃ๊ตฌ์กฐ. ๊ฐ์ฒด์ ํํ๋ก ๊ฐ์ ธ์ด**
// check~!!!
RequestDispatcher dispatcher = request.getRequestDispatcher("Receive10.jsp");
dispatcher.forward(request,response);
/* ==========================================================================
โ โ โ ใRequestDispatcherใ ์ธํฐํ์ด์ค โ โ โ
// **์๋ธ๋ฆฟ ์ปจํ
์ด๋๊ฐ ์ฐ๋ ๋๊ตฌ**
โป ์ด ์ธํฐํ์ด์ค๋ ใforward()ใ์ ใinclude()ใ ๋ง ์๋ค.
โป ์ฒ๋ฆฌ ๊ณผ์ ๋ฐ ๊ฐ๋
์ผ๋ฐ์ ์ผ๋ก HttpSevlet ์ ์์๋ฐ๋ ํด๋์ค... ์๋ธ๋ฆฟ
์ด๋ ๊ฒ ์์ฑ๋ ํด๋์ค ๋ด๋ถ์๋
์ค์ ์์ฒญ์ ์๋น์ค ํ๋ ใdoGet()ใ๊ณผ ใdoPost()ใ ๋ฉ์๋๊ฐ ์ ์๋์ด ์์ผ๋ฉฐ (service()๋ฉ์๋๊ฐ ์ด๋ค์ ์์ ๋ฉ์๋)
**SevletConatiner** ๋ **ใHttpSevletใ์ ์ธ์คํด์ค๋ฅผ ์์ฑ**ํ๊ณ **ใinit()ใ ๋ฉ์๋๋ฅผ ์คํ**ํด์ฃผ๊ณ ,
์ด ๋ฉ์๋์ ์ํด ๋งคํ๋ URL์ (ํ์ด์ง ์์ฒญ ๋ฐฉ์์ ๋ฐ๋ผ) **doGet()๊ณผ doPost() ์ค ์ ํํ์ฌ ๋ฉ์๋๋ฅผ ํธ์ถ**ํด์ฃผ๊ณ (์คํ์์ผ์ฃผ๊ณ )
Container ๊ฐ ์ข
๋ฃ๋ ๋ **ใdistroy()ใ ๋ฉ์๋๋ฅผ ํธ์ถ**ํด์ฃผ๊ณ , ๊ด๋ จ๋ ์ฒ๋ฆฌ ๊ณผ์ ์ด ๋ง๋ฌด๋ฆฌ ๋๋ค.
์ฆ, SevletConatiner ๊ฐ
inint() -> ์ฒ์
seveice() -> ์ค๊ฐ์ค๊ฐ ์์ฒญ์ด ์์ ๋๋ง๋ค
destroy() -> ๋ง์ง๋ง
๋ฉ์๋๋ฅผ ํธ์ถํ๋ค.(์ ๋ ์ฐ๋ฆฌ๊ฐ ์ง์ ํธ์ถํ๋ ๊ฒ์ด ์๋๋ค~!!!)
๊ฒฐ๊ตญ ใHttpSevletใ์ ํ๋์ ์ธ์คํด์ค๋ง ์์ฑ๋์ด ๋ฉํฐ ์ค๋ ๋ฉ์ผ๋ก ๋์๊ฐ๊ฒ ๋๋ค.
// **์ค๋ ๋: ํ๋์ ์์
๋จ์,**
// **๋ฉํฐ์ค๋ ๋: ์ฒ์์ ์ฐ์ฌ๋A, ๋ค์์ฌ๋์ด ์ด๊ณ ์์ B, A๊ฐ ๋ซ์ผ๋ฉด ์์๊ฐ ๊ผฌ์ผ ์ ์์ผ๋ฏ๋ก ๊ท์น์ ๋ง๋ค์ด ๋ฌด๊ฒฐ์ฑ์ ํด์น์ง ์๋๊ฒ ์ค์**
// **ใด ๋ฉํฐ ์ค๋ ๋ ์ธ์ดํํฐ vs. ๋ฉํฐ ์ค๋ ๋ ์ธ์ธ์ดํํฐ**
์ด๋ ๊ฒ ๊ตฌ์ฑ๋๋ ใHttpSevletใ์ ์์๋ ํด๋์ค์ ์ธ์คํด์ค๋ ์ค๋ ๋์ ์์ ํ๊ฒ ์ค๊ณ(์ค๋ ๋ ์ธ์ดํํฐ)๋์ด์ผ ํ๊ณ
๋ฐ๋ผ์ ์ค๋ ๋์ ์์ ํ๊ฒ ์ค๊ณ๋์ง ์์ ๊ฒฝ์ฐ ์์ ํด๋์ค๋ฅผ ๋ง๊ตฌ ์ ๊ทผํ๊ฒ ๋์ด ์๋ฌ๊ฐ ๋ฐ์ํ ์ ๋ฐ์ ์๋ค.
์ด์ ๊ฐ์ ์ด์ ๋ก ํ๊ฒฝ ์ค์ ์ด๋ J2EE ์๋น์ค์ ๊ดํ ๋ด์ฉ์ ใServletContextใ ์์ ํ ์ ์๊ฒ ๋๋ค.
(โป ServeletContext : ์๋ธ๋ฆฟ์ ๋ํ ํ๊ฒฝ, ์ํ ๋ฑ์ ์ค์ ํ ์ ์๋ ๊ฐ์ฒด)
์ด ใServeletContextใ๋ ใgetServletContext()ใ๋ก๋ง ๋ฐ์ ์ ์๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์ด ใgetServletContext()ใ๋ ๋๊ธฐํ๊ฐ ์ ๋๋ก ๊ตฌํ๋์ด ์์ ๊ฒ์ด๋ผ๊ณ ์์ธกํ ์ ์๋ค.
๊ทธ ์ด์ ๋ ๋ฉํฐ ์ค๋ ๋๊ฐ ์์ ํ๊ฒ ์ค๊ณ(์ธ์ดํํฐ)๋์ด ์์ด์ผ
์ฐ๋ฆฌ๊ฐ ใServeltContextใ์ ใsetAttribute()ใ๋ ใgetAttribute()ใ๋ฅผ ์ค๋ ๋ ๊ฑฑ์ ์์ด ๋ง์๋๋ก ์ฝ๊ณ ์ธ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
ใSevletContextใ์ ๋ ๋ค๋ฅธ ์ปค๋ค๋ ๊ธฐ๋ฅ ์ค ํ๋๋
๋ค๋ฅธ ์๋ธ๋ฆฟ ์ธ์คํด์ค๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค๊ฑฐ๋ ์๋ธ๋ฆฟ ํ๊ฒฝ ์ค์ ๊ฐ์ ๊ฐ์ ธ์ฌ ์ ์๋ ๊ธฐ๋ฅ์ด๋ค.
**ใRequestDispatcherใ** ์ญ์ ๊ทธ ๊ธฐ๋ฅ ์ค์ ํ๋์ด๋ค.
์ฌ์ ์ ์ธ ์๋ฏธ๋ก๋... ์์ฒญ์ ์ ๊ณตํ๋ **๋๊ตฌ**. ์ฆ, ์์ฒญ์ ๋ณด๋ด์ฃผ๋ **์ธํฐํ์ด์ค**์ด๋ค.
ํ์ฌ... ์์ฒญ์ ๋ค๋ฅธ ์๋ธ๋ฆฟ(ํน์ JSP)์ผ๋ก ๋ณด๋ด์ผํ๋ ์ํฉ.
๊ทธ๋ฐ๋ฐ, ์์ ์ธ๊ธํ ๋ฐ์ ๊ฐ์ด ์๋ธ๋ฆฟ์ ์ธ์คํด์ค๋ ํ๋๋ง ์์ฑ๋๊ณ ์ด๊ฒ์ด ๋ฉํฐ ์ค๋ ๋ฉ์ผ๋ก ๋์๊ฐ๊ณ ์๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์๋ก์ด ์๋ธ๋ฆฟ์ ๊ทธ ์๋ธ๋ฆฟ์ ์คํํ๋ ๊ฑฐ์ฐ์ผ๋ก๋ ์๋๊ณ
์ด๋ฏธ ๋์๊ฐ๊ณ ์๋ ์๋ธ๋ฆฟ ์ธ์คํด์ค์ ์ค๋ ๋๋ฅผ ํ๋ ๋ ์ถ๊ฐํด์ผ ํ๋ค.
์ด๊ฒ์ ์๋ธ๋ฆฟ ๊ฐ๋ฐ์๊ฐ ์ฒ๋ฆฌํด์ผ ํ ์์ญ์ ๋ฒ์ด๋ฌ๊ธฐ ๋๋ฌธ์ ์ด ์ผ์ ใDispatcherใ๊ฐ ๋์ ์ํํด ์ค๋ค๋ ๊ฒ์ด๋ค.
ํ์ง๋ง ์ด ใDispatcherใ๋
ใHttpServletRequestใ,ใHttpSevletResponseใ๋ฅผ ์์ฑํด ์ค ์ ์๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ใDispatcherใ๊ฐ ์์ฑํด์ค ์๋ก์ด ์๋ธ๋ฆฟ ์ค๋ ๋๋ฅผ ์คํ์ํค๊ธฐ์ํด ใdoGet()ใ์ด๋ ใdoPost()ใ๋ฅผ ํธ์ถํด์ผ ํ๋ค.
์ด์ ๊ฐ์ ์ด์ ๋ก ใdispatcher.forward(request, response);ใ๊ตฌ๋ฌธ์ ํตํด request ์ response ๋ฅผ ๋๊ฒจ์ฃผ๋ ๊ฒ์ด๋ค.
============================================================================= */
%>
ใดใดReceive10.jsp_์ต์ข ๊ฒฐ๊ณผ ์ถ๋ ฅ ํ์ด์ง
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// ์ด์ ํ์ด์ง(Forward10.jsp)๋ก ๋ถํฐ ๋์ด์จ ๋ฐ์ดํฐ ์์
// -> resultStr
// **setAttribute ํ ๋ด์ฉ์ ๋ฌด์กฐ๊ฑด getAttribute ํ๋ค. ๋ชจ๋ ๊ฒ์ ๋ด์ ์ ์์ผ๋ฏ๋ก Object ํ**
String result = (String)request.getAttribute("resultStr"); // ๋ค์ด์บ์คํ
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Receive10.jsp</title>
<!-- <link rel="stylesheet" type="text/css" href="css/main.css"> -->
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body class="section">
<div>
<h1>๋ฐ์ดํฐ ์ก์์ ์ค์ต 10</h1>
<hr>
</div>
<div>
<!-- <h2>์ฐ์ฐ ๊ฒฐ๊ณผ: 235</h2> -->
<h2>์ฐ์ฐ ๊ฒฐ๊ณผ: <%=result %></h2>
</div>
</body>
</html>
[โ ํฌ์๋ฉ / ๋ฆฌ๋ค์ด๋ ํธ ๊ด๋ จ ์ค์ํ ์ค์ต( redirect ์ฒ๋ฆฌ)โ ]


ใดใดSend11.jps_์ฌ์ฉ์ ์ต์ด ์์ฒญ ํ์ด์ง
<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Send11.jsp</title>
<!-- <link rel="stylesheet" type="text/css" href="css/main.css"> -->
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body class="section">
<div>
<h1>๋ฐ์ดํฐ ์ก์์ ์ค์ต 11</h1>
<hr>
</div>
<!-- โ โ โ ํฌ์๋ฉ / ๋ฆฌ๋ค์ด๋ ํธ ๊ด๋ จ ์ค์ํ ์ค์ต โ โ โ -->
<!-- โ ์ฌ์ฉ์ ์ต์ด ์์ฒญ ํ์ด์ง -->
<!-- ์ฌ์น ์ฐ์ฐ ์ํ์ ์ํ ์ ์ ์
๋ ฅ ํ์ด์ง ๊ตฌ์ฑ -->
<!-- ์ฐ์ฐ์๋ฅผ ํจ๊ป ์
๋ ฅ๋ฐ์ ์ ์๋๋ก ์ฒ๋ฆฌ -->
<!-- ์ ์1/ ์ ์2/ ์ฐ์ฐ์ -->
<!-- http://localhost:3306/WebApp07/Send11.jsp -->
<!-- โก ์ฐ์ฐ ์ ์ฉ ํ์ด์ง -->
<!-- ์คํฌ๋ฆฝํธ ์ฝ๋๋ง ์กด์ฌ (response.sendRedirect() ๋ฉ์๋ ํฌํจ) -->
<!-- -> ์ถํ ์ด ์ฝ๋๋ฅผ ๋
๋ฆฝ์ ์ธ java๋ก ๋ถ๋ฆฌ -> Servlet์ผ๋ก ๊ตฌ์ฑํ ์์ -->
<!-- http://localhost:3306/WebApp07/Forward11.jsp -->
<!-- โข ์ต์ข
๊ฒฐ๊ณผ ์ถ๋ ฅ ํ์ด์ง -->
<!-- ์ฐ์ฐ ์ ์ฉ ํ์ด์ง์์ ์ฒ๋ฆฌํ ๊ฒฐ๊ณผ๋ฅผ ๋๊ฒจ๋ฐ์ ํด๋ผ์ด์ธํธ์ ๋๋ฉดํ ํ์ด์ง๋ก ๊ตฌ์ฑ -->
<!-- -> ์ถํ ์ด ํ์ด์ง๋ jsp view ํ์ด์ง์ ์ญํ ์ ์ํํ ์์ -->
<!-- http://localhost:336/WebApp07/Receive11.jsp -->
<div class="layout">
<!-- redirect ์ฒ๋ฆฌํ๋ ํ์ด์ง๋ก ... -->
<form action="Forward11.jsp" method="post">
<div>
์ ์1
<input type="text" name="num1" class="txt" style="width: 60px;">
<select name="calResult">
<option selected="selected">์ฐ์ฐ์ ํ</option>
<option value="1">๋ํ๊ธฐ</option>
<option value="2">๋นผ๊ธฐ</option>
<option value="3">๊ณฑํ๊ธฐ</option>
<option value="4">๋๋๊ธฐ</option>
</select>
์ ์2
<input type="text" name="num2" class="txt" style="width: 60px;">
<button type="submit" class="btn control">ํ์ธ</button>
</div>
</form>
</div>
</body>
</html>
ใดใดForward11.js_์ฐ์ฐ ์ ์ฉ ํ์ด์ง
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// Redirect11.jsp
// ์ด์ ํ์ด์ง(Send11.jsp)๋ก ๋ถํฐ ๋์ด์จ ๋ฐ์ดํฐ ์์
// -> num1, calResult, num2
int num1 = Integer.parseInt(request.getParameter("num1"));
int num2 = Integer.parseInt(request.getParameter("num2"));
String op = request.getParameter("calResult");
// ์ฐ์ฐ ์ฒ๋ฆฌ
String str ="";
if (op.equals("1"))
str += String.format("%d", (num1+num2));
else if(op.equals("2"))
str += String.format("%d", (num1-num2));
else if(op.equals("3"))
str += String.format("%d", (num1*num2));
else if(op.equals("4"))
str += String.format("%.1f", (num1/(double)num2));
// check~!!!
// ์ฌ์ฉ์์๊ฒ ์์ฒญํ ํ์ด์ง๋ฅผ ์๋ด
//response.sendRedirect("Receive11.jsp");
// check~!!!
// ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ์ฌ์ ์ก -> sendRedirect() ๋ฉ์๋ ์ฌ์ฉ
// โป response ๊ฐ์ฒด์ ์ค์ ๋ฉ์๋ ์ค ํ๋์ธ
// ใsendRedirect(String location)ใ: ์ง์ ๋ URL(location)๋ก ์์ฒญ์ ์ฌ์ ์กํ๋ค.
// ์ฆ, ์ฌ์ฉ์๊ฐ ๋ค์ ํด๋น ์์ฒญ์ ์ํํ ์ ์๋๋ก ํ๋ดํ๋ค.
response.sendRedirect("Receive11.jsp?num1="+num1+"&num2="+num2+"&op="+op+"&str="+str);
//-- ํด๋ผ์ด์ธํธ์ Receive11.jsp ํ์ด์ง๋ฅผ ๋ค์ ์์ฒญํ ์ ์๋๋ก ์๋ด~!!!
// ์ด์ ๋ํ์ฌ... get ๋ฐฉ์์ ์์ฒญ URL ๊ตฌ์ฑ์ ํตํด ๋๊ธธ ๋ฐ์ดํฐ ์ฒ๋ฆฌ~!!!
%>
ใดใดReceive11.jsp_์ต์ข ๊ฒฐ๊ณผ ์ถ๋ ฅ ํ์ด์ง
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// ์ด์ ํ์ด์ง(Redirect11.jsp)๋ก ๋ถํฐ ๋์ด์จ ๋ฐ์ดํฐ์ ์์
// ใReceive11.jsp?num1=27&num2=27&op=4&str1.0ใ์ ๊ฐ์ ํํ~!!! check~!!!
//-- ์ง์ Redirect11.jsp ๋ก ๋ถํฐ ๋ฐ์ดํฐ๋ฅผ ๋๊ฒจ๋ฐ๋ ๊ฒ์ด ์๋๋ผ
// ํด๋ผ์ด์ธํธ๊ฐ ์๋ก์ด ์์ฒญ์ ํ๋ ๊ณผ์ ์์ ๋๊ธด ๊ฐ์ ์์ ํ๊ฒ ๋๋ ๊ฐ๋
~!!! check~!!!
String num1 = request.getParameter("num1");
String num2 = request.getParameter("num2");
String op = request.getParameter("op");
String str = request.getParameter("str");
if(op.equals("1"))
op = "+";
else if(op.equals("2"))
op = "-";
else if(op.equals("3"))
op = "*";
else if(op.equals("4"))
op = "/";
String strResult = String.format("%s %s %s = %s", num1, op, num2, str);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Receive11.jsp</title>
<!-- <link rel="stylesheet" type="text/css" href="css/main.css"> -->
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body class="section">
<div>
<h1>๋ฐ์ดํฐ ์ก์์ ์ค์ต 11</h1>
<hr>
</div>
<div>
<!-- <h2>์ฐ์ฐ ๊ฒฐ๊ณผ: 223</h2> -->
<h2>์ฐ์ฐ ๊ฒฐ๊ณผ: <%=strResult %></h2>
</div>
</body>
</html>
F_WebApp08
ใดC:WebStudy/WebApp08/WebContent/Test001.jsp
[๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ค์ต]
ใดใดTest001.jsp_ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ค์ต

<%@page import="java.sql.Connection"%>
<%@page import="com.util.DBConn"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%
String str = "";
try
{
Connection conn = DBConn.getConnection();
if(conn != null)
str += "๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ฑ๊ณต~!!!";
}
catch(Exception e)
{
//System.out.println(e.toString());
str += e.toString();
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test001.jsp</title>
<!-- <link rel="stylesheet" type="text/css" href="css/main.css"> -->
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body class="section">
<div>
<h1>๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ค์ต</h1>
<hr>
</div>
<div>
<!-- <h2>ํ์ธ๊ฒฐ๊ณผ : ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ฑ๊ณต~!!!</h2> -->
<h2>ํ์ธ๊ฒฐ๊ณผ : <%=str %></h2>
</div>
</body>
</html>
[๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ๋ฐ ๋ฐ์ดํฐ ์ฒ๋ฆฌ]


ใดใด WebApp08_scott.sql
SELECT USER
FROM DUAL;
--==>> SCOTT
SELECT *
FROM TAB;
-- ํด์งํต ๋น์ฐ๊ธฐ
PURGE RECYCLEBIN;
--==>> RECYCLEBIN์ด(๊ฐ) ๋น์์ก์ต๋๋ค.
SELECT *
FROM TAB;
-- ๊ธฐ์กด ํ
์ด๋ธ ์ ๊ฑฐ
DROP TABLE TBL_MEMBER;
--==>> Table TBL_MEMBER์ด(๊ฐ) ์ญ์ ๋์์ต๋๋ค.
--------------------------------------------------------------------------------
--โ ์ค์ต ํ
์ด๋ธ ์์ฑ(TBL_MEMVER)
CREATE TABLE TBL_MEMBER
( SID NUMBER
, NAME VARCHAR2(30)
, TEL VARCHAR2(40)
, CONSTRAINT MEMBER_SID_PK PRIMARY KEY(SID)
);
--==>> Table TBL_MEMEBER์ด(๊ฐ) ์์ฑ๋์์ต๋๋ค.
--โ ์ํ์ค ์์ฑ (MEMBERSEQ)
CREATE SEQUENCE MEMBERSEQ
NOCACHE;
--==>> Sequence MEMBERSEQ์ด(๊ฐ) ์์ฑ๋์์ต๋๋ค.
--โ ๋ฐ์ดํฐ ์
๋ ฅ ์ฟผ๋ฆฌ๋ฌธ ๊ตฌ์ฑ
INSERT INTO TBL_MEMBER(SID,NAME, TEL)
VALUES(MEMBERSEQ.NEXTVAL, '๋ฌธ์ ํ', '010-1111-1111');
--> ํ์ค๊ตฌ์ฑ
INSERT INTO TBL_MEMBER(SID, NAME, TEL) VALUES(MEMBERSEQ.NEXTVAL, '๋ฌธ์ ํ', '010-1111-1111')
;
--โ ์ํ ๋ฐ์ดํฐ ์ถ๊ฐ ์
๋ ฅ
INSERT INTO TBL_MEMBER(SID, NAME, TEL) VALUES(MEMBERSEQ.NEXTVAL, '์ ํ์ธ', '010-2222-2222')
;
INSERT INTO TBL_MEMBER(SID, NAME, TEL) VALUES(MEMBERSEQ.NEXTVAL, '์ตํ์ธ', '010-3333-3333')
;
INSERT INTO TBL_MEMBER(SID, NAME, TEL) VALUES(MEMBERSEQ.NEXTVAL, '๊ธธํ์ฑ', '010-4444-4444')
;
--โ ํ
์ด๋ธ ์ ์ฒด ์กฐํ ์ฟผ๋ฆฌ๋ฌธ ๊ตฌ์ฑ(๋ฆฌ์คํธ ํ์ธ)
SELECT SID, NAME, TEL
FROM TBL_MEMBER
ORDER BY SID;
--> ํ์ค ๊ตฌ์ฑ
SELECT SID, NAME, TEL FROM TBL_MEMBER ORDER BY SID
;
--==>>
/*
1 ๋ฌธ์ ํ 010-1111-1111
2 ์ ํ์ธ 010-2222-2222
3 ์ตํ์ธ 010-3333-3333
4 ๊ธธํ์ฑ 010-4444-4444
*/
--โ ์ธ์ ์ ํ์ธ ์ฟผ๋ฆฌ๋ฌธ ๊ตฌ์ฑ
SELECT COUNT(*) AS COUNT
FROM TBL_MEMBER;
--> ํ์ค ๊ตฌ์ฑ
SELECT COUNT(*) AS COUNT FROM TBL_MEMBER
;
--==>> 4
--โ ์ปค๋ฐ
COMMIT;
--==>> ์ปค๋ฐ ์๋ฃ.
ใดใดTest002.jsp_๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ๋ฐ ๋ฐ์ดํฐ ์ฒ๋ฆฌ
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="com.util.DBConn"%>
<%@page import="java.sql.Connection"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%
/* **ํ์ฌ๋ String์ ์ฐ์ง๋ง, ๋์ค์๋ String Buffer๋, Stringbuilder ์จ์ผํจ** */
// ๊ฒฐ๊ณผ๊ฐ ๋ณ์
String str ="";
// ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ
Connection conn = DBConn.getConnection();
// ์ฟผ๋ฆฌ๋ฌธ ์ค๋น(select)
String sql = "SELECT SID, NAME, TEL FROM TBL_MEMBER ORDER BY SID";
// ์์
๊ฐ์ฒด ์คํ ๋ฐ ์ฟผ๋ฆฌ๋ฌธ ์คํ
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
// ๊ฒฐ๊ณผ ResultSet ์ ๋ํ ์ฒ๋ฆฌ -> ๋ฐ๋ณต๋ฌธ ๊ตฌ์ฑ
str += "<table class ='table' style='width: 100%;'>";
str += "<tr>";
str += "<th id='numTitle'>๋ฒํธ</th>";
str += "<th id='nameTitle'>์ด๋ฆ</th>";
str += "<th id='telTitle'>์ ํ๋ฒํธ</th>";
str += "</tr>";
while(rs.next())
{
str += "<tr>";
str += "<td>"+rs.getString("SID")+"</td>";
str += "<td>"+rs.getString("NAME")+"</td>";
str += "<td>"+rs.getString("TEL")+"</td>";
str += "</tr>";
}
str += "</table>";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test002.jsp</title>
<!-- <link rel="stylesheet" type="text/css" href="css/main.css"> -->
<link rel="stylesheet" type="text/css" href="css/style.css">
<style type="text/css">
input {width: 200px;}
button {width: 208px; height: 50px; font-weight: bold;}
#numTitle {width: 50px;}
#nameTitle {width: 100px;}
#telTitle {width: 160px;}
.errMsg {font-weight: small; color: red;}
.table tr:not(first-child){text-align: center;}
</style>
</head>
<body class="section">
<script type="text/javascript">
// ํ์ ์
๋ ฅ ํญ๋ชฉ (-> ์ด๋ฆ)์ ๋ํ ๊ธฐ๋ณธ์ ์ธ ์
๋ ฅ ํ๋ฉด
function formCheck()
{
//alert('ํจ์ ํธ์ถ~!!!');
var uName = document.getElementById("userName");
var uErr = document.getElementBId("nameErr");
nameErr.style.display = "none";
if(uName.value=="")
{
nameErr.style.display="inline";
return false;
}
return false;
}
</script>
<div>
<h1>๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ๋ฐ ๋ฐ์ดํฐ ์ฒ๋ฆฌ</h1>
<hr>
</div>
<div class="layout">
<!-- ๋ฐ์ดํฐ ์
๋ ฅ -->
<form class="_box" action="MemberInsert.jsp" method="post" onsubmit="return formCheck()">
<table style="background:white;">
<tr>
<th>์ด๋ฆ(*)</th>
<td>
<input type="text" id="userName" name="userName" class="txt">
<span class="errMsg" id="nameErr">์ด๋ฆ์ ์
๋ ฅํด์ผ ํฉ๋๋ค.</span>
</td>
</tr>
<tr>
<th>์ ํ๋ฒํธ</th>
<td><input type="text" id="userTel" name="userTel" class="txt"></td>
</tr>
<tr>
<th></th>
<td><button type="submit" id="btnAdd" class="btn control">๋ฐ์ดํฐ ์ถ๊ฐ</button></td>
</tr>
</table>
</form>
<div class="result_box">
<%=str %>
<!-- ์ฒ๋ฆฌ๊ฒฐ๊ณผ -->
<!-- <table class ="table" style="width: 100%;">
<tr>
<th id="numTitle">๋ฒํธ</th>
<th id="nameTitle">์ด๋ฆ</th>
<th id="telTitle">์ ํ๋ฒํธ</th>
</tr>
<tr>
<td>5</td>
<td>๋ฐ๋์</td>
<td>010-5555-5555</td>
</tr>
<tr>
<td>6</td>
<td>์ ํ์ฑ</td>
<td>010-6666-6666</td>
</tr>
</table> -->
</div>
</div>
</body>
</html>
ใดใดMemberinsert.jsp_์ด์ ํ์ด์ง(Test002.jsp)๋ก ๋ถํฐ ๋์ด์จ ๋ฐ์ดํฐ ์์
<%@page import="java.sql.Statement"%>
<%@page import="com.util.DBConn"%>
<%@page import="java.sql.Connection"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// MemberInsert.jsp
// ์ด์ ํ์ด์ง(Test002.jsp)๋ก ๋ถํฐ ๋์ด์จ ๋ฐ์ดํฐ ์์
// -> userName, userTel
// ํ๊ธ ๊นจ์ง ๋ฐฉ์ง ์ฒ๋ฆฌ
request.setCharacterEncoding("UTF-8");
String uName = request.getParameter("userName");
String uTel = request.getParameter("userTel");
// ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ
Connection conn = DBConn.getConnection();
// ์ฟผ๋ฆฌ๋ฌธ ์ค๋น(insert)
String sql = String.format("INSERT INTO TBL_MEMBER(SID, NAME, TEL)"
+ " VALUES(MEMBERSEQ.NEXTVAL, '%s', '%s')", uName, uTel);
// DB ์ก์
์ฒ๋ฆฌ -> ์์
๊ฐ์ฒด ์์ฑ ๋ฐ ์ฟผ๋ฆฌ๋ฌธ ์ํ
Statement stmt = conn.createStatement();
int result = 0;
result = stmt.executeUpdate(sql);
stmt.close();
DBConn.close();
if(result <1)
{
// ์
๋ ฅ ์ก์
์ฒ๋ฆฌ๊ฐ ์ ์์ ์ผ๋ก ์ด๋ฃจ์ด์ง์ง ์์ ๊ฒฝ์ฐ
response.sendRedirect("Error.jsp");
//-- ๋ด๊ฐ ์ ์๋ ์๋ฌ ํ์ด์ง ์๊ฐ์์ผ์ค๊ฒ..
}
else
{
// ์
๋ ฅ ์ก์
์ฒ๋ฆฌ๊ฐ ์ ์์ ๊ธ๋ก ์ด๋ฃจ์ด์ง ๊ฒฝ์ฐ
response.sendRedirect("Test002.jsp");
//-- ์ด ํ์ด์ง๋ก ์ค๊ธฐ ์ ์ ๋ค๊ฐ ๋จธ๋ฌผ๋ ๋ฆฌ์คํธ ํ์ด์ง ์ฃผ์๋ฅผ ์๋กญ๊ฒ ๋ค์ ์์ฒญํด์ ์ฐพ์๊ฐ๋ด~!!!
// ๋ค๊ฐ ์
๋ ฅํ๋ ค๋ ๋ด์ฉ์ด ์ถ๊ฐ๋ ์ํ๋ก ๋ฆฌ์คํธ์ ๋ด์ฉ์ด ๋ฐ๋์ด ์์๊ฑฐ์ผ...
}
%>
F_WebApp09
ใดC:WebStudy/WebApp09/WebContent/
[์ด๋ฆ, ๊ตญ์ด์ ์, ์์ด์ ์, ์ํ์ ์๋ฅผ ์ ๋ ฅ๋ฐ์ ์ด์ ๊ณผ ํ๊ท ์ ๊ณ์ฐํ์ฌ ๋ฆฌ์คํธ๋ฅผ ์ถ๋ ฅ]

ใดใด WebApp09_scott.sql
SELECT USER
FROM DUAL;
--==>> SCOTT
--โ ๊ธฐ์กด ํ
์ด๋ธ ์ ๊ฑฐ
DROP TABLE TBL_SCORE;
--==>>Table TBL_SCORE์ด(๊ฐ) ์ญ์ ๋์์ต๋๋ค.
--โ ์ค์ต ํ
์ด๋ธ ์์ฑ(TBL_SCORE)
CREATE TABLE TBL_SCORE
( SID NUMBER
, NAME VARCHAR2(30)
, KOR NUMBER(3)
, ENG NUMBER(3)
, MAT NUMBER(3)
);
--==>> Table TBL_SCORE์ด(๊ฐ) ์์ฑ๋์์ต๋๋ค.
--โ ์์ฑ๋ ํ
์ด๋ธ์ ์ ์ฝ์กฐ๊ฑด ์ถ๊ฐ
ALTER TABLE TBL_SCORE
ADD CONSTRAINT SCORE_SID_PK PRIMARY KEY(SID);
--==>> Table TBL_SCORE์ด(๊ฐ) ๋ณ๊ฒฝ๋์์ต๋๋ค.
ALTER TABLE TBL_SCORE
ADD CONSTRAINT SCORE_KOR_CK CHECK(KOR BETWEEN 0 AND 100);
--==>> Table TBL_SCORE์ด(๊ฐ) ๋ณ๊ฒฝ๋์์ต๋๋ค.
ALTER TABLE TBL_SCORE
ADD CONSTRAINT SCORE_ENG_CK CHECK(ENG BETWEEN 0 AND 100);
--==>> Table TBL_SCORE์ด(๊ฐ) ๋ณ๊ฒฝ๋์์ต๋๋ค.
ALTER TABLE TBL_SCORE
ADD CONSTRAINT SCORE_MAT_CK CHECK(MAT BETWEEN 0 AND 100);
--==>> Table TBL_SCORE์ด(๊ฐ) ๋ณ๊ฒฝ๋์์ต๋๋ค.
--โ ๊ธฐ์กด ์ํ์ค ์ ๊ฑฐ
DROP SEQUENCE SCORESEQ;
--==>> Sequence SCORESEQ์ด(๊ฐ) ์ญ์ ๋์์ต๋๋ค.
--โ ์ค์ต ๊ด๋ จ ์ํ์ค ๋ค์ ์์ฑ
CREATE SEQUENCE SCORESEQ
NOCACHE;
--==>> Sequence SCORESEQ์ด(๊ฐ) ์์ฑ๋์์ต๋๋ค.
--โ ๋ฆฌ์คํธ ์กฐํ ์ฟผ๋ฆฌ๋ฌธ ๊ตฌ์ฑ
-- (๋ฒํธ, ์ด๋ฆ, ๊ตญ์ด์ ์, ์์ด์ ์, ์ํ์ ์, ์ด์ , ํ๊ท )
SELECT SID, NAME, KOR , ENG, MAT
, (KOR+ENG+MAT) AS TOT
, (KOR+ENG+MAT)/3 AS AVG
FROM TBL_SCORE
ORDER BY SID;
--==>> ํ ์ค ๊ตฌ์ฑ
SELECT SID, NAME, KOR , ENG, MAT , (KOR+ENG+MAT) AS TOT , (KOR+ENG+MAT)/3 AS AVG FROM TBL_SCORE ORDER BY SID;
--โ ๋ฐ์ดํฐ ์
๋ ฅ ์ฟผ๋ฆฌ๋ฌธ ๊ตฌ์ฑ
INSERT INTO TBL_SCORE(SID, NAME, KOR, ENG, MAT)
VALUES(SCORESEQ.NEXTVAL, '์ํ์ฑ', 90, 80, 70);
--==> ํ ์ค ๊ตฌ์ฑ
INSERT INTO TBL_SCORE(SID, NAME, KOR, ENG, MAT) VALUES(SCORESEQ.NEXTVAL, '์ํ์ฑ', 90, 80, 70)
;
--==>> 1 ํ ์ด(๊ฐ) ์ฝ์
๋์์ต๋๋ค.
--โ ์ํ ๋ฐ์ดํฐ ์ถ๊ฐ ์
๋ ฅ
INSERT INTO TBL_SCORE(SID, NAME, KOR, ENG, MAT) VALUES(SCORESEQ.NEXTVAL, '์ด์ค์', 80, 70, 60);
--==>> 1 ํ ์ด(๊ฐ) ์ฝ์
๋์์ต๋๋ค.
--โ ํ์ธ
SELECT *
FROM TBL_SCORE;
--==>>
/*
1 ์ํ์ฑ 90 80 70
2 ์ด์ค์ 80 70 60
*/
--โ ์ปค๋ฐ
COMMIT;
--==>> ์ปค๋ฐ ์๋ฃ.
ใดใด ScoreList.jsp
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="com.util.DBConn"%>
<%@page import="java.sql.Connection"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%
String str ="";
Connection conn = DBConn.getConnection();
String sql = "SELECT SID, NAME, KOR , ENG, MAT "
+ ", (KOR+ENG+MAT) AS TOT , (KOR+ENG+MAT)/3 AS AVG FROM TBL_SCORE ORDER BY SID";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
/* <table>
<tr>
<th>๋ฒํธ</th><th>์ด๋ฆ</th><th>๊ตญ์ด์ ์</th><th>์์ด์ ์</th><th>์ํ์ ์</th><th>์ด์ </th><th>ํ๊ท </th>
<tr>
<tr>
<td>1</td><td>์ํ์ฑ</td><td>90</td><td>60</td><td>70</td><td>xxx</td><td>xx.x</td>
</tr>
</table> */
str += "<table class ='table' style='width: 100%;'>";
str += "<tr>";
str += "<th>๋ฒํธ</th><th>์ด๋ฆ</th><th>๊ตญ์ด์ ์</th><th>์์ด์ ์</th><th>์ํ์ ์</th><th>์ด์ </th><th>ํ๊ท </th>";
str += "</tr>";
while(rs.next())
{
str += "<tr>";
str += "<td>"+rs.getString("SID")+"</td>";
str += "<td>"+rs.getString("NAME")+"</td>";
str += "<td>"+rs.getString("KOR")+"</td>";
str += "<td>"+rs.getString("ENG")+"</td>";
str += "<td>"+rs.getString("MAT")+"</td>";
str += "<td>"+rs.getString("TOT")+"</td>";
str += "<td>"+String.format("%.1f",rs.getDouble("AVG"))+"</td>";
str += "</tr>";
}
str += "</table>";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ScoreList.jsp</title>
<!-- <link rel="stylesheet" type="text/css" href="css/main.css"> -->
<link rel="stylesheet" type="text/css" href="css/style.css">
<style type="text/css">
[id^="err"] {display:none;}
</style>
</head>
<body class="section">
<script type="text/javascript">
function scoreInsert()
{
var uName = document.getElementById("userName");
var korStr = document.getElementById("userKor");
var engStr = document.getElementById("userEng");
var matStr = document.getElementById("userMat");
var uKor = Number(korStr);
var uEng = Number(engStr);
var uMat = Number(matStr);
var eName = document.getElementById("errName");
var eKor = document.getElementById("errKor");
var eEng = document.getElementById("errEng");
var eMat = document.getElementById("errMat");
eName.style.display = "none";
eName.style.display = "none";
eName.style.display = "none";
eName.style.display = "none";
/* -------------------------------------------- */
if(uName.value == "" || uName.value == null)
{
eName.style.display = "inline";
return false;
}
if(uKor.value<0 || uKor.value>100 || korStr.value== "")
{
eKor.style.display = "inline";
return false;
}
if(uEng.value<0 || uEng.value>100 || engStr.value== "")
{
eEng.style.display = "inline";
return false;
}
if(uMat.value<0 || uMat.value>100 || matStr.value== "")
{
eMat.style.display = "inline";
return false;
}
return true;
}
</script>
<!-- โ WebApp09
- ์ฌ๋ฌ ๋ช
์ ์ด๋ฆ, ๊ตญ์ด์ ์, ์์ด์ ์, ์ํ์ ์๋ฅผ ์
๋ ฅ๋ฐ์
์ด์ ๊ณผ ํ๊ท ์ ๊ณ์ฐํ์ฌ ๋ฆฌ์คํธ๋ฅผ ์ถ๋ ฅํด์ค ์ ์๋ ํ๋ก๊ทธ๋จ์ ๊ตฌํํ๋ค.
- ๋ฆฌ์คํธ ์ถ๋ ฅ ์ ๋ฒํธ ์ค๋ฆ ์ฐจ์ ์ ๋ ฌํ์ฌ ์ถ๋ ฅํ ์ ์๋๋ก ํ๋ค.
- ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๋ํ์ฌ ์ฒ๋ฆฌํ๋ค.(TBL_SCORE, SCORESEQ ํ์ฉ)
- ์ฆ, ์ฑ์ ์ฒ๋ฆฌ ํ๋ก๊ทธ๋จ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๋ํ์ฌ JSP๋ก ๊ตฌ์ฑํ ์ ์๋๋ก ํ๋ค.
๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ๋ฐ ๋ฐ์ดํฐ ์ฒ๋ฆฌ
---------------------------------------------------
์ฑ์ ์ฒ๋ฆฌ
์ด๋ฆ(*) [ textbox ] -> ์ด๋ฆ ์
๋ ฅ ํ์ธ
๊ตญ์ด์ ์ [ textbox ] -> 0~100 ์ฌ์ด์ ์ ์๊ฐ ์
๋ ฅ๋์๋์ง ํ์ธ
์์ด์ ์ [ textbox ] -> 0~100 ์ฌ์ด์ ์ ์๊ฐ ์
๋ ฅ๋์๋์ง ํ์ธ
์ํ์ ์ [ textbox ] -> 0~100 ์ฌ์ด์ ์ ์๊ฐ ์
๋ ฅ๋์๋์ง ํ์ธ
< ์ฑ์ ์ถ๊ฐ > -> button
๋ฒํธ ์ด๋ฆ ๊ตญ์ด์ ์ ์์ด์ ์ ์ํ์ ์ ์ด์ ํ๊ท
1 ์ํ์ฑ 90 80 70 xxx xx.x
2 ์ด์ค์ 90 80 70 xxx xx.x
โ WebApp09_scott.sql
ScoreList.jsp
ScoreInsert.jsp -> ์ฌ์ฉ์ ์๋ง๋จ
com.util.DBConn.java
-->
<div>
<h1>์ฑ์ ๋ฆฌ์คํธ๋ฅผ ์ถ๋ ฅ ํ๋ก๊ทธ๋จ</h1>
<hr>
</div>
<div class="layout">
<form action="ScoreInsert.jsp" method="post" onsubmit="return scoreInsert()">
<table>
<tr>
<th>์ด๋ฆ(*)</th>
<td>
<input type="text" id="userName" name="userName">
<span id="errName">์ด๋ฆ์ ์
๋ ฅํด์ฃผ์ธ์.</span>
</td>
</tr>
<tr>
<th>๊ตญ์ด์ ์</th>
<td>
<input type="text" id="userKor" name="userKor">
<span id="errKor">๊ตญ์ด์ ์(0~100)</span>
</td>
</tr>
<tr>
<th>์์ด์ ์</th>
<td>
<input type="text" id="userEng" name="userEng">
<span id="errEng">์์ด์ ์(0~100)</span>
</td>
</tr>
<tr>
<th>์ํ์ ์</th>
<td>
<input type="text" id="userMat" name="userMat">
<span id="errMat">์ํ์ ์(0~100)</span>
</td>
</tr>
</table>
<div class="btn_box">
<button type="submit" id="resultBtn" name="resultBtn" class="btn">์ฑ์ ์ถ๊ฐ</button>
</div>
</form>
<div class="result_box">
<!-- <table>
<tr>
<th>๋ฒํธ</th><th>์ด๋ฆ</th><th>๊ตญ์ด์ ์</th><th>์์ด์ ์</th><th>์ํ์ ์</th><th>์ด์ </th><th>ํ๊ท </th>
<tr>
<tr>
<td>1</td><td>์ํ์ฑ</td><td>90</td><td>60</td><td>70</td><td>xxx</td><td>xx.x</td>
</tr>
</table> -->
<%=str %>
</div>
</div>
</body>
</html>
ใดใดScoreInsert.jsp
<%@page import="java.sql.Statement"%>
<%@page import="com.util.DBConn"%>
<%@page import="java.sql.Connection"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%
//ScoreInsert.jsp
request.setCharacterEncoding("UTF-8");
String uName = request.getParameter("userName");
int uKor = Integer.parseInt(request.getParameter("userKor"));
int uEng = Integer.parseInt(request.getParameter("userEng"));
int uMat = Integer.parseInt(request.getParameter("userMat"));
Connection conn = DBConn.getConnection();
String sql = String.format("INSERT INTO TBL_SCORE(SID, NAME, KOR, ENG, MAT)"
+ " VALUES(SCORESEQ.NEXTVAL, '%s', %d, %d, %d)",uName, uKor, uEng, uMat);
Statement stmt = conn.createStatement();
int result = 0;
result = stmt.executeUpdate(sql);
stmt.close();
DBConn.close();
if(result <1)
{
response.sendRedirect("Error.jsp");
}
else
{
response.sendRedirect("ScoreList.jsp");
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ScoreInsert.jsp</title>
<!-- <link rel="stylesheet" type="text/css" href="css/main.css"> -->
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
</body>
</html>