- addform.jsp 파일
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <%@ 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> <h1>입력폼 페이지</h1> <form action="add.jsp"> <p>id:<input type="text" name="id"> </p> <p>pw:<input type="text" name="pw"> </p> <p><input type="submit" value="입 력"> <input type="reset" value="취소"></p> </form> </body> </html> | cs |
- add.jsp 파일 (DB연동)
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 | <%@page import="java.sql.Statement"%> <%@page import="java.sql.Connection"%> <%@page import="java.sql.DriverManager"%> <%@ 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> <% String id = request.getParameter("id"); String pw = request.getParameter("pw"); System.out.println(id+" : "+pw); String url = "jdbc:oracle:thin:@localhost:1521:xe"; String user="scott"; String password = "tiger"; String sql="insert into testuser values ('"+id+"','"+pw+"')"; Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection(url,user,password); Statement stmt = conn.createStatement(); int cnt = stmt.executeUpdate(sql); if(cnt>0){ out.print("<h1>정상입력 되었습니다.</h>"); }else{ out.print("<h1>입력 실패</h>"); } %> </body> </html> | cs |
DB 에 값 넣기 전
실행
입력 완료
DB 입력 후
'* Programming > WEB' 카테고리의 다른 글
Form(회원가입) (0) | 2016.09.08 |
---|---|
Form(로그인창) (0) | 2016.09.08 |
기본 내장객체 (0) | 2016.09.08 |
스크립트릿 특징 (0) | 2016.09.08 |
Table사용(구구단 만들기) (1) | 2016.09.08 |