JSP 3일차 Session 테스트 (로그인)

CookieLogin.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>Cookie Login</title>
</head>
<body>

<form action="SessionLogin.jsp">
<table>
<tr>
<td>id</td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td>pw</td>
<td><input type="text" name="pw"></td>
</tr>
<tr>
<td><input type="submit" value="Send"></td>
</tr>
</table>
</form>

</body>
</html>

SessionLogin.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>Session Login</title>
</head>
<body>

<%
String id_ = "jiniusman";
String pw_ = "blogspot";

String id = request.getParameter("id");
String pw = request.getParameter("pw");

if(id.equals(id_) && pw.equals(pw_))
{
session.setAttribute("identification", id_);
session.setAttribute("password", pw_);
response.sendRedirect("SessionLogin1.jsp");

session.setMaxInactiveInterval(10);
}
else
{
%>
<script>
alert("fail");
history.go(-1);
</script>
<%
//response.sendRedirect("CookieLogin.jsp");
}


%>

</body>
</html>

SessionLogin1.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>Session Login</title>
</head>
<body>

<%
String id = session.getAttribute("identification").toString();
String pw = session.getAttribute("password").toString();
%>

id : <%=id%><br>
pw : <%=pw%><br>
<a href="Login.jsp">log-in</a>

</body>
</html>

Login.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>Login</title>
</head>
<body>

<form action="SessionLogin.jsp">
<table>
<tr>
<td>id</td>
<td>
<input type="text" name="id" value="<%=session.getAttribute("identification")%>">
</td>
</tr>
<tr>
<td>pw</td>
<td>
<input type="text" name="pw" value="<%=session.getAttribute("password")%>">
</td>
</tr>
<tr>
<td><input type="submit" value="Send"></td>
</tr>
</table>
</form>

</body>
</html>


result)




JSP 3일차 Cookie 테스트2 (로그인)

CookieLogin.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>CookieLogin</title>
</head>
<body>

<form action="CookieLoginProc.jsp">
<table>
<tr>
<td>id</td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td>pw</td>
<td><input type="text" name="pw"></td>
</tr>
<tr>
<td><input type="submit" value="Send"></td>
</tr>
</table>
</form>

</body>
</html>

CookieLogin1.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></title>
</head>
<body>

<%
Cookie[] cookies = request.getCookies();


if(cookies!=null && cookies.length>0)
{
for(int i=0; i<cookies.length; i++)
{
if(cookies[i].getValue().equals("jiniusman"))
{
%>
id <%= cookies[i].getValue() %> log-in.<br>
<%
}

// else
%>
<!-- login failed. -->
<%
}
}
%>

</body>

</html>

CookieProc.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>CookieLoginProc</title>
</head>
<body>

<%
String id_ = "jiniusman";
String pw_ = "blogspot";

String id = request.getParameter("id");
String pw = request.getParameter("pw");

if(id.equals(id_) && pw.equals(pw_))
response.addCookie(new Cookie("cookie_id", id));


response.sendRedirect("CookieLogin1.jsp");
%>

</body>
</html>


result)


JSP 3일차 Cookie 테스트

<%@ 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>Cookie Test</title>
</head>
<body>

<%
Cookie cookie = new Cookie("jwnamkung","SamsungSDS");
response.addCookie(cookie);
%>
name : <%= cookie.getName() %><br>
value : <%= cookie.getValue() %><br>

<br>

<%
Cookie[] cookies = request.getCookies();

if(cookies!=null && cookies.length>0)
{
for(int i=0; i<cookies.length; i++)
{
%>
name : <%= cookies[i].getName() %><br>
value : <%= cookies[i].getValue() %><br>
<%
}
}
%>

</body>
</html>

JSP 3일차 회원관리 GUI

MemberList.jsp

<%@page import="java.util.Vector"%>
<%@page import="member.MemberDAO"%>
<%@page import="member.MemberBean"%>
<%@ 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>Member List</title>
</head>
<body>

<center>
<h2>Member List</h2>
<table cellpadding="5" border="1" bordercolor="white" bgcolor="#FFBB00" width="400" >
<tr>
<td>No.</td>
<td>ID</td>
<td>Name</td>
<td>Gender</td>
<td>Phone</td>
<td>E-mail</td>
</tr>

<%
MemberDAO mdao = new MemberDAO();
MemberBean mbean = new MemberBean();

Vector<MemberBean> vector = mdao.getAllMember();

for(int i=0; i<vector.size(); i++)
{
mbean = vector.get(i);
%>

<tr bgcolor="white">
<td><%= i+1 %></td>
<td>
<a href="MemberInfo.jsp?id=<%=mbean.getId()%>"><%=mbean.getId()%></a>
</td>
<td><%= mbean.getName() %></td>
<td><%= mbean.getGender() %></td>
<td><%= mbean.getPhone() %></td>
<td><%= mbean.getEmail() %></td>
</tr>

<%
}
%>
</table>

