1. index2.jsp 에서
- 부서이름
- 이름
이 나오도록 하시오
package dto;
public class EnameAndDnameDto {
private String ename;
private String dname;
public EnameAndDnameDto() {
}
public EnameAndDnameDto(String ename, String dname) {
super();
this.ename = ename;
this.dname = dname;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}
}
package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import dto.EnameAndDnameDto;
public class EnameAndDnameDao {
private DataSource dataSource = null;
public EnameAndDnameDao() {
try {
Context context = new InitialContext();
dataSource = (DataSource)context.lookup("java:comp/env/jdbc/oracle");
} catch(Exception e) {
e.printStackTrace();
};
}
public List<EnameAndDnameDto> edList() {
List<EnameAndDnameDto> list = new ArrayList<EnameAndDnameDto>();
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String query = "select emp.ename, dept.dname from emp, dept where emp.deptno = dept.deptno";
System.out.println(query);
try {
connection = dataSource.getConnection();
pstmt = connection.prepareStatement(query);
rs = pstmt.executeQuery();
while(rs.next()) {
list.add(new EnameAndDnameDto(
rs.getString("ename"),
rs.getString("dname")
));
};
System.out.println("SUCESS");
} catch(Exception e) {
System.out.println("FAIL");
e.printStackTrace();
};
return list;
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*" import="java.io.*"
import="dao.EnameAndDnameDao" import="dto.EnameAndDnameDto"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>index2.jsp</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<link href="css/prettyPhoto.css" rel="stylesheet">
<link href="css/price-range.css" rel="stylesheet">
<link href="css/animate.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<link href="css/responsive.css" rel="stylesheet">
<link rel="shortcut icon" href="images/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144"
href="images/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114"
href="images/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72"
href="images/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed"
href="images/ico/apple-touch-icon-57-precomposed.png">
</head>
<body>
<header></header>
<section>
<div class="container">
<div class="row">
<div class="col-sm-9 padding-right">
<div class="features_items">
<h2 class="title text-center">EMP LIST</h2>
<%
EnameAndDnameDao edDao = new EnameAndDnameDao();
List<EnameAndDnameDto> dtos = edDao.edList();
pageContext.setAttribute("dtos", dtos);
List<String> results = new ArrayList<String>();
File[] files = new File("C:/Users/601-26/Documents/workspace-sts-3.9.11.RELEASE/jsp_jk_el/WebContent/images/home").listFiles();
for (File file : files) {
if (file.isFile()) {
results.add(file.getName());
};
};
Collections.shuffle(results);
Iterator<String> it = results.iterator();
%>
<c:forEach var="dto" items="${dtos}">
<div class="col-sm-4">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<img src=<%="images/home/" + it.next()%> alt="" />
<h2>${dto.getDname()}</h2>
<p>${dto.getEname()}</p>
</div>
<div class="product-overlay">
<div class="overlay-content">
<h2>${dto.getDname()}</h2>
<p>${dto.getEname()}</p>
</div>
</div>
</div>
</div>
</div>
</c:forEach>
</div>
</div>
</div>
</div>
</section>
<footer></footer>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.scrollUp.min.js"></script>
<script src="js/price-range.js"></script>
<script src="js/jquery.prettyPhoto.js"></script>
<script src="js/main.js"></script>
</body>
</html>