<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<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/sample.css">
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
setInterval("timer2()",1000); //timer()를 1초간격 호출해서 실행
function timer2() {
var nowtime = document.getElementById("now2");
nowtime.innerHTML = (new Date()).toLocaleTimeString(); //시간
}
</script>
<header>
JSP 미니 프로그젝트ver1.0
</header>
<nav class="navbar navbar">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.jsp">참좋은</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><img src="image/1.png" width="50px" 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="#">Page 1-1</a></li>
<li><a href="#">Page 1-2</a></li>
<li><a href="#">Page 1-3</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="#">Page 1-1</a></li>
<li><a href="#">Page 1-2</a></li>
<li><a href="#">Page 1-3</a></li>
</ul>
</li>
<ul class="nav navbar-nav navbar-right">
<li><span style="color:red;font-size: 20px;margin-right:150px"id=now2></span></li>
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</ul>
</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>학생성적입력현황</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>
</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>
<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>
</section>
<jsp:include page="footer.jsp"/>
</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>
<form action="modify1.jsp">
<table border="1" align="center">
<tr>
<th>수정할 이름</th>
<td><input type="text" name="name"></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"/>
</html>
<%@ 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>
<%!
String mname;
String name;
int ban,kor,eng,mat;
%>
<%
request.setCharacterEncoding("utf-8");
mname = request.getParameter("name");
String sql = "select * from db02131 where name=?";
psmt = con.prepareStatement(sql);
psmt.setString(1, mname);
rs = psmt.executeQuery();
if(rs.next()) {
ban = rs.getInt(1);
name = rs.getString(2);
kor = rs.getInt(3);
eng = rs.getInt(4);
mat = rs.getInt(5);
}
%>
<form action="modify.do">
<table border="1" align="center">
<tr>
<th>반</th>
<td><input type="text" name="ban" value="<%=ban%>"></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name" value="<%=name%>" readonly></td>
</tr>
<tr>
<th>국어</th>
<td><input type="text" name="kor" value="<%=kor%>"></td>
</tr>
<tr>
<th>영어</th>
<td><input type="text" name="eng" value="<%=eng%>"></td>
</tr>
<tr>
<th>수학</th>
<td><input type="text" name="mat" value="<%=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"/>
</html>
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="index.jsp";
}
else if(fname.equals("/out.do")) {
//Input 이라는 클래스로 service 객체를 만든 이유
service = new Output();
service.aaa(request, response);
vpage="out.jsp";
}
else if(fname.equals("/modify.do")) {
//Input 이라는 클래스로 service 객체를 만든 이유
service = new modify();
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Input implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
try {
ScoreDAO dao = new ScoreDAO();
dao.insert(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 Output implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
try {
ScoreDAO dao = new ScoreDAO();
ArrayList<ScoreDTO> list = dao.out();
request.setAttribute("list", list);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
package com.ezen;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class modify implements service{
@Override
public void aaa(HttpServletRequest request, HttpServletResponse response) {
try {
ScoreDAO dao = new ScoreDAO();
dao.modify(request);
} 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 ScoreDAO {
Connection con;
PreparedStatement psmt;
ResultSet rs;
String driver="oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:xe";
ArrayList<ScoreDTO> list = new ArrayList<ScoreDTO>();
public ScoreDAO() 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 ban = Integer.parseInt(request.getParameter("ban"));
String name = request.getParameter("name");
int kor = Integer.parseInt(request.getParameter("kor"));
int eng = Integer.parseInt(request.getParameter("eng"));
int mat = Integer.parseInt(request.getParameter("mat"));
String sql ="insert into db02131 values (?,?,?,?,?)";
try {
psmt = con.prepareStatement(sql);
psmt.setInt(1, ban);
psmt.setString(2, name);
psmt.setInt(3, kor);
psmt.setInt(4, eng);
psmt.setInt(5, mat);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public ArrayList<ScoreDTO> out() {
String sql="select ban,name,kor,eng,mat,(kor+eng+mat), "
+ " rank() over(partition by ban order by (kor+eng+mat) desc), "
+ " rank() over(order by (kor+eng+mat) desc) "
+ " from db02131";
try {
psmt = con.prepareStatement(sql);
rs = psmt.executeQuery();
while(rs.next()) {
int ban = rs.getInt(1);
String name = rs.getString(2);
int kor = rs.getInt(3);
int eng = rs.getInt(4);
int mat = rs.getInt(5);
int tot = rs.getInt(6);
int brank = rs.getInt(7);
int rank = rs.getInt(8);
ScoreDTO dto = new ScoreDTO();
dto.setBan(ban);
dto.setName(name);
dto.setKor(kor);
dto.setEng(eng);
dto.setMat(mat);
dto.setTot(tot);
dto.setBrank(brank);
dto.setRank(rank);
list.add(dto);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public void modify(HttpServletRequest request) {
try {
request.setCharacterEncoding("utf-8");
int ban = Integer.parseInt(request.getParameter("ban"));
String name = request.getParameter("name");
int kor = Integer.parseInt(request.getParameter("kor"));
int eng = Integer.parseInt(request.getParameter("eng"));
int mat = Integer.parseInt(request.getParameter("mat"));
String sql ="update db02131 set ban=?,kor=?,eng=?,mat=? where name=?";
try {
psmt = con.prepareStatement(sql);
psmt.setInt(1, ban);
psmt.setInt(2, kor);
psmt.setInt(3, eng);
psmt.setInt(4, mat);
psmt.setString(5, name);
psmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public void search() {
}
}
'JSP' 카테고리의 다른 글
230215_서블릿 (0) | 2023.02.15 |
---|---|
230214_서블릿 (0) | 2023.02.14 |
230210_서블릿 (0) | 2023.02.10 |
230209_서블릿 (0) | 2023.02.09 |
230208_서블릿 (0) | 2023.02.08 |
댓글