<br>
<a href = "MemberForm.jsp"> Member Join </a>
</center>

</body>
</html>


result)















MemberForm.jsp

<!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>Member Join</title>
</head>
<body>

<center>
<h2>Member Join</h2>
<form action="MemberJDBC.jsp" method="post">
<table cellpadding="5" border="1" bordercolor="white" bgcolor="#FFBB00">
<tr>
<th>ID</th>
<th><input type="text" name="id" size="16"></th>
<th>P/W</th>
<th><input type="password" name="password" size="16"></th>
</tr>
<tr>
<th>Name</th>
<th><input type="text" name="name" size="16"></th>
<th>E-mail</th>
<th><input type="text" name="email" size="16"></th>
</tr>
<tr>
<th>Phone</th>
<th><input type="text" name="phone" size="16"></th>
<th>Address</th>
<th><input type="text" name="address" size="16"></th>
<tr>
<th>Gender</th>
<th><input type="radio" name="gender" value="male"> male
<input type="radio" name="gender" value="female"> female</th>
<th>Hobby</th>
<th><input type="checkbox" name="hobby1" value="baseball">baseball
<input type="checkbox" name="hobby2" value="soccer">soccer</th>
</tr>
<tr>
<th>etc</th>
<th colspan="3"><textarea name="etc" rows="3" cols="50"></textarea></th>
<tr>
<th colspan="4">
<center>
<input type="submit" value="Send">
<input type="reset" value="Cancel">
</center>
</th>
</tr>
</table>
</form>
</center>

</body>
</html>

MemberJDBC.jsp

<%@page import="member.MemberDAO"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@ 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>jdbc</title>
</head>
<body>

<jsp:useBean id="mbean" class="member.MemberBean"/>
<jsp:setProperty property="*" name="mbean"/>

<%
MemberDAO mdao = new MemberDAO();

mdao.con();
mdao.insertMember(mbean);

response.sendRedirect("MemberList.jsp");
%>

</body>
</html>


result)

















MemberInfo.jsp

<%@page import="member.MemberBean"%>
<%@page import="java.util.Vector"%>
<%@page import="member.MemberDAO"%>
<%@ 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>Member Information</title>
</head>
<body>

<center>
<%
MemberDAO mdao = new MemberDAO();
MemberBean mbean = new MemberBean();
mbean = mdao.getSelectMember(request.getParameter("id"));
%>

<h2>Member Information</h2>
<table border="1" bordercolor="white" bgcolor="#FFBB00" cellpadding="5">
<form action="MemberUpdate.jsp" method = "post">
<tr>
<td>ID</td>
<td>
<input type="text" name=id value=<%=mbean.getId()%>>
</td>
</tr>
<tr>
<td>Phone</td>
<td>
<input type="text" name=phone value=<%=mbean.getPhone()%>>
</td>
</tr>
<tr>
<td>E-mail</td>
<td>
<input type="text" name=email value=<%=mbean.getEmail()%>>
</td>
</tr>

<tr>
<td colspan="4" align="center">
<input type="submit" value="Update">
</td>
</tr>
</form>

<tr>
<td colspan="4" align="center">
<form action = "MemberDelete.jsp?id=<%=mbean.getId()%>" method = "post">
     <input type="submit" value="Delete">
     </form>
    </td>
    </tr>
</table>
</center>

</body>
</html>

MemberUpdate.jsp

<%@page import="member.MemberDAO"%>
<%@ 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>Member Update</title>
</head>
<body>

<%
MemberDAO mdao = new MemberDAO();

mdao.updateMember(request.getParameter("id"),
request.getParameter("phone"),
request.getParameter("email"));
response.sendRedirect("MemberList.jsp");
%>

</body>
</html>


result)
















MemberDelete.jsp

<%@page import="member.MemberDAO"%>
<%@ 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>Member Delete</title>
</head>
<body>

<%
MemberDAO mdao = new MemberDAO();
mdao.deleteMember(request.getParameter("id"));
response.sendRedirect("MemberList.jsp");
%>

</body>
</html>

MemberBean.java

package member;

