-
day51 - JSP(model2, login)KIC/JSP 2021. 8. 26. 22:49반응형
[memberInput]
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <div class="w3-content " style="width:80%; align-self: center;"> <form action="<%=request.getContextPath()%>/member/memberInputPro" name="f" method="post"> <input type="hidden" name="picture" value=""> <table > <caption>회원가입</caption> <tr> <td rowspan="4" valign="bottom"><img src="" width="100" height="120" id="pic"><br> <font size="1"><a href="javascript:win_upload()">사진등록</a></font></td> <td>아이디</td> <td><input type="text" name="id"></td> </tr> <tr> <td>비밀번호</td> <td><input type="password" name="pass"></td> </tr> <tr> <td>이름</td> <td><input type="text" name="name"></td> </tr> <tr> <td>성별</td> <td><input type="radio" value="1" name="gender" checked>남 <input type="radio" value="2" name="gender" >여</td> </tr> <tr> <td>전화번호</td> <td colspan="2"><input type="text" name="tel"></td> </tr> <tr> <td>이메일</td> <td colspan="2"><input type="text" name="email"></td> </tr> <tr> <td colspan="3" align="right"><input type="submit" value="회원가입"></td> </tr> </table> </form></div> </body> </html>
[memberDao]
package dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import model.Member; import util.DBConnection; public class MemberDao { public int memberInsert(Member member) { Connection con = DBConnection.getConnection(); PreparedStatement pstmt = null; String sql = "insert into member2 values (?, ?, ?, ?, ?, ?, ?)"; try { pstmt = con.prepareStatement(sql); pstmt.setString(1, member.getId()); pstmt.setString(2, member.getPass()); pstmt.setString(3, member.getName()); pstmt.setInt(4, member.getGender()); pstmt.setString(5, member.getTel()); pstmt.setString(6, member.getEmail()); pstmt.setString(7, member.getPicture()); return pstmt.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { DBConnection.close(con, pstmt, null); } return 0; } public List<Member> memberList() { Connection con = DBConnection.getConnection(); PreparedStatement pstmt = null; ResultSet rs = null; String sql = "select * from member2"; List<Member> li = new ArrayList<Member>(); try { pstmt = con.prepareStatement(sql); rs=pstmt.executeQuery(); while(rs.next()) { Member member = new Member(); member.setId(rs.getString("id")); member.setPass(rs.getString("pass")); member.setName(rs.getString("name")); member.setGender(rs.getInt("gender")); member.setTel(rs.getString("tel")); member.setEmail(rs.getString("email")); member.setPicture(rs.getString("picture")); li.add(member); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { DBConnection.close(con, pstmt, rs); } return li; } public Member selectOne(String id) { Connection con = DBConnection.getConnection(); PreparedStatement pstmt = null; ResultSet rs = null; String sql = "select * from member2 where id=?"; Member member = new Member(); try { pstmt = con.prepareStatement(sql); pstmt.setString(1, id); rs=pstmt.executeQuery(); if(rs.next()) { member.setId(rs.getString("id")); member.setPass(rs.getString("pass")); member.setName(rs.getString("name")); member.setGender(rs.getInt("gender")); member.setTel(rs.getString("tel")); member.setEmail(rs.getString("email")); member.setPicture(rs.getString("picture")); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { DBConnection.close(con, pstmt, rs); } System.out.println(member); return member; } }
[loginForm.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <div class="w3-content" style="width:50%;"> <form action="<%=request.getContextPath() %>/member/loginPro" method="post"> <caption><h2>로그인</h2></caption> <table> <tr><th>아이디</th><td><input type="text" name="id"></td></tr> <tr><th>비밀번호</th><td><input type="password" name="pass"></td></tr> <tr><td colspan="2" ><input type="submit" value="로그인"> <input type="submit" value="회원가입" onclick="location.href='<%=request.getContextPath() %>/member/memberInput'"></td> </tr> </table> </form> <br><br> </div> </body> </html>
300x250'KIC > JSP' 카테고리의 다른 글
day53 - JSP(사진 추가 페이지) (0) 2021.08.31 day52 - JSP(login, memberList) (0) 2021.08.27 day50 - JSP(model2, login, DBconnection) (0) 2021.08.26 day49 - JSP(model2) (0) 2021.08.25 day48 - JSP(model2) (0) 2021.08.24