-
Notifications
You must be signed in to change notification settings - Fork 0
14.休日一覧出力 Action
domanthan edited this page Jun 22, 2020
·
1 revision
/**
*
*/
package smart.calendar.action;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import com.opensymphony.xwork2.ActionSupport;
import smart.calendar.model.Holiday;
/**
* @author gridscale
*
*/
public class HolidayAction extends ActionSupport {
List<Holiday> holidays = new ArrayList<Holiday>();
public String show() {
try {
// コネクション取得
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:/comp/env/jdbc/calendar");
Connection con = ds.getConnection();
// SQL文送信
PreparedStatement st = con.prepareStatement("select * from holiday");
// 実行&結果受け取り
ResultSet rs = st.executeQuery();
// データの表示
while (rs.next()) {
Holiday holiday = new Holiday();
holiday.setYear(rs.getInt("year"));
holiday.setMonth(rs.getInt("month"));
holiday.setDay(rs.getInt("day"));
holiday.setName(rs.getString("name"));
holidays.add(holiday);
}
} catch (Exception e) {
}
return SUCCESS;
}
/**
* @return holidays
*/
public List<Holiday> getHolidays() {
return holidays;
}
/**
* @param holidays セットする holidays
*/
public void setHolidays(List<Holiday> holidays) {
this.holidays = holidays;
}
}
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta charset='UTF-8' />
<style>
table {
width: 80%
}
th, td {
border-bottom: 1px solid #ddd;
}
th, td {
padding: 15px;
text-align: left;
}
th {
height: 50px;
background-color: blue;
color: white;
}
</style>
</head>
<body>
<h1 style='color: blue'>2020年年間休日一覧</h1>
<br />
<table>
<tr>
<th>年</th>
<th>月</th>
<th>日</th>
<th>休日名称</th>
</tr>
<s:iterator value="holidays">
<tr>
<td><s:property value="year" /></td>
<td><s:property value="month" /></td>
<td><s:property value="day" /></td>
<td><s:property value="name" />
</tr>
</s:iterator>
</table>
</body>
</html>