public class MemberBean
{
private String id;
private String password;
private String name;
private String email;
private String gender;
private String hobby1;
private String hobby2;
private String phone;
private String address;
private String etc;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getHobby1() {
return hobby1;
}
public void setHobby1(String hobby1) {
this.hobby1 = hobby1;
}
public String getHobby2() {
return hobby2;
}
public void setHobby2(String hobby2) {
this.hobby2 = hobby2;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEtc() {
return etc;
}
public void setEtc(String etc) {
this.etc = etc;
}
}

MemberDAO.java

package member;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;

public class MemberDAO
{
String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
String id = "system";
String password = "nam";
Connection con;
PreparedStatement ps;
ResultSet rs;
public void con()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, id, password);
}
catch(Exception e)
{
}
}
public void insertMember(MemberBean mbean)
{
this.con();
String sql = "INSERT into member values(?,?,?,?,?,?,?,?,?,?)";
try
{
ps = con.prepareStatement(sql);
ps.setString(1, mbean.getId());
ps.setString(2, mbean.getPassword());
ps.setString(3, mbean.getName());
ps.setString(4, mbean.getEmail());
ps.setString(5, mbean.getGender());
ps.setString(6, mbean.getHobby1());
ps.setString(7, mbean.getHobby2());
ps.setString(8, mbean.getPhone());
ps.setString(9, mbean.getAddress());
ps.setString(10, mbean.getEtc());
ps.executeUpdate();
ps.close();
con.close();
}
catch(Exception e) 
{
}
}
public Vector<MemberBean> getAllMember()
{
Vector<MemberBean> vector = new Vector<>();
MemberBean mbean;
try
{
this.con();
String sql = "SELECT * from member";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next())
{
mbean = new MemberBean();
mbean.setId(rs.getString(1));
mbean.setPassword(rs.getString(2));
mbean.setName(rs.getString(3));
mbean.setEmail(rs.getString(4));
mbean.setGender(rs.getString(5));
mbean.setHobby1(rs.getString(6));
mbean.setHobby2(rs.getString(7));
mbean.setPhone(rs.getString(8));
mbean.setAddress(rs.getString(9));
mbean.setEtc(rs.getString(10));
vector.add(mbean);
}
con.close();
ps.close();
rs.close();
}
catch(Exception e) 
{
}
return vector;
}
public void updateMember(String id, String phone, String email)
{
this.con();

String sql = "UPDATE member set phone=?, email=? where id=?";
try
{
ps = con.prepareStatement(sql);
ps.setString(1, phone);
ps.setString(2, email);
ps.setString(3, id);

ps.executeUpdate();

ps.close();
con.close();
}
catch (Exception e)
{
}

public void deleteMember(String id)
{
this.con();

String sql="DELETE from member where id=?";
try
{
ps = con.prepareStatement(sql);
ps.setString(1, id);

ps.executeUpdate();

ps.close();
con.close();
}
catch (Exception e)
{
}
public MemberBean getSelectMember(String id)
{
this.con();

MemberBean member = new MemberBean();
String sql = "SELECT * from member where id=?";

try
{
ps = con.prepareStatement(sql);
ps.setString(1, id);

rs = ps.executeQuery();

rs.next();
member.setId(rs.getString(1));
member.setEmail(rs.getString(4));
member.setPhone(rs.getString(8));

con.close();
ps.close();
rs.close();
}
catch(Exception e)
{
}
return member;
}
}


result)


JSP 2일차 JDBC DAO

form.jsp

<!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>Introduce GUI</title>
</head>
<body>

<form action="jdbc.jsp" method="post">
<table cellpadding="5">
<tr>
<th>ID</th>
<th><input type="text" name="id" size="16"></th>
</tr>
<tr>
<th>P/W</th>
<th><input type="password" name="password" size="16"></th>
<th>Name</th>
<th><input type="text" name="name" size="16"></th>
</tr>
<tr>
<th>Gender</th>
<th><input type="radio" name="gender" value="male"> male
<input type="radio" name="gender" value="female"> female</th>
<th>Hobby</th>
<th><input type="checkbox" name="hobby" value="baseball">baseball
<input type="checkbox" name="hobby" value="soccer">soccer</th>
</tr>
<tr>
<th>Phone</th>
<th><input type="text" name="phone" size="16"></th>
<tr>
<th>etc</th>
<th colspan="3"><textarea name="etc" rows="3" cols="50"></textarea></th>
<tr>
<th colspan="4">
<center>
<input type="submit" value="Send">
<input type="submit" value="Cancel">
</center>
</th>
</tr>
</table>
</form>

</body>
</html>

jdbc.jsp

<%@page import="member.MemberDAO"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@ 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>jdbc</title>
</head>
<body>

<jsp:useBean id="mbean" class="member.MemberBean"/>
<jsp:setProperty property="*" name="mbean"/>

<%
MemberDAO mdao = new MemberDAO();

mdao.con();
mdao.insertMember(mbean);

response.sendRedirect("Result.jsp");
%>

</body>
</html>

Result.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>Result</title>
</head>
<body>

<h2> 입력 완료 </h2>

