๋ชฉ์ฐจ
1. 2023.12.7(๋ชฉ)
F_WebApp04
ใด C:\WebStudy\WebApp04\WebContent
[HttpServlet ๊ด๋ จ ์ค์ต]
ใดใดjsptest005.html_HttpServlet ๊ด๋ จ ์ค์ต(HttpServlet ์ ์์๋ฐ๋ ํด๋์ค๋ก ์ค๊ณ)
- **์คํฌ๋ฆฝํธ์ ์ด-> id ์์ฑ, ์๋ฒ์ ์ด-> name ์์ฑ**
- โป form ํ๊ทธ์ action ์์ฑ์ ์ ์ดํฐ ์ ์ก ๋ฐ ํ์ด์ง ์์ฒญ์ ํด์ผํ๋ ๋์ ํ์ด์ง๋ฅผ ๋ฑ๋กํ๋ ๊ธฐ๋ฅ์ ์ํ.
(์๋ต ์ ๋ฐ์ดํฐ ์ ์ก ๋ฐ ํ์ด์ง ์์ฒญ์ ํ๊ฒ ๋๋ ๋์์ ์๊ธฐ ์์ )
- โป form ํ๊ทธ์ method ์์ฑ์ ๋ฐ์ดํฐ ์ ์ก ๋ฐ ํ์ด์ง ์์ฒญ์ ๋ํ ๋ฐฉ์
(์๋ต ์ ๋ฐ์ดํฐ ์ ์ก ๋ฐ ํ์ด์ง ์์ฒญ์ ํ๊ฒ ๋๋ ๋ฐฉ์์ get)
- โป submit ์ก์ -> form ๋ฐ์ดํฐ ์ ์ก ๋ฐ ํ์ด์ง ์์ฒญ


<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jsptest005.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>JSP ๊ด์ฐฐํ๊ธฐ</h1>
<hr>
</div>
<div class="layout">
<h2>HttpServlet ๊ด๋ จ ์ค์ต</h2>
<!-- โป ์
๋ ฅ ์ปจํธ๋กค์ ํ์ฉํ์ฌ ์๋ฒ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์กํ๊ธฐ ์ํด์๋ form ํ์ -->
<!-- โป form ํ๊ทธ์ action ์์ฑ์ ์ ์ดํฐ ์ ์ก ๋ฐ ํ์ด์ง ์์ฒญ์ ํด์ผํ๋ ๋์ ํ์ด์ง๋ฅผ ๋ฑ๋กํ๋ ๊ธฐ๋ฅ์ ์ํ.
(์๋ต ์ ๋ฐ์ดํฐ ์ ์ก ๋ฐ ํ์ด์ง ์์ฒญ์ ํ๊ฒ ๋๋ ๋์์ ์๊ธฐ ์์ ) -->
<!-- โป form ํ๊ทธ์ method ์์ฑ์ ๋ฐ์ดํฐ ์ ์ก ๋ฐ ํ์ด์ง ์์ฒญ์ ๋ํ ๋ฐฉ์
(์๋ต ์ ๋ฐ์ดํฐ ์ ์ก ๋ฐ ํ์ด์ง ์์ฒญ์ ํ๊ฒ ๋๋ ๋ฐฉ์์ get) -->
<form action="/WebApp04/login" method="get">
<!-- ** action="" -> ๋ด๊ฐ ๋ ์์ ์ ์ฐธ์กฐ(ex. ๋ด๊ฐ ์ ์ก, ๋ด๊ฐ ๋ฐ์ ๊ฐฑ์ ) ** -->
<!-- ** method="" -> get ๋ฐฉ์์ผ๋ก ์ฒ๋ฆฌ ** -->
<table>
<tr>
<th>์์ด๋</th>
<td>
<!-- name ์์ฑ check~!!! -->
<!-- **์คํฌ๋ฆฝํธ์ ์ด-> id ์์ฑ, ์๋ฒ์ ์ด-> name ์์ฑ** -->
<input type="text" name="userId" size="10" maxlength="10" class="txt">
</td>
</tr>
<tr>
<th>ํจ์ค์๋</th>
<td>
<!-- name ์์ฑ check~!!! -->
<input type="password" name="userPwd" size="10" class="txt">
</td>
</tr>
<tr>
<td colspan="2">
<!-- โป submit ์ก์
-> form ๋ฐ์ดํฐ ์ ์ก ๋ฐ ํ์ด์ง ์์ฒญ -->
<input type="submit" value="๋ก๊ทธ์ธ" class="btn control">
<input type="reset" value="๋ค์์
๋ ฅ" class="btn control">
</td>
</tr>
</table>
</form>
</div>
<!-- **
http://localhost:3306/WebApp04/jsptest005.jsp?userId=super&userPwd=1234
ใด '?' ์ -> ์์ฒญํ๋ ํ์ด์ง
ใด '?' ๋ค -> ์๋ต ๋ด์ฉ(& ํํ๋ก ๊ฒฐํฉ๋จ)
** -->
</body>
</html>
ใดใดTest005.java_์์ฒญ๋ฐ์ ๋ด์ฉ์ ์๋ต(์ถ๋ ฅ์คํฌ๋ฆผ ๊ตฌ์ฑ)

