[Day4] JSP/Servlet 4 [12/7]
์ง๋ฌธ ๋ต๋ณ
test01.jsp -> ์์ฒญ -> ์น์๋ฒ(์ํ์น) -> WAS(ํฐ์บฃ) jsp -> ์๋ธ๋ฆฟํด๋์ค
<- ์๋ต404 ์๋ฐ์ฝ๋ฉ JASPER
์๋ฒ ๋จผ์ ์คํ
์น์ปจํ ์ด๋(์๋ธ๋ฆฟ๊ฐ์ฒด๋ค์ด ์์ฑ ์๋ฉธ)
* WAS์ JASPER๊ฐ ์๋ธ๋ฆฟ๊ฐ์ฒด ๋ง๋ฆ
์๋ต๋ฐ์ดํฐ : ํผ์ผํธ(์๋ฒ์์ ์คํ) ์๋ธ๋ฆฟ ๊ฐ์ฒด ์์ฑ๋๊ณ
์๋ผ์ ํ๋ ์ด์ : ์ฑ๋ฅ (ํผ์ผํธ ๋ฐ์์ ํ๋ ๊ฒ์ด WAS๊น์ง ์๊ฐ๊ธฐ ๋๋งค)
1. ex01.jsp ํ์ด์ง์์ ์๋ ๋งํฌ ํ๊ทธ๋ฅผ ํด๋ฆญํ ๋.
<a href="<%= contextPath %>/test/test00.htm">test00.htm</a>
2. ์๋ธ๋ฆฟ( TestDeptEmp.java ) ์ ํธ์ถํ๊ณ
๊ฒฐ๊ณผ๋ฌผ request ์ ์ฅ
ํฌ์๋ฉ.
package days04;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.util.DBConn;
import domain.DeptDTO;
import domain.EmpDTO;
@WebServlet("/test/test00.htm")
public class TestDeptEmp extends HttpServlet {
private static final long serialVersionUID = 1L;
public TestDeptEmp() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Get ๋ฐฉ์ ์์ฒญ ์ฒ๋ฆฌ.
System.out.println(" > /test/test00.htm(get) ->TestDeptEmp.doGet() ํธ์ถ๋จ.");
// [1๋ฒ ]
// 1. ๋ถ์์ ๋ณด
// 2. ์ฌ์์ ๋ณด
int pdeptno = 10;
try{
pdeptno = Integer.parseInt( request.getParameter("deptno") );
}catch(NumberFormatException e){ }
//
Connection conn = DBConn.getConnection();
PreparedStatement pstmt = null;
ResultSet rs = null;
// 1. ๋ถ์ ์ ๋ณด
ArrayList<DeptDTO> deptList = null;
String sql = "SELECT deptno, dname, loc "
+" FROM dept ";
try{
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() ){
deptList = new ArrayList<>();
do{
DeptDTO dto = new DeptDTO( rs.getInt("deptno"), rs.getString("dname"), rs.getString("loc"));
deptList.add(dto);
}while( rs.next() );
} // if
pstmt.close();
rs.close();
}catch(Exception e){
e.printStackTrace();
} // try
//
// 2. ํด๋น ๋ถ์์ ์ ๋ณด
ArrayList<EmpDTO> empList = null;
sql = "SELECT * "
+" FROM emp "
+" WHERE deptno = ? "
+" ORDER BY ename ASC";
try{
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, pdeptno );
rs = pstmt.executeQuery();
if( rs.next() ){
empList = new ArrayList<>();
do{
// empno, ename, job, hiredate, mgr, sal, comm, deptno
EmpDTO dto = new EmpDTO(
rs.getInt("empno")
, rs.getString("ename")
, rs.getString("job")
, rs.getDate("hiredate")
, rs.getInt("mgr")
, rs.getDouble("sal")
, rs.getDouble("comm")
, rs.getInt("deptno")
);
empList.add(dto);
}while( rs.next() );
} // if
pstmt.close();
rs.close();
}catch(Exception e){
e.printStackTrace();
} // try
DBConn.close();
// deptList, empList => request ๊ฐ์ฒด ์ ์ฅ.
request.setAttribute("deptList", deptList);
request.setAttribute("empList", empList);
request.setAttribute("name", "hong gil dong");
// [2๋ฒ ํฌ์๋ฉ ]
// String path = "ex01_forward.jsp";
// http://localhost/jspPro/test/ex01_forward.jsp
// String path = "days04/ex01_forward.jsp";
// http://localhost/jspPro/test/days04/ex01_forward.jsp
String path = "/days04/ex01_forward.jsp";
// http://localhost/jspPro/days04/ex01_forward.jsp
RequestDispatcher dispatcher = request.getRequestDispatcher(path);
dispatcher.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
3. ex01_forward.jsp ํ์ด์ง๋ก ํฌ์๋ฉ ์์ผ์
3์ผ์ฐจ_์บก์ณ_01.png
select ํ๊ทธ์์ ๋ถ์๋ฅผ ์ ํํ๋ฉด change ์ด๋ฒคํธ ๋ฐ์ -> ์๋ธ๋ฆฟ ํธ์ถ
<%@page import="java.util.Iterator"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="com.util.DBConn"%>
<%@page import="java.sql.Connection"%>
<%@page import="domain.EmpDTO"%>
<%@page import="domain.DeptDTO"%>
<%@page import="java.util.ArrayList"%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
// ์ฌ๋ฌ ํ์ด์ง์ ๊ณตํต์ ์ผ๋ก ํ์ํ ๋ณ์ ( include ์ง์์ ์ฌ์ฉํ๋ค. )
String contextPath = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2022. 12. 7. ์ค์ 10:44:49</title>
<link rel="shortcut icon" type="image/x-icon" href="../images/SiSt.ico">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<style>
table{
width:100%;
min-width: 700px;
}
table, th, td{
border:1px solid gray;
}
</style>
</head>
<body>
<h3>ex01_forward.jsp</h3>
<select id="selDept" name="deptno">
<!-- request.setAttribute("deptList", deptList); -->
<c:forEach items="${ deptList }" var="dto">
<option value= "${ dto.deptno }">${ dto.dname }</option>
</c:forEach>
</select>
<br>
<br>
<table>
<thead>
<tr>
<th><input type="checkbox" id="ckbAll" name="ckbAll">์ ์ฒด ์ ํ</th>
<th>empno</th>
<th>ename</th>
<th>job</th>
<th>hiredate</th>
<th>mgr</th>
<th>sal</th>
<th>comm</th>
<th>deptno</th>
</tr>
</thead>
<tbody>
<c:choose>
<c:when test="${ not empty empList }">
<c:forEach items="${ empList }" var="dto">
<tr>
<td><input type="checkbox" name="ckbEmp" data-empno="${ dto.empno }"></td>
<td>${ dto.empno }</td>
<td>${ dto.ename }</td>
<td>${ dto.job }</td>
<td>${ dto.hiredate }</td>
<td>${ dto.mgr }</td>
<td>${ dto.sal }</td>
<td>${ dto.comm }</td>
<td>${ dto.deptno }</td>
</tr>
</c:forEach>
</c:when>
<c:otherwise>
<tr>
<td colspan="9" style="text-align: center">employee does not exist.</td>
</tr>
</c:otherwise>
</c:choose>
</tbody>
<tfoot>
<tr>
<td colspan="9" style="text-align: center">
<button id="checkedEmpno">์ ํํ empno ํ์ธ</button>
</td>
</tr>
</tfoot>
</table>
<p id="demo"></p>
<script>
$("#selDept").change(function() {
location.href = "<%= contextPath %>/test/test00.htm?deptno=" + $(this).val();
}); // change
</script>
<script>
$("#selDept").val( "${ empty param.deptno ? 10 : param.deptno}" );
</script>
<script>
$("#ckbAll").change( function (){
$("table tbody tr")
.find("td:first-child :checkbox")
.prop("checked", $(this).prop("checked") );
}); // change
</script>
<script>
$("#checkedEmpno").on("click" , function (){
var empnos = [];
$("table tbody :checkbox[name=ckbEmp]:checked").each(function(i, element) {
var empno = $(this).data("empno");
empnos.push( empno );
}); // each
location.href="<%= contextPath %>/days04/ex01_finsish.jsp?empno=" + empnos.join("&empno=");
}); // click
</script>
</body>
</html>
4. 3์ผ์ฐจ_์บก์ณ_02.png ํ๋ฉด์ฒ๋ผ ์ฒดํฌ๋ฐ์ค๋ฅผ ์ฒดํฌ ํ
ํ์ธ ๋ฒํผ์ ํด๋ฆญํ๋ฉด
3์ผ์ฐจ_์บก์ณ_03.png ์ ๊ฐ์ด ex01_finsish.jsp ์์ ์ถ๋ ฅ
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2022. 12. 7. ์ค์ 11:30:43</title>
<link rel="shortcut icon" type="image/x-icon" href="../images/SiSt.ico">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<h3>ex01_finsish.jsp</h3>
<!--
http://localhost/jspPro/days04/ex01_finsish.jsp
?
empno=7499
&
empno=7698
-->
<%
String [] empnos = request.getParameterValues("empno");
for(int i=0; i< empnos.length ; i++){
%>
<li><%= empnos[i] %></li>
<%
}
%>
<hr>
<!-- JSTL + EL -->
<!-- JSTL ๋ณ์ ์ ์ธ ํ๊ทธ -->
<h3>JSTL + EL ์ฌ์ฉ</h3>
<c:set var="length" value="<%= empnos.length %>"></c:set>
<c:forEach var="i" begin="0" end="${ length-1 }">
<li>${ paramValues.empno[i] }</li>
</c:forEach>
(day3)
ex08.jsp -> ex08_02.jsp -> ex08_03.jsp
์ด๋ฆ ์ฃผ์
๋์ด ์ฐ๋ฝ์ฒ
์๋ธ๋ฐ ์๋ธ๋ฐ
<form action="ex08_02.jsp" method="get">
name : <input type="text" name="name" value="ํ๊ธธ๋"><br>
age : <input type="text" name="age" value="20"><br>
<input type="submit" value="Next">
</form>
*history back : ๊ธฐ์ต๋ ๊ฐ์ผ๋ก ์ ๋ ฅํ๋ ๊ฒ
* ํ์ด์ง ์ฌ๋ฌ๊ฐ ๋์ด๊ฐ๋ ์ฟ ํค / ์ธ์ / DB ์ ์ฅ (์ํ๊ด๋ฆฌ)
08.2์
* url ์ฟผ๋ฆฌ์ ๊ทธ๋ฅ ๊ฐ ๊ทธ๋๋ก ์ถ๊ฐํด๋ฒ๋ฆฌ๊ธฐ (formํ๊ทธ ์์ hidden ์ผ๋ก ๋๊ฒจ์ฃผ๊ธฐ)
1)
<input type = "hidden" name = "name" value = "<%= name %>">
2)
<%
Enumeration<String> en = requeset.getParameterNames();
while(en.hasMoreElements()) {
String pname = en.nextElement();
String pvalue = request.getParameter(pname);
%>
$("form").appen("<input type='hidden' name='<%= pname %>' value='<%= pvalue %>">");
<%
} // while
%>
JDBC ์์ days03. [ Ex03.java/Ex03_02.java/Ex03_03.java ]
[์คํ๊ฒฐ๊ณผ] 1๋ฑ๊ธ ( 700 ~ 1200 ) - 2๋ช 20 RESEARCH 7369 SMITH 800.00 30 SALES 7900 JAMES 950.00 2๋ฑ๊ธ ( 1201 ~ 1400 ) - 3๋ช 10 ACCOUNTING 7934 MILLER 1300.00 30 SALES 7654 MARTIN 1250.00 30 SALES 7521 WARD 1250.00 3๋ฑ๊ธ ( 1401 ~ 2000 ) - 2๋ช 30 SALES 7844 TURNER 1500.00 30 SALES 7499 ALLEN 1600.00 4๋ฑ๊ธ ( 2001 ~ 3000 ) - 4๋ช 10 ACCOUNTING 7782 CLARK 2450.00 20 RESEARCH 7902 FORD 3000.00 20 RESEARCH 7566 JONES 2975.00 30 SALES 7698 BLAKE 2850.00 5๋ฑ๊ธ ( 3001 ~ 9999 ) - 1๋ช 0 null 7839 KING 5000.00 - END - |
ex02.jsp
1. <a href="">๋ฑ๊ธ๋ณ ์ฌ์ ์ ๋ณด ์กฐํ</a>
2. ์๋ธ๋ฆฟ ์ ์ธ ( SalgradeEmp.java )
LinkedHashMap<SalgradeDTO, ArrayList<DeptEmpSalgradeDTO>> map
request ์ ์ฅ( map )
ํฌ์๋ฉ
3. ex02_ok.jsp
ํ๋ฉด ์ถ๋ ฅ
jquery UI : Accordion ์ฌ์ฉํด์ ์ถ๋ ฅ.
<%
String contextPath = request.getContextPath();
%>
<a href="<%= contextPath %>/days04/ex02.htm">๋ฑ๊ธ๋ณ ์ฌ์ ์ ๋ณด ์กฐํ</a>
package days04;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.Set;
import com.util.DBConn;
import domain.DeptEmpSalgradeDTO;
import domain.SalgradeDTO;
@WebServlet("/days04/ex02.htm")
public class SalgradeEmp extends HttpServlet {
private static final long serialVersionUID = 1L;
public SalgradeEmp() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("> SalgradeEmp.doGet() ํธ์ถ๋จ.");
// JDBC days03.Ex03_03.java main(){}
Connection conn = null;
PreparedStatement pstmt = null , e_pstmt = null;
ResultSet rs = null, e_rs= null;
SalgradeDTO dto = null; // key
ArrayList<DeptEmpSalgradeDTO> list = null; // value
DeptEmpSalgradeDTO desDto = null;
LinkedHashMap<SalgradeDTO, ArrayList<DeptEmpSalgradeDTO>> map = null;
String sql = "SELECT grade , losal , hisal "
+ ", count(*) cnt "
+ " FROM salgrade s JOIN emp e ON e.sal BETWEEN s.losal AND s.hisal "
+ " GROUP BY grade , losal , hisal "
+ " ORDER BY grade ASC";
String sql2 = "SELECT d.deptno, dname, empno, ename, sal , grade "
+ " FROM dept d RIGHT JOIN emp e ON d.deptno = e.deptno "
+ " JOIN salgrade s ON e.sal BETWEEN s.losal AND s.hisal "
+ " WHERE grade = ? ";
//
conn = DBConn.getConnection();
try {
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if( rs.next() ) {
map = new LinkedHashMap<SalgradeDTO, ArrayList<DeptEmpSalgradeDTO>>();
do {
int grade = rs.getInt(1);
int losal = rs.getInt(2);
int hisal = rs.getInt(3);
int cnt = rs.getInt(4);
dto = new SalgradeDTO(grade, losal, hisal, cnt); // key
list = null;
e_pstmt = conn.prepareStatement(sql2);
e_pstmt.setInt(1, grade);
e_rs = e_pstmt.executeQuery();
if( e_rs.next() ) {
list = new ArrayList<DeptEmpSalgradeDTO>();
do {
int deptno = e_rs.getInt(1);
String dname = e_rs.getString(2);
int empno = e_rs.getInt(3);
String ename = e_rs.getString(4);
double sal = e_rs.getDouble(5);
desDto = new DeptEmpSalgradeDTO(deptno, dname, empno, ename, null, sal, grade);
list.add(desDto); // value
}while( e_rs.next() );
map.put(dto, list); // entry ์ถ๊ฐ
} // if
e_pstmt.close(); //
e_rs.close(); //
}while( rs.next() );
} // if
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
pstmt.close();
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} // try
} // try
DBConn.close();
//
request.setAttribute("map", map);
// ํฌ์๋ฉ
//String path = "ex02_ok.jsp";
String path = "ex02_ok_jstl.jsp";
RequestDispatcher dispatcher = request.getRequestDispatcher(path);
dispatcher.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
* ์๋ธ๋ฆฟ ์ฌ์ฉํ ๋ ํธ์ถ ์ ๋๋์ง ํ์ธ!
servlet์์ ์ฃผ์ String path ์ค์ ํ๊ณ dispatchํ๊ณ (ํฌ์๋ฉ์ผ๋)
jsp ํ์ผ์์ ํธ์ถ ํ์ธ (๊ทธ๋ฅ 404 ์๋์ค๊ณ html ํ์ผ ์ ๋์ค๋์ง)
acodian (jquery)
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="java.util.Set"%>
<%@page import="domain.DeptEmpSalgradeDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="domain.SalgradeDTO"%>
<%@page import="java.util.LinkedHashMap"%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2022. 12. 7. ์คํ 12:35:26</title>
<link rel="shortcut icon" type="image/x-icon" href="../images/SiSt.ico">
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://www.jquery.com/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
<script>
$( function() {
$( "#accordion" ).accordion();
} );
</script>
</head>
<body>
<%
// request.setAttribute("map", map);
LinkedHashMap<SalgradeDTO, ArrayList<DeptEmpSalgradeDTO>> map =
(LinkedHashMap<SalgradeDTO, ArrayList<DeptEmpSalgradeDTO>>)request.getAttribute("map");
%>
<h3>ex02_ok.jsp - jquery UI : Accordion</h3>
<div id="accordion">
<%
Set<Entry<SalgradeDTO, ArrayList<DeptEmpSalgradeDTO>>> set = map.entrySet();
Iterator<Entry<SalgradeDTO, ArrayList<DeptEmpSalgradeDTO>>> ir = set.iterator();
while (ir.hasNext()) {
Entry<SalgradeDTO,ArrayList<DeptEmpSalgradeDTO>> entry = ir.next();
SalgradeDTO key = entry.getKey();
%>
<h3><%= key %></h3>
<%
ArrayList<DeptEmpSalgradeDTO> list = entry.getValue();
Iterator<DeptEmpSalgradeDTO> ir2 = list.iterator();
%>
<div>
<%
while (ir2.hasNext()) {
DeptEmpSalgradeDTO dto = ir2.next();
%>
<p> <%= dto.toString() %> </p>
<%
} // while
%>
</div>
<%
} // while
%>
</div>
* ์คํฌ๋ฆฝํธ๋ฆฟ ์ฌ์ฉํด์ ๋ฐ๋ณตํด์ ์์ฑ..
acodian(jstl)
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="java.util.Set"%>
<%@page import="domain.DeptEmpSalgradeDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="domain.SalgradeDTO"%>
<%@page import="java.util.LinkedHashMap"%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2022. 12. 7. ์คํ 12:35:26</title>
<link rel="shortcut icon" type="image/x-icon" href="../images/SiSt.ico">
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://www.jquery.com/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
<script>
$( function() {
$( "#accordion" ).accordion();
$( "#tabs" ).tabs(); // 13 ์ค
} );
</script>
</head>
<body>
<h3>ex02_ok_jstl.jsp - jquery UI : Accordion</h3>
<div id="accordion">
<c:forEach items="${ map }" var="entry">
<h3>${ entry.key }</h3> <!-- entry.key = SalgradeDTO -->
<div>
<c:choose>
<c:when test="${ empty entry.value }">
<li>์ฌ์ ์กด์ฌ X</li>
</c:when>
<c:otherwise>
<c:forEach items="${ entry.value }" var="dto"><!-- entry.value = ArrayList<DeptEmpSalgradeDTO> -->
<li>${ dto.empno } / ${ dto.ename } </li>
</c:forEach>
</c:otherwise>
</c:choose>
</div>
</c:forEach>
</div>
<hr>
<div id="tabs">
<ul>
<!--
<li><a href="#tabs-1">Nunc tincidunt</a></li>
<li><a href="#tabs-2">Proin dolor</a></li>
<li><a href="#tabs-3">Aenean lacinia</a></li>
-->
<c:forEach items="${ map }" var="entry" varStatus="status">
<li><a href="#tabs-${ status.count }">${ entry.key }</a></li>
</c:forEach>
</ul>
<c:forEach items="${ map }" var="entry" varStatus="status">
<div id="tabs-${ status.count }">
<c:choose>
<c:when test="${ empty entry.value }">
<li>์ฌ์ ์กด์ฌ X</li>
</c:when>
<c:otherwise>
<c:forEach items="${ entry.value }" var="dto"><!-- entry.value = ArrayList<DeptEmpSalgradeDTO> -->
<li>${ dto.empno } / ${ dto.ename } </li>
</c:forEach>
</c:otherwise>
</c:choose>
</div>
</c:forEach>
<!--
<div id="tabs-1">
<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
</div>
<div id="tabs-2">
<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
</div>
<div id="tabs-3">
<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
</div>
-->
</div>
* accodian + tabs
* varStatus -> ๋ฒํธ๊ฐ ์ฐํ (tab1, tab2)
p 100 Chapter 04 ํ์ ์ดํด ์์
1. JSP์ ์์ฒญ ์ฒ๋ฆฌ ๊ณผ์
2. ์ถ๋ ฅ ๋ฒํผ
3. ์น ์ดํ๋ฆฌ์ผ์ด์ ํด๋ ๊ตฌ์กฐ
4. war ํ์ผ
๊ณต์ฅ
์ํํ aaaa
๋ ธ์ฉ์ค aaa -> 1ํค : [a][a][a][a] -> ํ๋งค์
๊ถ์ฌํ aaaaa ๋ฐฐ์ก(์ ๋ฌ)
์น์๋ฒ <- ์์ฒญ ํด๋ผ์ด์ธํธ
[][][][์๋ฐ]
์๋ต๋ฒํผ ์๋ ๋ฐฐ๋ฌ
:
๋ฒํผ ๋น์ฐ๊ณ
p99 ๊ทธ๋ฆผ 4.1 JSP ์ฒ๋ฆฌ ๊ณผ์
* WAS -> ----- JSP -> JAVA CLASS FILE -> SERVLET -----> WAS
ใด JASPER
request
response
out
<%
// ์คํฌ๋ฆฝํธ ๋ฆฟ
String name = "hong";
%>
<%!
// ์ ์ธ๋ถ
int age = 20;
public String getName(){
return "ํ๊ธธ๋";
}
%>
<%
// ์คํฌ๋ฆฝํธ๋ฆฟ
for( int i = 1; i<=10 ; i++){
%>
<li><%= i %>+</li>
<%
}
%>
* ์คํฌ๋ฆฝํธ๋ฆฟ -> ์๋ฒ์์ ๋จผ์ ์คํ, ํ๋๋ก ๋ฌถ์
* ์ ์ธ๋ถ -> ์ ์ญ๋ณ์๋ก ์ ์ธ
[์ถ๋ ฅ ๋ฒํผ์ ์๋ต ]
1. ๋ฐ๋ก ์ถ๋ ฅ ์ ์กํ์ง ์๊ณ ์ถ๋ ฅ ๋ฒํผ ์ฌ์ฉํ๋ ์ด์ ( ์ฅ์ )
1) ๋ฐ์ดํฐ ์ ์ก ์ฑ๋ฅ ํฅ์
2) jsp ์คํ ๋์ค์ ๋ฒํผ๋ฅผ ๋น์ฐ๊ณ ์๋ก์ด ๋ด์ฉ ์ ์ก ๊ฐ๋ฅ
3) ๋ฒํผ๊ฐ ๋ค ์ฐจ๊ธฐ ์ ์ ํค๋ ๋ณ๊ฒฝ ๊ฐ๋ฅ.
2. ์ถ๋ ฅ ๋ฒํผ๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ์ ํ๋ค๋ฉด
buffer="none"
1) ์ ํ : ๋ด์ฉ ์ทจ์ X, jsp:forward ์ก์ ํ๊ทธ X
3. p 103 ๊ทธ๋ฆผ 4.4
p 106 ์น ์ดํ๋ฆฌ์ผ์ด์ ํด๋ ๊ตฌ์ฑ๊ณผ URL ๋งคํ
ใด WEB-INF ํด๋ : ์น ์ดํ๋ฆฌ์ผ์ด์ ์ ์ค์ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ web.xml ํ์ผ ์์นํ๋ค.
์ค์ ํ์ผ
์ธ๋ถ์์ ์ ๊ทผํ ์ ์์ด์.
http://localhost/jspPro/WEB-INF/web.xml 404 X
์ธ๋ถ์์ ์ง์ ์ ์ผ๋ก ์ ๊ทผํ ์ ์๋ ํ์ผ๋ค์ WEB-INF ํด๋ ์์ ํด๋๋ฅผ ๋ง๋ค์ด์ ์ ์ฅ.
ใด classes ํด๋ : .class ( ๋ชจ๋ ํด๋์ค ํ์ผ์ ์ ์ฅํ๋ ํด๋.)
ใด lib ํด๋ : jar ํ์ผ ์ ์ฅํ๋ ํด๋.
p 107 ์น ์ดํ๋ฆฌ์ผ์ด์ ํด๋์ URL์์ ๊ด๊ณ
URL : http://localhost[:80]/jspPro/
์น์๋ฒ : ~~~~\\jspPro/webapp
" ๋ฐฐํฌ " :C:\apache-tomcat-8.5.83\webapps\\jspPro
p 110 ์น ์ดํ๋ฆฌ์ผ์ด์ ๋ฐฐํฌ
1) ๋์ ํด๋์ ํ์ผ์ ์ง์ ๋ณต์ฌ .
2) war ํ์ผ๋ก ๋ฌถ์ด์ ๋ฐฐํฌ
[ JSP์์ ์ ๊ณตํ๋ 9๊ฐ์ง์ ๊ธฐ๋ณธ๊ฐ์ฒด์ ์์ญ( scope )]
1. request : HttpServletRequest ํด๋์ค๋ช ์์ฒญ ๊ฐ์ฒด
ServletReqeust X
2. response : HttpServletResponse ์๋ต ๊ฐ์ฒด
3. out : JspWriter ์ถ๋ ฅ ์คํธ๋ฆผ ๊ฐ์ฒด
4. pageContext :PageContext JSP ํ์ด์ง ๋ํ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ ๊ฐ์ฒด.
9. page : Object JSPํ์ด์ง๋ฅผ ๊ตฌํํ ์๋ฐ ํด๋์ค ์ธ์คํด์ค
5. session : HttpSession http ์ธ์ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ค.
6. application : [ServerContext] ์น ์ดํ๋ฆฌ์ผ์ด์ ์ ๋ํ ์ ๋ณด ์ ์ฅ.
์น ์ฌ์ดํธ
์๋ฒ ์ ๋ณด ์ ์ฅ
7. config : Servlet[Config] ์ค์ ์ ๋ณด ์ ์ฅ
8. exception : Throwable ์์ธ ์ฒ๋ฆฌ ๊ฐ์ฒด
out ๊ฐ์ฒด (๋ฒํผ, flush ์์์)
out ๊ฐ์ฒด</h3>
<%
out.flush();
out.print("hello<br>");
out.newLine();// "\r\n"
out.println("world!!<br>"); // "\r\n" -> <br>
%>
๋ฒํผ ํฌ๊ธฐ : <%= out.getBufferSize() %>kb<br>
<%
out.clearBuffer();
%>
๋จ์ ๋ฒํผ ํฌ๊ธฐ : <%= out.getRemaining() %><br>
autoFlush : <%= out.isAutoFlush() %> <br>
p 119 page[Context] ๊ธฐ๋ณธ ๊ฐ์ฒด : J SP ํ์ด์ง ๋ํ [์ ๋ณด๋ฅผ ์ ์ฅ]ํ๋ ๊ฐ์ฒด.
page ๊ธฐ๋ณธ ๊ฐ์ฒด : JSPํ์ด์ง -> ์๋ฐ ํด๋์ค์ ์ธ์คํด์ค
1) JSP ์ ๊ณต๋๋ ๊ธฐ๋ณธ ๊ฐ์ฒด ์ป์ด์ฌ ์ ๋ ์๋ค.
- ์ปค์คํ ํ๊ทธ๋ฅผ ๊ตฌํํ ๋ ์ฌ์ฉ
2) ์์ฑ ์ฒ๋ฆฌ ( ์ด ์ฅ์์ ์ค๋ช ํ๋ค. )
3) ํ์ด์ง์ ํ๋ฆ ์ ์ด ( 7์ฅ )
4) ์๋ฌ ๋ฐ์ดํฐ ๊ตฌํ๊ธฐ( 6์ฅ )
// request ๊ธฐ๋ณธ ๊ฐ์ฒด
// request.getParameter("name");
//request ๊ธฐ๋ณธ ๊ฐ์ฒด
// pageContext.getRequest().getParameter("name");
// pageContext.getOut()
// application == pageContext.getServletContext();
// config == pageContext.getServletConfig();
[JSP ๊ธฐ๋ณธ๊ฐ์ฒด : request, response, out, pageContext ] application ๊ธฐ๋ณธ ๊ฐ์ฒด
1. ์น ์ดํ๋ฆฌ์ผ์ด์ ๊ด ๊ด๋ จ๋ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ ๊ธฐ๋ณธ ๊ฐ์ฒด ( ์น ์ฌ์ดํธ )
2. ๋ชจ๋ JSPํ์ด์ง์์ ๊ณต์ ํ๋ ๊ธฐ๋ณธ ๊ฐ์ฒด ( ์ํ๊ด๋ฆฌ )
3. " ํ ์ ๋ณด ์ฐ๊ธฐ/์ฝ๊ธฐ
p 121 ์น ์ดํ๋ฆฌ์ผ์ด์ ์ ์ด๊ธฐํ ํ๋ผ๋ฏธํฐ ์ฝ์ด์ค๊ธฐ.
1. WEB-INF/web.xml ํ์ผ์ <context-param> ํ๊ทธ ์ฌ์ฉํด์ ์ด๊ธฐํ ๊ฐ ์ถ๊ฐ
2. application
1) getInitParameter( name )
2) getInitParameterNames()
<%
Enumeration<String> en= application.getInitParameterNames();
while( en.hasMoreElements() ){
String pname = en.nextElement();
String pvalue = application.getInitParameter( pname );
%>
<li><%= pname %> : <%= pvalue %></li>
<%
} // while
%>
<h3>p 124 ์๋ฒ ์ ๋ณด ์ฝ์ด์ค๊ธฐ</h3>
<pre>
application ๊ธฐ๋ณธ ๊ฐ์ฒด๋ ํ์ฌ ์ฌ์ฉ ์ค์ธ ์น์ปจํ ์ด๋(ํฐ์บฃ)์
๋ํ ์ ๋ณด๋ฅผ ์ฝ์ด์ค๋ ๋ฉ์๋๋ฅผ ์ ๊ณต
getSeverInfo()
getMajorVersion()
getMinorVersion()
</pre>
์๋ฒ ์ ๋ณด : <%= application.getServerInfo() %><br>
์๋ฒ ๋ฉ์ด์ ธ ๋ฒ์ ผ : <%= application.getMajorVersion() %><br>
์๋ฒ ๋ง์ด๋ ๋ฒ์ ผ : <%= application.getMinorVersion() %><br>
์ต๊ทผ๋๊ธ