<a href = "form.jsp"> 뒤로 </a>

</body>
</html>

MemberBean.java

package member;

public class MemberBean
{
private String id;
private String password;
private String name;
private String gender;
private String hobby;
private String phone;
private String etc;

public String getId()
{
return id;
}

public void setId(String id)
{
this.id = id;
}

public String getPassword()
{
return password;
}

public void setPassword(String password)
{
this.password = password;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}


public String getGender()
{
return gender;
}

public void setGender(String gender)
{
this.gender = gender;
}

public String getHobby()
{
return hobby;
}

public void setHobby(String hobby)
{
this.hobby = hobby;
}

public String getPhone()
{
return phone;
}

public void setPhone(String phone)
{
this.phone = phone;
}

public String getEtc()
{
return etc;
}

public void setEtc(String etc)
{
this.etc = etc;
}
}

MemberDAO.java

package member;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class MemberDAO
{
String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
String id = "system";
String password = "nam";
Connection con;
PreparedStatement ps;
ResultSet rs;

public void con()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, id, password);
}
catch(Exception e)
{
}
}

public void insertMember(MemberBean mbean)
{
this.con();

String sql = "INSERT into membertest values(?,?,?,?,?,?,?)";

try
{
ps = con.prepareStatement(sql);

ps.setString(1, mbean.getId());
ps.setString(2, mbean.getPassword());
ps.setString(3, mbean.getName());
ps.setString(4, mbean.getGender());
ps.setString(5, mbean.getHobby());
ps.setString(6, mbean.getPhone());
ps.setString(7, mbean.getEtc());

ps.executeUpdate();

ps.close();
con.close();
}
catch(Exception e)
{
}
}
}


result)




JSP 2일차 JDBC

form.jsp

<!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>Introduce GUI</title>
</head>
<body>

<form action="jdbc.jsp" method="post">
<table cellpadding="5">
<tr>
<th>ID</th>
<th><input type="text" name="id" size="16"></th>
</tr>
<tr>
<th>P/W</th>
<th><input type="password" name="password" size="16"></th>
<th>Name</th>
<th><input type="text" name="name" size="16"></th>
</tr>
<tr>
<th>Gender</th>
<th><input type="radio" name="gender" value="male"> male
<input type="radio" name="gender" value="female"> female</th>
<th>Hobby</th>
<th><input type="checkbox" name="hobby" value="baseball">baseball
<input type="checkbox" name="hobby" value="soccer">soccer</th>
</tr>
<tr>
<th>Phone</th>
<th><input type="text" name="phone" size="16"></th>
<tr>
<th>etc</th>
<th colspan="3"><textarea name="etc" rows="3" cols="50"></textarea></th>
<tr>
<th colspan="4">
<center>
<input type="submit" value="Send">
<input type="submit" value="Cancel">
</center>
</th>
</tr>
</table>
</form>

</body>
</html>

jdbc.jsp

<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@ 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>jdbc</title>
</head>
<body>

<jsp:useBean id="mbean" class="member.MemberBean"/>
<jsp:setProperty property="*" name="mbean"/>

<%
String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
String id = "system";
String password = "nam";
Connection con;
PreparedStatement ps;
ResultSet rs;

String sql = "INSERT into membertest values(?,?,?,?,?,?,?)";

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, id, password);

ps = con.prepareStatement(sql);

ps.setString(1, mbean.getId());
ps.setString(2, mbean.getPassword());
ps.setString(3, mbean.getName());
ps.setString(4, mbean.getGender());
ps.setString(5, mbean.getHobby());
ps.setString(6, mbean.getPhone());
ps.setString(7, mbean.getEtc());

ps.executeUpdate();

ps.close();
con.close();

response.sendRedirect("Result.jsp");
}
catch(Exception e)
{
}
%>

</body>
</html>

memberBean.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>Result</title>
</head>
<body>

<h2> 입력 완료 </h2>

<a href = "form.jsp"> 뒤로 </a>

</body>
</html>

MemberBean.java

package member;

public class MemberBean
{
private String id;
private String password;
private String name;
private String gender;
private String hobby;
private String phone;
private String etc;

public String getId()
{
return id;
}

public void setId(String id)
{
this.id = id;
}

public String getPassword()
{
return password;
}

public void setPassword(String password)
{
this.password = password;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}


public String getGender()
{
return gender;
}

public void setGender(String gender)
{
this.gender = gender;
}

public String getHobby()
{
return hobby;
}

public void setHobby(String hobby)
{
this.hobby = hobby;
}

public String getPhone()
{
return phone;
}

public void setPhone(String phone)
{
this.phone = phone;
}

public String getEtc()
{
return etc;
}

public void setEtc(String etc)
{
this.etc = etc;
}
}


result)