/* ==================
Test005.java
- Servlet ์ค์ต
=================== */
// ํ์ฌ... ์๋ฐ์ ๊ธฐ๋ณธ ํด๋์ค Test004
// ์ด๋ฅผ... Servlet ์ผ๋ก ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ
// HttpServlet ์ ์์๋ฐ๋ ํด๋์ค๋ก ์ค๊ณ -> Servlet
// ** HttpServlet์ด ๊ฐ์ฅ ์ผ๋ฐ์ ์ธ ๋ฐฉ๋ฒ **
// ** HttpServlet api -> https://docs.oracle.com/javaee%2F7%2Fapi%2F%2F/javax/servlet/http/HttpServlet.html **
/* **
์ฐ๋ฆฌ๊ฐ ํ์ด์ง๋ฅผ ์์ฒญํ๋ ๊ฒ์ด ์๋๋ผ, servlet(์๋ธ๋ฆฟ ์ปจํ
์ด๋) ์ด ์์ฒญํ๋ ๊ฒ
ใด ์ฌ์ฉ์๊ฐ get ๋ฐฉ์ -> ์๋ธ๋ฆฟ doGet
ใด ์ฌ์ฉ์๊ฐ post ๋ฐฉ์-> ์๋ธ๋ฆฟ doPost
** */
package com.test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Test005 extends HttpServlet
// ** ์ถ์ํด๋์ค์ด์ง๋ง, ๋ด๋ถ์ ์ผ๋ก ์ถ์๋ฉ์๋๋ฅผ ๊ฐ์ง๊ณ ์์ง ์์ **
{
private static final long serialVersionUID = 1L;
// ์ฌ์ฉ์์ http ํ๋กํ ์ฝ ์์ฒญ์ด GET ๋ฐฉ์์ผ ๊ฒฝ์ฐ ํธ์ถ๋๋ ๋ฉ์๋
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGetPost(request, response);
}
// ์ฌ์ฉ์์ http ํ๋กํ ์ฝ ์์ฒญ์ด POST ๋ฐฉ์์ ๊ฒฝ์ฐ ํธ์ถ๋๋ ๋ฉ์๋
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGetPost(request, response);
}
// ์ฌ์ฉ์ ์ ์ ๋ฉ์๋
protected void doGetPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// GET ๋ฐฉ์์ด๋ POST ๋ฐฉ์์ด๋
// ์ด๋ค ๋ฐฉ์์ ์์ฒญ์๋ ๋ชจ๋ ์ฒ๋ฆฌํ ์ ์๋ ์ฌ์ฉ์ ์ ์ ๋ฉ์๋
// request -> ์์ฒญ ๊ฐ์ฒด
String id = request.getParameter("userId");
// ** request ๊ฐ์ฒด๋ก๋ถํฐ userId๋ฅผ ๊บผ๋ด์ ์ธ ๊ฒ์ด๋ค. **
String pwd = request.getParameter("userPwd");
response.setContentType("text/html; charset=UTF-8");
String str="์์ด๋:" + id + ", ํจ์ค์๋: " + pwd;
// ์๋ต์ ์ถ๋ ฅ ์คํธ๋ฆผ์ผ๋ก ๊ตฌ์ฑํ๊ธฐ ์ํ ์ค๋น
PrintWriter out = response.getWriter();
// ์ถ๋ ฅ ์คํธ๋ฆผ์ ํ์ฉํด์ ํ์ด์ง ๋ ๋๋ง
out.print("<!DOCTYPE html>");
out.print("<html>");
out.print("<head>");
out.print("<meta charset=\"UTF-8\">");
// ** ์ด์ค๋ฐ์ดํ ์ฒ๋ฆฌ: "UTF-8" -> \"UTF-8\" **
out.print("<title>Test005.java</title>");
out.print("</head>");
out.print("<body>");
out.print("");
out.print("<div>");
out.print(" <h1>์๋ธ๋ฆฟ ๊ด๋ จ ์ค์ต</h1>");
out.print(" <hr>");
out.print("</div>");
out.print("");
out.print("<div>");
out.print(" <h2>HttpServlet ํด๋์ค๋ฅผ ํ์ฉํ ์๋ธ๋ฆฟ ํ
์คํธ</h2>");
out.print(" ");
out.print(" <p>" + str + "</p>");
out.print("</div>");
out.print("");
out.print("</body>");
out.print("</html>");
}
}
ใดใด web.xml_ jsp์ java๋ฅผ servlet์ ํตํด ์ฐ๊ฒฐ
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>WebApp04</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- *************************************************************************************** -->
<!-- **Servlet ๊ณผ Servlet-mapping์ด ๊ฐ์ ์ด๋ฆ์ด์ด์ผ ํจ** -->
<servlet>
<servlet-name>Test004</servlet-name> <!-- ** ๋งคํ์ ๊ตฌ๋ถํ๊ธฐ ์ํ ์ด๋ฆ ** -->
<servlet-class>com.test.Test004</servlet-class> <!-- ** Serlvet ํด๋์ค ์ด๋ฆ ** -->
</servlet>
<servlet-mapping>
<servlet-name>Test004</servlet-name>
<url-pattern>/test004</url-pattern> <!-- ** Serlvet ๋์ํ๋ URL ** -->
</servlet-mapping>
<!-- *************************************************************************************** -->
<servlet>
<servlet-name>Test005</servlet-name>
<servlet-class>com.tets.Test005</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test005</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<!-- *************************************************************************************** -->
</web-app>
ใดใดResponseSample.html_HTML ์ฝ๋ ์์ฑ์ ์ํ ์ํ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test005.java</title>
</head>
<body>
<div>
<h1>์๋ธ๋ฆฟ ๊ด๋ จ ์ค์ต</h1>
<hr>
</div>
<div>
<h2>HttpServlet ํด๋์ค๋ฅผ ํ์ฉํ ์๋ธ๋ฆฟ ํ
์คํธ</h2>
<p> </p>
</div>
</body>
</html>
[ WebApp00 ์ ServletSample.java ๋ง๋ค๊ธฐ ]


