<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<%@ include file="dbcon.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<%!
int id,count;
%>
<%
String sql="select max(id)+1,count(id) from db02151";
psmt = con.prepareStatement(sql);
rs = psmt.executeQuery();
if(rs.next()) {
id = rs.getInt(1);
count = rs.getInt(2);
}
%>
<h3 align="center">근태관리입력</h3>
<form action="officeinput.do">
<table border="1" align="center">
<caption>(데이터갯수:<%=count%>개)</caption>
<tr>
<th>아이디(자동생성)</th>
<td><input type="text" name="id" value="<%=id%>" readonly></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name"></td>
</tr>
<tr>
<th>날짜</th>
<td><input type="date" name="day" id="day"></td>
</tr>
<tr>
<th>출근시간</th>
<td><input type="time" name="timein" id="timein"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="리셋">
</td>
</tr>
</table>
</form>
<script type="text/javascript">
var date = new Date();
date.setHours(date.getHours() + 9);
document.getElementById('day').value = date.toISOString().substring(0, 10);
document.getElementById('timein').value = date.toISOString().substring(11, 16);
</script>
</section>
<jsp:include page="footer.jsp"></jsp:include>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<h3 align="center">퇴근시간 기록</h3>
<form action="officeinput2.do">
<table border="1" align="center">
<tr>
<th>아이디</th>
<td><input type="text" name="id"></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name"></td>
</tr>
<tr>
<th>퇴근시간</th>
<td><input type="time" name="timeout" id="timeout"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="리셋">
</td>
</tr>
</table>
</form>
<script type="text/javascript">
var date = new Date()
date.setHours(date.getHours() + 9)
document.getElementById('timeout').value = date.toISOString().substring(11, 16);
</script>
</section>
<jsp:include page="footer.jsp"></jsp:include>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ include file="top.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<h3 align="center">근태관리출력</h3>
<table border="1" align="center" width="800px">
<tr>
<th>이름</th><th>이름</th><th>날짜</th><th>출근시간</th>
<th>출근비고</th><th>퇴근시간</th><th>퇴근비고</th>
</tr>
<c:forEach items="${listb}" var="dto">
<tr>
<td>${dto.id}</td><td>${dto.name}</td><td>${dto.day}</td>
<td>${dto.timein}</td><td>${dto.inbigo}</td>
<td>${dto.timeout}</td><td>${dto.outbigo}</td>
</tr>
</c:forEach>
</table>
</section>
<jsp:include page="footer.jsp"/>
</html>
package com.ezen;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Officeinput implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
try {
OfficeDAO odao = new OfficeDAO();
odao.insert(request);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
package com.ezen;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Officeinput2 implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
try {
OfficeDAO odao = new OfficeDAO();
odao.insert2(request);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
package com.ezen;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class OfficeOut implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
try {
OfficeDAO odao = new OfficeDAO();
ArrayList<OfficeDTO> list= odao.out();
request.setAttribute("listb", list);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
package com.ezen;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
public class OfficeDAO {
int id;
String name,day;
String timein,timeout;
String inbigo,outbigo;
Connection con;
PreparedStatement psmt;
ResultSet rs,rs1,rs2;
String driver="oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:xe";
ArrayList<OfficeDTO> list = new ArrayList<OfficeDTO>();
public OfficeDAO() throws ClassNotFoundException {
Class.forName(driver);
try {
con=DriverManager.getConnection(url, "ezen", "12345");
} catch (SQLException e) {
e.printStackTrace();
}
}
public void insert(HttpServletRequest request) {
try {
request.setCharacterEncoding("utf-8");
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String day = request.getParameter("day");
String timein = request.getParameter("timein");
String sql = "insert into db02151 values (?,?,?,?,0)";
try {
psmt = con.prepareStatement(sql);
psmt.setInt(1, id);
psmt.setString(2, name);
psmt.setString(3, day);
psmt.setString(4, timein);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public void insert2(HttpServletRequest request) {
try {
request.setCharacterEncoding("utf-8");
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String timeout = request.getParameter("timeout");
String sql = "update db02151 set timeout=? where id=? and name=?";
try {
psmt = con.prepareStatement(sql);
psmt.setString(1, timeout);
psmt.setInt(2, id);
psmt.setString(3, name);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public ArrayList<OfficeDTO> out() {
// String sql = "select * from db02151";
String sql = "select id,name,day,timein,timeout, "
+ "case when timein > '09:00' then '지각' else '정상' end as inbigo, "
+ "case when timeout < '18:00' then '조퇴' else '정상' end as outbigo "
+ "from db02151";
try {
psmt = con.prepareStatement(sql);
rs = psmt.executeQuery();
while(rs.next()) {
int id = rs.getInt(1);
String name = rs.getString(2);
String day = rs.getString(3).substring(0, 10);
String timein = rs.getString(4);
String timeout = rs.getString(5);
String inbigo = rs.getString(6);
String outbigo = rs.getString(7);
//
// String inbigo = null;
// if(Integer.parseInt(timein.substring(0, 2))>=9 &
// Integer.parseInt(timein.substring(3, 5))>=1) {
// inbigo = "지각";
// }
// else {
// inbigo = "정상";
// }
// String outbigo = null;
// if(Integer.parseInt(timeout.substring(0, 2))<=17 &
// Integer.parseInt(timeout.substring(3, 5))<=59) {
// outbigo = "조퇴";
// }
// else {
// outbigo = "정상";
// }
OfficeDTO odto = new OfficeDTO();
odto.setId(id);
odto.setName(name);
odto.setDay(day);
odto.setTimein(timein);
odto.setTimeout(timeout);
odto.setInbigo(inbigo);
odto.setOutbigo(outbigo);
list.add(odto);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
}
입출력까지
로그인기능
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" a href="css/sample1.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" a href="css/show.css">
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
setInterval("timer2()",1000); //timer()를 1초간격 호출해서 실핼ㅇ
function timer2(){
var nowtime2 =document.getElementById("now2");
nowtime2.innerHTML=(new Date()).toLocaleTimeString();//시간
}
</script>
<header>
JSP 미니 프로젝트ver1.0
</header>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.jsp">HOME</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">
<img alt="" src="image/1.png" width="40px" height="30px" >
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">성적관리<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="input.jsp">성적입력</a></li>
<li><a href="out.do">성적출력</a></li>
<li><a href="modify.jsp">성적수정</a></li>
<li><a href="delete.jsp">성적삭제</a></li>
<li><a href="search.jsp">성적검색</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">인사관리 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="sawoninput.jsp">사원정보입력</a></li>
<li><a href="sawonout.do">사원정보출력</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">근태관리 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="officeinput.jsp">출근하기</a></li>
<li><a href="officeinput2.jsp">퇴근하기</a></li>
<li><a href="officeout.do">근태관리출력</a></li>
<li><a href="officemodify.jsp">근태관리수정</a></li>
<li><a href="officedelete.jsp">근태관리삭제</a></li>
<li><a href="officesearch.jsp">근태관리검색</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">로그인관리 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="member.jsp">회원가입</a></li>
<li><a href="login.jsp">로그인</a></li>
<li><a href="logout.do">로그아웃</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<c:choose>
<c:when test="${login == true && member != null}">
<li>
<a href="logout.do"><span class="glyphicon glyphicon-log-in"></span> 환영합니다!! ${member.id}님</a>
<a href="logout.do"><span class="glyphicon glyphicon-log-in"></span> 로그아웃</a>
</li>
</c:when>
<c:otherwise>
<li><a href="member.jsp"><span class="glyphicon glyphicon-user"></span>회원가입</a></li>
<li><a href="login.jsp"><span class="glyphicon glyphicon-log-in"></span> 로그인</a></li>
</c:otherwise>
</c:choose>
</ul>
</div>
</div>
</nav>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<h3 align="center">회원가입 현황</h3>
<form action="member.do" method="get">
<table border="1" align="center">
<tr>
<th>아이디</th>
<td><input type="text" name="id"> </td>
</tr>
<tr>
<th>패스워드</th>
<td><input type="text" name="pw"> </td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="가입">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</section>
<jsp:include page="footer.jsp"></jsp:include>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<h3 align="center">로그인 하기 </h3>
<form action="login.do" method="get">
<table border="1" align="center">
<tr>
<th>아이디</th>
<td><input type="text" name="id"> </td>
</tr>
<tr>
<th>패스워드</th>
<td><input type="text" name="pw"> </td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="로그인">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</section>
<jsp:include page="footer.jsp"></jsp:include>
</html>
package com.ezen;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Member implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
try {
MemberDAO mdao = new MemberDAO();
mdao.insert(request);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
package com.ezen;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class Login implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
try {
MemberDAO mdao = new MemberDAO();
MemberDTO member = mdao.login(request);
if(member !=null) {
//회원이다
HttpSession hs = request.getSession();
hs.setAttribute("member", member); //id,pw존재
hs.setAttribute("login", true);
hs.setMaxInactiveInterval(60);
request.setAttribute("vpage", "index.jsp");//로그인후 ViewPage
}
else {
//비회원이다
request.setAttribute("vpage", "login.jsp");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
package com.ezen;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Logout implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
try {
MemberDAO mdao = new MemberDAO();
mdao.logout(request);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
package com.ezen;
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;
@WebServlet("*.do")
public class FrontController extends HttpServlet {
private static final long serialVersionUID = 1L;
public FrontController() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uri = request.getRequestURI();
String path = request.getContextPath();
String fname = uri.substring(path.length());
service service = null;
String vpage = null;
if(fname.equals("/input.do")) {
//Input 이라는 클래스로 service 객체를 만든 이유
service = new Input();
service.aaa(request, response);
vpage="reset.jsp";
}
else if(fname.equals("/out.do")) {
service = new Output();
service.aaa(request, response);
vpage="out.jsp";
}
else if(fname.equals("/modify.do")) {
service = new modify();
service.aaa(request, response);
vpage="index.jsp";
}
else if(fname.equals("/delete.do")) {
service=new Delete();
service.aaa(request, response);
vpage="index.jsp";
}
else if(fname.equals("/search.do")) {
service=new Search();
service.aaa(request, response);
vpage="out2.jsp";
}
else if(fname.equals("/sawoninput.do")) {
service=new Sawoninput();
service.aaa(request, response);
vpage="index.jsp";
}
else if(fname.equals("/sawonout.do")) {
service=new Sawonout();
service.aaa(request, response);
vpage="out3.jsp";
}
else if(fname.equals("/officeinput.do")) {
service=new Officeinput();
service.aaa(request, response);
vpage="index.jsp";
}
else if(fname.equals("/officeinput2.do")) {
service=new Officeinput2();
service.aaa(request, response);
vpage="index.jsp";
}
else if(fname.equals("/officeout.do")) {
service = new OfficeOut();
service.aaa(request, response);
vpage="officeout.jsp";
}
else if(fname.equals("/officemodify.do")) {
service = new OfficeModify();
service.aaa(request, response);
vpage="index.jsp";
}
else if(fname.equals("/officedelete.do")) {
service = new OfficeDelete();
service.aaa(request, response);
vpage="index.jsp";
}
else if(fname.equals("/officesearch.do")) {
service = new OfficeSearch();
service.aaa(request, response);
vpage="officeout2.jsp";
}
else if(fname.equals("/member.do")) {
service = new Member();
service.aaa(request, response);
vpage="index.jsp";
}
else if(fname.equals("/login.do")) {
service = new Login();
service.aaa(request, response);
vpage=(String)request.getAttribute("vpage");
}
else if(fname.equals("/logout.do")) {
service = new Logout();
service.aaa(request, response);
vpage="index.jsp";
}
RequestDispatcher rd = request.getRequestDispatcher(vpage);
rd.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
package com.ezen;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class MemberDAO {
Connection con;
PreparedStatement psmt;
ResultSet rs;
String driver="oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:xe";
public MemberDAO() throws ClassNotFoundException {
Class.forName(driver);
try {
con=DriverManager.getConnection(url, "ezen", "12345");
} catch (SQLException e) {
e.printStackTrace();
}
}
public void insert(HttpServletRequest request) {
try {
request.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String pw = request.getParameter("pw");
String sql = "insert into db02152 values (?,?)";
try {
psmt = con.prepareStatement(sql);
psmt.setString(1, id);
psmt.setString(2, pw);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public MemberDTO login(HttpServletRequest request) {
String id = request.getParameter("id");
String pw = request.getParameter("pw");
String sql = "select * from db02152 where id=? and pw=?";
MemberDTO member = null;
try {
psmt = con.prepareStatement(sql);
psmt.setString(1, id);
psmt.setString(2, pw);
rs = psmt.executeQuery();
if(rs.next()) {
member = new MemberDTO();
member.setId(rs.getString(1));
member.setPw(rs.getString(2));
}
else {
member = new MemberDTO();
member=null;
}
} catch (SQLException e) {
e.printStackTrace();
}
return member;
}
public void logout(HttpServletRequest request) {
HttpSession hs = request.getSession();
hs.removeAttribute("member");
hs.removeAttribute("login");
hs.setAttribute("login", false);
}
}
로그인기능
게시판 로그인 여부에 따른 잠금기능
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="top.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<%
HttpSession hs = request.getSession();
if((boolean)hs.getAttribute("login"))
{
%>
<h3 align="center">학생성적입력</h3>
<form action="input.do">
<table border="1" align="center">
<tr>
<th>반</th>
<td><input type="text" name="ban"></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name"></td>
</tr>
<tr>
<th>국어</th>
<td><input type="text" name="kor"></td>
</tr>
<tr>
<th>영어</th>
<td><input type="text" name="eng"></td>
</tr>
<tr>
<th>수학</th>
<td><input type="text" name="mat"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="리셋">
</td>
</tr>
</table>
</form>
</section>
<jsp:include page="footer.jsp"></jsp:include>
<%
}
else
{
%>
<script type="text/javascript">
window.onload=function() {
alert("로그인 후에 사용해주세요!")
}
</script>
<%
}
%>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ include file="top.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<section>
<c:choose>
<c:when test="${login == true && member != null}">
<h3 align="center">학생성적출력</h3>
<table border="1" align="center" width="800px">
<tr>
<th>반</th><th>이름</th><th>국어</th>
<th>영어</th><th>수학</th><th>총점</th>
<th>반순위</th><th>전체순위</th>
</tr>
<c:forEach items="${list}" var="my">
<tr>
<td>${my.ban}</td><td>${my.name}</td><td>${my.kor}</td>
<td>${my.eng}</td><td>${my.mat}</td><td>${my.tot}</td>
<td>${my.brank}</td><td>${my.rank}</td>
</tr>
</c:forEach>
</table>
</c:when>
<c:otherwise>
<script type="text/javascript">
window.onload=function() {
alert("로그인 후에 사용해주세요!")
}
</script>
</c:otherwise>
</c:choose>
</section>
<jsp:include page="footer.jsp"/>
</html>
'JSP' 카테고리의 다른 글
230217_서블릿 (0) | 2023.02.17 |
---|---|
230216_서블릿 (0) | 2023.02.16 |
230214_서블릿 (0) | 2023.02.14 |
230213_서블릿 (0) | 2023.02.13 |
230210_서블릿 (0) | 2023.02.10 |
댓글