728x90
반응형
댓글 기능을 만드는 미션을 받았다.
수정하고 삭제하고 저장하는 기능 만들기.
댓글 화면
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="ssi.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> [guestReply.jsp] </title>
<style type="text/css">
*{ font-size: 16pt; font-weight: bold; }
a{ font-size: 16pt; text-decoration:none; color:blue ; font-family: Comic Sans MS; }
a:hover{ font-size: 18pt; text-decoration:underline; color:green ; font-family: Comic Sans MS; }
#rsave{
font-size: 26pt; font-weight: bold;
background:yellow; height:130px;
}
</style>
<script type="text/javascript">
var gr_num; //전역변수
function re_edit(num, writer, content){
}//end
function re_save(){//3페이지 26번라인
}//end
</script>
</head>
<body>
<%
//guestReply.jsp단독실행하면 에러발생
String Rdata = request.getParameter("Gidx") ;
System.out.println("guestReply.jsp댓글문서 넘어온 Gidx="+ Rdata);
%>
<form name="reply_form" action="guestReply_insert.jsp">
<table width=900 border=1 cellspacing=0>
<tr>
<td> <img src="images/z1.gif"> Gidx: <img src="images/z1.gif"> </td>
<td> <input type="text" name="sabun" value="<%= Rdata %>" size=30 readonly="readonly"> </td>
<td rowspan="3" align="center">
<input type="submit" id="rsave" name="bt_save" onClick="re_save();" value="댓글저장">
</td>
</tr>
<tr>
<td> <img src="images/z1.gif"> 저자: <img src="images/z1.gif"> </td>
<td> <input type="text" name="writer" size=30> </td>
</tr>
<tr>
<td> <img src="images/z1.gif"> 내용: <img src="images/z1.gif"> </td>
<td> <textarea rows="3" cols="27" name="content"></textarea> </td>
</tr>
</table>
</form>
<p>
<table width=900 border=0 cellspacing=0>
<caption> <<<< 댓글내용출력 >>>> </caption>
<tr bgcolor="pink" >
<td>번호</td>
<td>저자</td>
<td>댓글내용</td>
<td>수정/삭제</td>
</tr>
<%
String a="select rownum rrn,r.num, r.writer, r.content, g.sabun from guest g " ;
String b=" inner join guestreply r " ;
String y=" on g.sabun = r.sabun " ;
String c=" and r.sabun = " + Rdata ;
msg = a+b+y+c;
ST=CN.createStatement();
RS=ST.executeQuery(msg); //msg대신 sb.toString()변환
while(RS.next()==true) {
Rrn = RS.getInt("rrn"); //1 2 3 4 5 6 순서번호
Rnum = RS.getInt("num");
Rwriter = RS.getString("writer");
Rcontent = RS.getString("content");
Rsabun = RS.getInt("sabun");
%>
<tr onmouseover="style.backgroundColor='yellow'" onmouseout="style.backgroundColor='' ">
<td width=70> <%= Rrn %> </td>
<td width=150> <%= Rwriter %> </td>
<td width=200> <%= Rcontent %> </td>
<td>
<a href="guestReply_delete.jsp?idx=<%=Rnum%>" >[댓글삭제]</a>
<a href="guestReply_edit.jsp?idx=<%=Rnum%>">[댓글수정]</a>
</td>
</tr>
<% } %>
</table>
<p style="margin-bottom:150px">
<p><br>
</body>
</html>
댓글 저장하기
댓글 저자와 내용을 입력하고
저장을 누르면
전송이 된다
값을 받아서
메세지에 담아 실행을 시킨다.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="ssi.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> [guestReply_insert.jsp] </title>
<style type="text/css">
*{ font-size: 16pt; font-weight: bold; }
a{ font-size: 16pt; text-decoration:none; color:blue ; font-family: Comic Sans MS; }
a:hover{ font-size: 18pt; text-decoration:underline; color:green ; font-family: Comic Sans MS; }
#rsave{
font-size: 26pt; font-weight: bold;
background:lightgreen; height:130px;
}
</style>
</head>
<body>
<%
//guestReply_insert단독실행하면 에러발생
try{
String s = request.getParameter("sabun");
String w = request.getParameter("writer");
String c = request.getParameter("content");
msg = "insert into guestreply values(guestreply_seq.nextval, '"+ c +"', '"+ w +"', '"+ s +"')";
ST = CN.createStatement();
ST.executeUpdate(msg);
%>
<script type="text/javascript">
alert("정보 저장 되었습니다");
location.href="login.jsp";
</script>
<%
}catch( Exception e ){
}
%>
</body>
</html>
댓글 수정하기
댓글 수정을 누르면
a 태그가 값을 들고 전송이 된다.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="ssi.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> [guestReply_edit.jsp] </title>
<style type="text/css">
*{ font-size: 16pt; font-weight: bold; }
a{ font-size: 16pt; text-decoration:none; color:blue ; font-family: Comic Sans MS; }
a:hover{ font-size: 18pt; text-decoration:underline; color:green ; font-family: Comic Sans MS; }
#rsave{
font-size: 26pt; font-weight: bold;
background:lightgreen; height:130px;
}
</style>
</head>
<body>
<%
//guestReply_edit단독실행하면 에러발생
int Gdata = Integer.parseInt(request.getParameter("idx"));
%>
<form name="reple_edit" action="guestReply_editSave.jsp">
<table>
<tr>
<td>
SABUN :<%=Gdata %> size=30 ><br>
</td>
</tr>
<tr>
<td>
WRITER : <input type="text" name="writer" size=30 ><br>
</td>
</tr>
<tr>
<td>
CONTENT : <input type="text" name="content" size=30 ><br>
</td>
<td rowspan="3" align="center">
<input type="submit" id="editsave" value="수정 저장">
</td>
</tr>
</table>
</form>
</body>
</html>
값을 받아와서
사번에 대한
수정 할 데이터를 입력 받는다
저장 버튼을 누르면
여기로 전송을 해주자
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="ssi.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> [guestReply_editSave.jsp] </title>
<style type="text/css">
*{ font-size: 16pt; font-weight: bold; }
a{ font-size: 16pt; text-decoration:none; color:blue ; font-family: Comic Sans MS; }
a:hover{ font-size: 18pt; text-decoration:underline; color:green ; font-family: Comic Sans MS; }
#rsave{
font-size: 26pt; font-weight: bold;
background:lightgreen; height:130px;
}
</style>
</head>
<body>
<%
try{
int n = Integer.parseInt(request.getParameter("sabun"));
String w = request.getParameter("writer");
String c = request.getParameter("content");
msg = "UPDATE GUESTREPLY SET CONTENT = '" + c + "', WRITER = '" + w + "' WHERE NUM = " + n;
ST = CN.createStatement();
ST.executeUpdate(msg);
}catch( Exception e ){
System.out.print("수정 에러 : " + e );
}
%>
<script type="text/javascript">
alert("수정 되었습니다");
location.href="login.jsp";
</script>
</body>
</html>
값을 받아와서
쿼리문을 던지고
실행을 시킨다
댓글 삭제하기
댓글 삭제를 누르면 a 태그로 값을 가지고 간다
사번을 받아서 그 사번에 대한 쿼리문 작성
쿼리문 작성하고 실행
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="ssi.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> [guestReply_delete.jsp] </title>
<style type="text/css">
*{ font-size: 16pt; font-weight: bold; }
a{ font-size: 16pt; text-decoration:none; color:blue ; font-family: Comic Sans MS; }
a:hover{ font-size: 18pt; text-decoration:underline; color:green ; font-family: Comic Sans MS; }
#rsave{
font-size: 26pt; font-weight: bold;
background:lightgreen; height:130px;
}
</style>
</head>
<body>
<%
//guestReply_delete단독실행하면 에러발생
try{
int Gdata = Integer.parseInt(request.getParameter("idx"));
msg ="delete from guestreply where num = " + Gdata ;
ST = CN.createStatement();
ST.executeUpdate(msg);
%>
<script type="text/javascript">
alert("삭제 되었습니다");
location.href="login.jsp";
</script>
<%
}catch( Exception e ){
System.out.print("실행 오류 : " + e);
}
%>
</body>
</html>
이제 값 넘김의 흐름을 잘 익혀 가는 중 아이 행복해 ♩
ssi.jsp
<%@page import="net.tis.sql.GuestDTO"%>
<%@page import="net.tis.sql.GuestSQL"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.CallableStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.util.Date" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> </title>
<style type="text/css">
*{ font-size: 26pt; }
a{ font-size: 26pt; color:green; text-decoration:none; }
a:hover{ font-size:30pt; color:blue; text-decoration:underline; }
</style>
<script type="text/javascript">
</script>
</head>
<body>
<%!
//ssi.jsp문서
Connection CN ;
Statement ST ;
PreparedStatement PST;
CallableStatement CST;
ResultSet RS ;
int Gsabun,Gpay, Ghit ;
int GGtotal; //전체레코드갯수
int Gtotal ; //조회레코드갯수
int GStotal=0 ; //Gtotal대신 GStotal사용도 좋습니다조회갯수
String Gname,Gtitle, Gemail ;
java.util.Date Gwdate;
String msg;
String submsg;
String Gdata;
int Rcnt ; //댓글갯수 카운트
//댓글관련 전역변수
String Rdata ; //guest_reply.jsp문서에서 사용
int Rrn, Rnum, Rsabun ;
String Rwriter, Rcontent;
%>
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@127.0.0.1:1521:XE" ;
CN=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","system","1234");
//System.out.println("ssi.jsp문서 오라클연결성공success");
}catch(Exception ex){ System.out.println(ex); }
//자바클래스 객체화
GuestSQL sql = new GuestSQL();
GuestDTO dto = new GuestDTO();
%>
</body>
</html>
728x90
반응형
'개발중 > Web' 카테고리의 다른 글
다음 주소창 이용하기 (0) | 2020.08.05 |
---|---|
Web 이미지를 a 태그로 (0) | 2020.08.04 |
Web06 전체 데이터 출력 ( MY ) (0) | 2020.07.31 |
Web06 .jsp 문서에서 .java 문서 호출 (0) | 2020.07.30 |
Web06 FORWARD / INCLUDE (0) | 2020.07.30 |