Jsp - 게시글 쓰기

2020. 7. 30. 21:28Jsp

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<%@ 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>
<h1>boarder/writeForm.jsp</h1>
<form action="writePro.jsp" method="post">
<table border="1">
<tr><td>글쓴이</td><td><input type="text" name="name"></td></tr>
<tr><td>비밀번호</td><td><input type="password" name="pass"></td></tr>
<tr><td>제목</td><td><input type="text" name="subject"></td></tr>
<tr><td>내용</td><td><textarea rows="10" cols="20" name="content"></textarea></td></tr>
<tr><td colspan="2"><input type="submit" value="글쓰기"></td></tr>
 
</table>
</form>
</body>
</html>
 
 
<%@page import="board.BoardDAO"%>
<%@page import="board.BoardDTO"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.Timestamp"%>
<%@ 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>
<h1>boarder/writePro.jsp</h1>
<%
//한글처리
request.setCharacterEncoding("utf-8");
//name pass subject content 파라미터 가져오기
String name=request.getParameter("name");
String pass=request.getParameter("pass");
String subject=request.getParameter("subject");
String content=request.getParameter("content");
 
//int  readcount=0         Timestamp date = 시스템 날짜
int readcount=0;
Timestamp time=new Timestamp(System.currentTimeMillis());
//패키지 board  파일이름  BoardBean 만들기 멤버변수 Getter/Setter
//BoardBean bb 객체 생성
BoardDTO bb=new BoardDTO();
//멤버변수<=파라미터값 저장
bb.setName(name);
bb.setPass(pass);
bb.setSubject(subject);
bb.setContent(content);
bb.setReadcount(readcount);
bb.setTime(time);
 
 
//패키지 board 파일이름 BoardDAO 만들기
//insertBoard(bb) 메서드만들기
//BoardDAO bdao 객체 생성
//insertBoard(bb) 메서드 호출
BoardDAO bdao=new BoardDAO();
bdao.insertBoard(bb);
 
 
//list.jsp 이동
response.sendRedirect("list.jsp");
%>
 
 
</body>
</html>
 
cs

 

DAO와 DTO를 활용하여 게시글을 작성하는 기능을 구현해 보았다. 파라미터를 받아오고 입력하고 어떻게 하는지만 안다면 간단하게 적용 가능하니 헷갈려서 실수만 하지 말도록 해야겠다.

'Jsp' 카테고리의 다른 글

Jsp - Update 게시글  (0) 2020.07.30
Jsp - Delete 게시글  (0) 2020.07.30
Jsp - DAO,Paging 을 활용한 게시판 글목록 불러오기  (1) 2020.07.30
Jsp - file upload  (0) 2020.07.26
Jsp - paging  (0) 2020.07.26