start.jsp
============
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.seoulit.DBUtil3"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<style type="text/css">
td {
border: 2px solid green;
}
</style>
<script>
function a(){
document.forms[0].action="join.jsp";
}
</script>
</head>
<body>
<form action="list.jsp">
<input type="submit" value="회원리스트">
<input type="submit" onclick="a()" value="회원가입">
</form>
</body>
</html>
list.jsp
===========
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.seoulit.DBUtil3" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<style type="text/css">
td { border:2px solid green; }
</style>
</head>
<body>
<form action="update.jsp">
<%
Connection connection=null;
Statement stmt=null;
ResultSet rs=null;
try{
connection=DBUtil3.getConnection();
stmt=connection.createStatement();
rs=stmt.executeQuery("select id from member");
out.println("<table>");
while(rs.next()){
out.println("<tr>");
out.println("<td><input type=radio name=id value="+rs.getString("id")+"></td>");
out.println("<td>"+rs.getString("id")+"</td>");
out.println("</tr>");
}
out.println("</table>");
}catch(Exception e){
out.println(e);
}finally{
if(rs!=null){ rs.close(); rs=null; }
if(stmt!=null){ stmt.close(); stmt=null; }
if(connection!=null){ connection.close(); connection=null; }
}
%>
<input type="submit" value="수정">
<input type="submit" value="삭제" onclick='this.form.action="delete.jsp"'>
</form>
<a href="start.jsp">처음으로</a>
</body>
</html>
update.jsp
==========
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.seoulit.DBUtil3" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<style type="text/css">
td {
border: 2px solid green;
}
</style>
</head>
<body>
<form action="update3.jsp">
<%
Connection connection=null;
Statement stmt=null;
ResultSet rs=null;
String id=null;
try{
connection=DBUtil3.getConnection();
String sql="select * from member where id=?";
PreparedStatement pstmt=connection.prepareStatement(sql);
id=request.getParameter("id");
pstmt.setString(1, id);
rs=pstmt.executeQuery();
out.write("회원수정<br>");
if(rs.next()){
out.write("<input type=text disabled name=id value="+rs.getString("id")+"><br>");
out.write("<input type=text name=pw value="+rs.getString("pw")+"><br>");
out.write("<input type=text name=addr value="+rs.getString("addr")+"><br>");
out.write("<input type=text name=tel value="+rs.getString("tel")+"><br>");
}
}catch(Exception e){
out.println(e);
}finally{
if(rs!=null){ rs.close(); rs=null; }
if(stmt!=null){ stmt.close(); stmt=null; }
if(connection!=null){ connection.close(); connection=null; }
}
%>
<input type="hidden" name="id" value="<%=id%>">
<input type="submit" value="수정">
</form>
</body>
</html>
update3
===============
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.seoulit.DBUtil3"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
</head>
<body>
<%
String id = request.getParameter("id");
String pw = request.getParameter("pw");
String addr = request.getParameter("addr");
String tel = request.getParameter("tel");
Connection connection = DBUtil3.getConnection();
PreparedStatement pstmt = connection.prepareStatement("update member set pw=?, addr=?, tel=? where id=?");
pstmt.setString(1, pw);
pstmt.setString(2, addr);
pstmt.setString(3, tel);
pstmt.setString(4, id);
int result = pstmt.executeUpdate();
out.println("<script>");
out.println("location.href='All_list.jsp'");
out.println("</script>");
%>
</body>
</html>
join.jsp
===============
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.seoulit.DBUtil3" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<style type="text/css">
td { border:2px solid green; }
</style>
</head>
<body>
<form action="insert.jsp">
<input type="text" name="id"><br>
<input type="text" name="pw"><br>
<input type="text" name="addr"><br>
<input type="text" name="tel"><br>
<input type="submit" value="가입">
</form>
<a href="start.jsp">되돌아가기</a>
</body>
</html>
insert.jsp
===============
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.seoulit.DBUtil3"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<style type="text/css">
td {
border: 2px solid green;
}
</style>
</head>
<body>
<form action="start.jsp">
<%
String id=request.getParameter("id");
String pw=request.getParameter("pw");
String addr=request.getParameter("addr");
String tel=request.getParameter("tel");
Connection connection=DBUtil3.getConnection();
PreparedStatement pstmt=connection.prepareStatement("insert into member values(?,?,?,?)");
pstmt.setString(1, id);
pstmt.setString(2, pw);
pstmt.setString(3, addr);
pstmt.setString(4, tel);
pstmt.executeUpdate();
%>
<input type="submit" value="가입성공">
</form>
</body>
</html>
delete.jsp
==============
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form action="deleteAction.jsp">
<input type="text" name="id"><br>
<input type="text" name="pw"><br>
<input type="submit" value="삭제">
</form>
<%
if(session.getAttribute("msg")!=null){
out.println(session.getAttribute("msg"));
}
%>
</body>
</html>
deleteAction.jsp
==================
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="a.b.DBUtil" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
String id=request.getParameter("id"); //delect.jsp에서 id를 받는다.
String pw=request.getParameter("pw"); //delete.jsp에서 pw를 받는다.
String sql=""; //prepareStatement에서 사용할 sql을 미리 선언해 놓는다.
Connection connection=null; //자원해제를 위해서 전역변수 선언해 놓는다
PreparedStatement pstmt=null; //자원해제를 위해서 전역변수 선언해 놓는다.
ResultSet rs=null; //자원해제 전역변수 선언
try{
connection=DBUtil.getConnection(); // DBUtil과 연결~
sql="select pw from member where id=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, id); // 1은 테이블의 첫번째 칼럼, id는 칼럼 값~
rs=pstmt.executeQuery(); //sql 문을 실행한다~
if(rs.next()){
String pw2=rs.getString("pw"); //db에서 pw를 받아온다.
if(pw.equals(pw2)){ //입력받은 pw와 db에서 불러온 pw가 같은지 비교
sql="delete from member where id=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1,id);
pstmt.executeQuery();
}
else{
session.setAttribute("msg", "비번잘못됨"); //request 보다 session이 더 오랫동안 유지가능.
// 객체명.setAttribute("속성노드명", 새로운속성값);
response.sendRedirect("delete.jsp"); //delete.jsp로 화면이동
}
}
else{
session.setAttribute("msg", "아이디 틀림");
response.sendRedirect("delete.jsp");
}
}catch(Exception e){ // 예외처리
out.println(e); //Exception 이 어떤게 발생하는지 보여줌
}finally{
if(rs!=null){rs.close(); rs=null;} //자원해제
if(pstmt!=null){pstmt.close(); pstmt=null;}//자원해제
if(connection!=null){connection.close(); connection=null;}//자원해제
}
%>
<script>
alert("삭제성공");
location.href="list.jsp"; //삭제성공과 동시에 list.jsp로 화면이동
</script>
</body>
</html>
All_list.jsp
======================
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.seoulit.DBUtil3" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<style type="text/css">
td{border:2px solid;}
</style>
</head>
<body>
<form action="list.jsp">
<%
Connection connection=DBUtil3.getConnection();
Statement stmt=connection.createStatement();
ResultSet rs=stmt.executeQuery("select * from member");
out.write("<table>");
while(rs.next()){
out.write("<tr><td>"+rs.getString(1)+"</td>");
out.write("<td>"+rs.getString(2)+"</td>");
out.write("<td>"+rs.getString(3)+"</td>");
out.write("<td>"+rs.getString(4)+"</td></tr>");
}
out.write("</table>");
%>
<input type="submit" value="되돌아가기">
</form>
</body>
</html>
'jsp' 카테고리의 다른 글
EL변경 (0) | 2013.11.25 |
---|---|
jquery 꼭 풀어봐야 할 예제들 (0) | 2013.11.08 |
DB 연동 (0) | 2013.10.30 |
jsp와 db연동 (0) | 2013.10.28 |
선언문,request객체의메서드들,화면이동하기 (0) | 2013.10.23 |