index
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*, java.text.*"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <head> <title>메인 페이지</title> </head> <body> <%=new Date()%> <h2>Hello World</h2> <% if(session.getAttribute("id")==null){ %> <form action = "t1"> id : <input type = "text" name = "id"><br> pw : <input type = "text" name = "pw"><br> <input type = "submit" value = "로그인"><br> </form> <form action = "aaa.jsp"> <input type = "submit" value = "회원가입"> </form> <% }else{ %> <form action = "logout.jsp"> <input type = "submit" value = "로그아웃"> </form> <%} %> </body> | cs |
select
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | package Pack01; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import javax.xml.ws.Response; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class select { @RequestMapping("t1") String func01(Model model ,String id, int pw) { try { //1단계 : class 확인 //현재 찾고 싶은 클래스를 찾아준다. String driver = "oracle.jdbc.driver.OracleDriver"; System.out.println(Class.forName(driver)); //2단계 : 로그인 Connection con = null; String dburl = "jdbc:oracle:thin:@127.0.0.1:1521:orcl"; String username = "c##jwh"; String password = "1"; con = DriverManager.getConnection(dburl, username, password); //3단계: 쿼리문 작성 및 컴파일 PreparedStatement ps = null; String sql = String.format("select * from banana where id='%s' and pw= %d",id,pw); System.out.println(sql); ps = con.prepareStatement(sql); ResultSet rs = ps.executeQuery(); boolean isfind=false; while(rs.next()) { String id1 = rs.getString("id"); int pw1 = rs.getInt("pw"); if(id.equals(id1)&&pw==pw1) { isfind = true; } } //4단계: 실행 ps.executeUpdate(); //f5번 누른것과 같다. //5단계: 접속 종료 ps.close(); if(isfind) { model.addAttribute("id",id); return "success"; }else { return "fail"; } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return "null"; } } | cs |
success
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html> <html> <head> <meta charset="EUC-KR"> <title>Insert title here</title> </head> <body> <% String name = request.getParameter("id"); String id = (String)request.getAttribute("id"); session.setAttribute("id", id); %> <%= name %>님 환영합니다. <a href = "index.jsp">홈으로</a> </body> </html> | cs |
logout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html> <html> <head> <meta charset="EUC-KR"> <title>Insert title here</title> </head> <body> <% session.invalidate(); response.sendRedirect("index.jsp"); %> </body> </html> | cs |
728x90
댓글