ใด/WebApp00/src/com/test/ServletSample.java
/* ==================
ServletSample.java
=================== */
package com.test;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletSample extends HttpServlet
{
private static final long serialVersionUID = 1L;
// ์ฌ์ฉ์์ http ํ๋กํ ์ฝ ์์ฒญ์ด GET ๋ฐฉ์์ผ ๊ฒฝ์ฐ ํธ์ถ๋๋ ๋ฉ์๋
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGetPost(request, response);
}
// ์ฌ์ฉ์์ http ํ๋กํ ์ฝ ์์ฒญ์ด POST ๋ฐฉ์์ ๊ฒฝ์ฐ ํธ์ถ๋๋ ๋ฉ์๋
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGetPost(request, response);
}
// ์ฌ์ฉ์ ์ ์ ๋ฉ์๋
protected void doGetPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// GET ๋ฐฉ์์ด๋ POST ๋ฐฉ์์ด๋
// ์ด๋ค ๋ฐฉ์์ ์์ฒญ์๋ ๋ชจ๋ ์ฒ๋ฆฌํ ์ ์๋ ์ฌ์ฉ์ ์ ์ ๋ฉ์๋
}
}
WebApp05
ใดWebApp05\WebContent
ใดใดHap.jsp_JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 01


<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hap.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>JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 01</h1>
<hr>
<p>Hap.jsp -> HapOk.jsp</p>
</div>
<div class="layout">
<!-- โป <form> ์ action ์์ฑ ์์ ์ ใHapOk.jspใ ๋ก ์ง์ ํด๋ ๋๊ณ
ใ/WebApp05/HapOk.jspใ ํํ๋ก ์ง์ ํด๋ ๋๋ค.
๋จ, ใ/HapOk.jspใ๋ก ์ง์ ํ๋ฉด ์๋๋ค. -->
<form action="/WebApp05/HapOk.jsp" method="post">
<!-- <form action="HapOk.jsp"> -->
<div class="input_box">
<ul>
<li>์ ์1 <input type="text" name="su1" class="txt"></li>
<li>์ ์2 <input type="text" name="su2" class="txt"></li>
</ul>
</div>
<div class="btn_box">
<input type="submit" value="๊ฒฐ๊ณผ ํ์ธ" class="btn control">
</div>
</form>
<!-- โ form ๋ด๋ถ์ ๊ตฌ์ฑํ ๋ฐ์ดํฐ๋ค์ ใHapOk.jspใ ๋ก ์ ์กํ๊ฒ ๋ค. -> su1, su2 -->
<!-- โก ใHapOk.jspใ ํ์ด์ง๋ฅผ ์์ฒญํ๊ฒ ๋ค.
-> ๋ด๊ฐ ๋ณด๋ด๋ ๋ฐ์ดํฐ๋ค์ ๋ฐ๊ณ ~ ๋๋ฅผ ๊ทธ ํ์ด์ง์ ๋ง๋ ์ ์๊ฒํด๋ค์ค~!!! -->
</div>
</body>
</html>
ใดใดHapOk.jsp_JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 01
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// ์คํฌ๋ฆฝ๋ฆฟ ์์ญ
// ์ด์ ํ์ด์ง(Hap.jsp)๋ก๋ถํฐ ๋์ด์จ ๋ฐ์ดํฐ ์์ -> su1, su2
String str1 = request.getParameter("su1");
String str2 = request.getParameter("su2");
int sum=0;
try
{
int n1 = Integer.parseInt(str1);
int n2 = Integer.parseInt(str2);
sum = n1 + n2;
}
catch(Exception e)
{
// ์์ธ ๋ฐ์ ์...
// ํด๋ผ์ด์ธํธ์ ๋ธ๋ผ์ฐ์ ํ๋ฉด์ ์ถ๋ ฅ๋์ง ์๊ณ
// ์๋ฒ์ ์ฝ์ ์ฐฝ์ ์ค๋ฅ ๋ฉ์ธ์ง๊ฐ ๋์ค๋๋ก ๊ตฌ์ฑํ๋ ์ฝ๋
System.out.println(e.toString());
// ์์ธ ๋ฐ์ ์...
// ํด๋น ๋ด์ฉ์ ์๋ฒ log ๊ธฐ๋ก์ผ๋ก ๋จ๊ธฐ๋ ์ฒ๋ฆฌ...
getServletContext().log("์ค๋ฅ: " + e.toString());
// ...
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HapOk.jsp</title>
</head>
<body>
<div>
<h1>JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 01</h1>
<hr>
<p>Hap.jsp -> HapOk.jsp</p>
</div>
<div>
<!-- <h2>๊ฒฐ๊ณผ: 10</h2> -->
<h2>๊ฒฐ๊ณผ: <%=sum %></h2>
</div>
</body>
</html>
ใดใดGugudan.jsp_JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 02


<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gugudan.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>JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 02</h1>
<hr>
<p>Gugudan.jsp -> GugudanOk.jsp</p>
</div>
<div class="layout">
<form action="/WebApp05/GugudanOk.jsp" method="post">
<table class="table">
<tr>
<th>์ํ๋ ๋จ ์
๋ ฅ</th>
<td>
<input type="text" name="dan" class="txt">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="๊ฒฐ๊ณผ ํ์ธ" class="btn control" style="width: 100%;">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
ใดใดGugudanOk.jsp_JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 02
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// [ ๋ด๊ฐ ํผ ํ์ด ] ==============================================
// ์คํฌ๋ฆฝ๋ฆฟ ์์ญ
/* int dan = 0;
String result = "";
try
{
dan = Integer.parseInt(request.getParameter("dan"));
for(int i=1; i<=9; i++)
{
// System.out.println(dan + " * " + i + " = " + dan*i);
result += (dan + " * " + i + " = " + dan*i+"<br>");
}
}
catch(Exception e)
{
System.out.println(e.toString());
}; */
// [ ํจ๊ป ํผ ํ์ด ] ==============================================
// ์ด์ ํ์ด์ง(Gugudan.jsp)๋ก ๋ถํฐ ๋ฐ์ดํฐ ์์ -> dan
String danStr = request.getParameter("dan");
int n=0;
try
{
n = Integer.parseInt(danStr);
}
catch(Exception e)
{
System.out.println(e.toString());
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>GugudanOk.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>JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 02</h1>
<hr>
<p>Gugudan.jsp -> GugudanOk.jsp</p>
</div>
<div class="layout">
<!-- // [ ๋ด๊ฐ ํผ ํ์ด ] ============================================== -->
<%--
<div class="info_box">๊ฒฐ๊ณผ: <%=dan%> ๋จ</div>
<div class="result_box"><%=result%></div>
--%>
<!-- html ์ฃผ์๋ฌธ: ๋ธ๋ผ์ฐ์ ์๊ฒ ๊ฐ์์ ์ผ๋ก ๋ณด์ง ์๋๋ก ์๋ด -> ์์ค์ฝ๋๋ณด๊ธฐ๋ก ๋ณด์ฌ์ง -->
<%-- JSP ์ฃผ์๋ฌธ: sevlet container ๊ฐ ์ธ์ํ์ง ๋ชปํ๋ ์์ญ --%>
<!-- // [ ํจ๊ป ํผ ํ์ด ] ============================================== -->
<%-- ๋ฐฉ๋ฒ1 --%>
<%-- <%
for(int i=1; i<=9; i++)
{
// System.out.println(dan + " * " + i + " = " + dan*i);
out.print(n + " * " + i + " = " + (n*i)+"<br>");
}
%> --%>
<%-- ๋ฐฉ๋ฒ2 --%>
<%for(int i=1; i<=9; i++)
{%>
<%=n%> * <%=i%> = <%=(n*i)%> <br>
<%}%>
</div>
</body>
</html>
ใดใดRadioSelect.jsp_radio, select ๋ฐ์ดํฐ ์ ์ก
// ํ๊ธ ๊นจ์ง ๋ฐฉ์ง ์ฒ๋ฆฌ
request.setCharacterEncoding("UTF-8"); // check~!!!


ใดใดRadioSelectOk.jsp_radio, select ๋ฐ์ดํฐ ์ ์ก
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// ์คํฌ๋ฆฝ๋ฆฟ ์์ญ
// ์ด์ ํ์ด์ง(RadioSelect.jsp)๋ก ๋ถํฐ ๋ฐ์ดํฐ ์์
// -> name
// ํ๊ธ ๊นจ์ง ๋ฐฉ์ง ์ฒ๋ฆฌ
request.setCharacterEncoding("UTF-8"); // check~!!!
String nameStr = request.getParameter("name"); //-- ํ
์คํธ๋ฐ์ค... ๋จ์ผ๊ฐ ์์
String genderStr = request.getParameter("gender"); //-- ๋ผ๋์ค๋ฒํผ... ๋จ์ผ๊ฐ ์์
String majorStr = request.getParameter("major"); //-- ์ ํ์์... ๋จ์ผ๊ฐ ์์
//String hobbyStr = request.getParameter("hobby");
String[] hobbyArr = request.getParameterValues("hobby");//-- ์ ํ์์... ๋ค์ค ๋ฐ์ดํฐ ์์
//-- ๋ค์ค ์ ํ์ด ๊ฐ๋ฅํ ์ ํ์์ผ ๊ฒฝ์ฐ...
// ใgetParameterValues()ใ๋ก ๋ฐ์ดํฐ ์์
// -> ๋ฐฐ์ด ๋ฐํ
// name ์์ ๋ฐ ์ฒ๋ฆฌ -> ํน์ด์ฌํญ ์์
// gender ์์ ๋ฐ ์ฒ๋ฆฌ
String gender = "";
if(genderStr.equals("M"))
gender = "๋จ์";
else if(genderStr.equals("F"))
gender = "์ฌ์";
else
gender = "ํ์ธ๋ถ๊ฐ";
// major ์์ ๋ฐ ์ฒ๋ฆฌ -> ํน์ด์ฌํญ ์์~!!!
// hobby ์์ ๋ฐ ์ฒ๋ฆฌ
String hobby = "";
if(hobbyArr != null)
{
for(String item : hobbyArr)
hobby += "[" + item + "]";
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>RadioSelectOk.jsp</title>
</head>
<body class="section">
<div>
<h1>JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 03</h1>
<hr>
<p>RadioSelect.jsp -> RadioSelectOk.jsp</p>
</div>
<div class="layout">
<h2>radio, select ๋ฐ์ดํฐ ์ ์ก</h2>
<ul>
<li><span class="tit">์ด๋ฆ: </span><%=nameStr %></li>
<li><span class="tit">์ฑ๋ณ: </span><%=genderStr %>(<%=gender %>)</li>
<li><span class="tit">์ ๊ณต: </span><%=majorStr %></li>
<li><span class="tit">์ทจ๋ฏธ: </span><%=hobby %></li>
</ul>
</div>
</body>
</html>
ใดใดCheckBox.jsp_checkbox ๋ฐ์ดํฐ ์ ์ก


<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CheckBox.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>JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 04</h1>
<hr>
<p>CheckBox.jsp -> CheckBoxOk.jsp</p>
</div>
<div class="layout">
<h2>checkbox, textarea ๋ฐ์ดํฐ ์ ์ก</h2>
<form action="/WebApp05/CheckBoxOk.jsp" method="post">
<div class="input_box" style="display: inline-block;">
<ul>
<li>
<span class="tit">์ด๋ฆ</span><input type="text" name="name" class="txt">
</li>
<li>
<span class="tit">๋ฉ๋ชจ</span><textarea name="meno" rows="5" cols="30"></textarea>
</li>
<li style="display:flex;">
<span class="tit">์ด์ํ</span>
<div>
<label><input type="checkbox" name="checkGruop" value="์กฐํด์ผ">์กฐํด์ผ</label>
<label><input type="checkbox" name="checkGruop" value="์ ์ฌ์">์ ์ฌ์</label>
<label><input type="checkbox" name="checkGruop" value="๋ฅ์ง">๋ฅ์ง</label>
<label><input type="checkbox" name="checkGruop" value="์ ์ฐ์ฑ">์ ์ฐ์ฑ</label>
<label><input type="checkbox" name="checkGruop" value="์ฐจ์์ฐ">์ฐจ์์ฐ</label>
<br>
<label><input type="checkbox" name="checkGruop" value="์นด๋ฆฌ๋">์นด๋ฆฌ๋</label>
<label><input type="checkbox" name="checkGruop" value="์๊ฐ์ค">์๊ฐ์ค</label>
<label><input type="checkbox" name="checkGruop" value="๋ฐ์๋น">๋ฐ์๋น</label>
<label><input type="checkbox" name="checkGruop" value="๊ณ ์ค์ ">๊ณ ์ค์ </label>
</div>
</li>
</ul>
<div class="btn_box"><input type="submit" value="์ ์กํ๊ธฐ" class="btn control"></div>
</div>
</form>
</div>
</body>
</html>
ใดใดCheckBoxOk.jsp_checkbox ๋ฐ์ดํฐ ์ ์ก
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// ์คํฌ๋ฆฝ๋ฆฟ ์์ญ
// ์ด์ ํ์ด์ง(CheckBox.jsp)๋ก๋ถํฐ ๋ฐ์ดํฐ ์์
//-> name, memo, checkGroup
// ํ๊ธ ๊นจ์ง ๋ฐฉ์ง ์ฒ๋ฆฌ
//**request.getParameter ๋ค์์ ํ๋ฉด ์ ์ฉ ์๋จ~!!!**
request.setCharacterEncoding("UTF-8");
// ์ด๋ฆ ๋ฐ์ดํฐ ์์
String name = request.getParameter("name");
// ๋ฉ๋ชจ ๋ฐ์ดํฐ ์์ check~!!!
//**textarea์ ๊ฐํ์ <**
String memo = request.getParameter("meno");
//memo = memo.replace("\n","<br>");
memo.replaceAll("\n","<br>");
// ** ์ ๊ทํํ์์ผ๋ก ๊ตฌ์ฑ๋ ๋ฌธ์๋ replace ๊ฐ๋ฅ **
//-- JDK 1.5 ์ดํ๋ถํฐ ใreplaceAll()ใ ๋ฉ์๋ ์ฌ์ฉ ๊ฐ๋ฅ
// ใreplaceAll()ใ ์ ํตํด ์ฒ๋ฆฌํ ๊ฒฐ๊ณผ๋ฅผ ๋ค์ memo ๋ณ์์ ๋์
// "์๋
ํ์ธ์\n๋ฐ๊ฐ์ต๋๋ค.\n์ด์ค์์
๋๋ค."
// -> "์๋
ํ์ธ์<br>๋ฐ๊ฐ์ต๋๋ค.<br>์ด์ค์์
๋๋ค."
// ์ด์ํ ๋ฐ์ดํฐ ์์
//String checkGroup = request.getParameter("checkGroup"); //(x)
// โป ๊ฐ์ name ์์ฑ์ ๊ฐ์ ๊ฐ์ง ๋ฐ์ดํฐ ์ฌ๋ฌ ๊ฐ๋ฅผ ๋ฐ๋ ๊ฒฝ์ฐ(์ฆ, ๋ค์ค ๋ฐ์ดํฐ๋ก ์์ ํ๋ ๊ฒฝ์ฐ)
// ์ด๋ฅผ ๋ฐฐ์ด๋ก ์ฒ๋ฆฌํด์ผ ํ๋ค. -> ใgetParameterValues()ใ
String[] checkGroup = request.getParameterValues("checkGruop");
// โป ๋ฐฐ์ด ๋ฐ์ดํฐ๋ฅผ ์์ ํ์ฌ ์ฒ๋ฆฌํ ๊ฒฝ์ฐ..
// ์์ ๋ ๋ฐ์ดํฐ๊ฐ ์ ํ ์๋ ๊ฒฝ์ฐ
// ๋ฐฐ์ด์ ๊ฐ ์์ฒด๊ฐ null์ด ๋์ด๋ฒ๋ฆฌ๊ธฐ ๋๋ฌธ์
// null ์ ๋ํ ํ์ธ(๊ฒ์ฌ) ๊ณผ์ ์ด ํ์ํ๋ค. check~!!!
String str = "";
if(checkGroup != null)
{
for(String item: checkGroup)
str += "["+ item + "]";
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CheckBoxOk.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>JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 04</h1>
<hr>
<p>CheckBox.jsp -> CheckBoxOk.jsp</p>
</div>
<div class="layout">
<h2>checkbox, textarea ๋ฐ์ดํฐ ์ ์ก</h2>
<ul>
<li><span class="tit">์ด๋ฆ: </span><%=name %></li>
<li><span class="tit">๋ฉ๋ชจ: </span><%=memo %></li>
<li><span class="tit">์ด์ํ:</span><%=str %></li>
</ul>
</div>
</body>
</html>
ใดใดTable.jsp_JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 05


<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Table.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>JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 05</h1>
<hr>
<p>Table.jsp -> TableOk.jsp</p>
</div>
<div class="layout">
<form action="/WebApp05/TableOk.jsp">
<table style="max-width:500px;width:100%;">
<tr>
<th>๊ฐ๋ก</th>
<td><input type="text" name="su1" class="txt"></td>
</tr>
<tr>
<th>์ธ๋ก</th>
<td><input type="text" name="su2" class="txt"></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn control" style="width:280px;">๊ฒฐ๊ณผ ํ์ธ</button>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
ใดใดTableOk.jsp_ JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 05
<%@ page contentType="text/html; charset=UTF-8"%>
<%
// ์คํฌ๋ฆฝ๋ฆฟ ์์ญ
// ๋ด๊ฐ ํผ ๋ฐฉ๋ฒ
/* // ์ด์ ํ์ด์ง(Table.jsp)๋ก๋ถํฐ ์ ์ก๋ ๋ฐ์ดํฐ ์์
//->su1, su2
int su1 = Integer.parseInt(request.getParameter("su1"));
int su2 = Integer.parseInt(request.getParameter("su2"));
int num = 1;
//[๋ค๋ฅธ์ฌ๋์ด ํผ ๋ฐฉ๋ฒ]
String result = "";
if((su1*su2)!=0){
result += "<table>";
for(int i=0; i<su2; i++)
{
result += "<tr>";
for(int j=0; j<su1; j++)
{
result += "<td>" + (num++) + "</td>";
}
result += "</tr>";
}
result += "</table>";
} */
String s1 = request.getParameter("su1");
String s2 = request.getParameter("su2");
int n1=0;
int n2=0;
//ํ
์ด๋ธ ์์์ 1์ฉ ์ฆ๊ฐ์์ผ ๋๊ฐ ๋ณ์ ์ ์ธ ๋ฐ ์ด๊ธฐํ
int n=0;
try
{
// ์์ ๋ ๋ฐ์ดํฐ ํ ๋ณํ
n1 = Integer.parseInt(s1);
n2 = Integer.parseInt(s2);
}
catch(Exception e)
{
System.out.println(e.toString());
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TableOk.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>JSP๋ฅผ ์ด์ฉํ ๋ฐ์ดํฐ ์ก์์ ์ค์ต 05</h1>
<hr>
<p>Table.jsp -> TableOk.jsp</p>
</div>
<div class="layout">
<!-- [๋ด๊ฐ ํผ ๋ฐฉ๋ฒ] -->
<%-- <%
if((su1*su2)!=0){
%>
<table>
<%
for(int i=0; i<su2; i++)
{%>
<tr>
<%
for(int j=0; j<su1; j++)
{%>
<td>
<%=num++ %>
</td>
<%}%>
</tr>
<%
}%>
</table>
<%
}
%> --%>
<!-- [๋ค๋ฅธ์ฌ๋์ด ํผ ๋ฐฉ๋ฒ] -->
<%-- <%=result %> --%>
<!-- [ํจ๊ป ํผ ๋ฐฉ๋ฒ] -->
<table>
<%
for(int i=0; i<n2; i++)
{
%>
<tr>
<%
for(int j=0; j<n1; j++)
{
%>
<td><%=++n %></td>
<%
}
%>
</tr>
<%
}
%>
</table>
</body>
</html>