jQuery
ajax
csv / json /xml
cross domain 제한 - taglib proxy(*)
sql mapper - myBatis
sql 문 + java
=> sql -> xml(mapper)
* java programming
* web programming
모델 1 / 모델 2
DAO -> myBatis
1. 모델 1 게시판이 돌아 갈 수 있게 해준다
1) 라이브러리
2) context.xml
3) 빈즈
4) jsp / css / image / js
myBatis로 바꾸기 위해
1. 라이브러리
2. xml
3. dao -> mapper로 옮기는 작업
4. dao 수정
MyBatisBoardEx01.MyBatisConfig
<?xml version= "1.0" encoding ="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development1">
<environment id="development1">
<transactionManager type="JDBC" />
<dataSource type="POOLED" >
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
<property name="username" value="project"/>
<property name="password" value="project"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="model1/mapper.xml" />
</mappers>
</configuration>
MyBatisBoardEx01.model1.mapper
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="board">
<insert id="write_ok" parameterType="model1.BoardTO">
insert into board1
values (board_seq.nextval, #{subject}, #{writer}, #{mail}, #{password}, #{content}, 0, #{wip}, sysdate)
</insert>
<select id="list" resultType="model1.BoardTO">
select seq, subject, writer, to_char(wdate, 'YYYY/MM/DD') wdate, hit, trunc(sysdate-wdate) wgap
from board1
order by seq desc
</select>
<update id="view_hit" parameterType="model1.BoardTO">
update board1 set hit = hit + 1 where seq = #{seq}
</update>
<select id="view" parameterType="model1.BoardTO" resultType="model1.BoardTO">
select subject, writer, wdate, hit, content, mail
from board1 where seq = #{seq}
</select>
<select id="modify" parameterType="model1.BoardTO" resultType="model1.BoardTO">
select subject, writer, mail, content
from board1 where seq = #{seq}
</select>
<update id="modify_ok" parameterType="model1.BoardTO">
update board1 set subject= #{subject}, mail= #{mail}, content= #{content}
where seq= #{seq} and password= #{password}
</update>
<select id="delete" parameterType="model1.BoardTO" resultType="model1.BoardTO">
select subject, writer
from board1 where seq = #{seq}
</select>
<delete id="delete_ok" parameterType="model1.BoardTO">
delete from board1 where seq = #{seq} and password = #{password}
</delete>
</mapper>
mapper에서 parameter값 불러오기 할때 #{ 가져올 객체}로 할 것 $ 이런걸로 하지 말고..
MyBatisBoardEx01.model1.boardDAO
package model1;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
public class BoardDAO {
private SqlSession sqlSession;
public BoardDAO() {
String resource = "myBatisConfig.xml";
InputStream inputStream = null;
try {
inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory
= new SqlSessionFactoryBuilder().build(inputStream);
sqlSession = sqlSessionFactory.openSession(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if(inputStream != null) try { inputStream.close();} catch(IOException e) {};
}
}
public void boardWrite() {
}
public int boardWriteOk(BoardTO to) {
int flag = 1;
int result = sqlSession.insert("write_ok", to);
if(result == 1) {
flag = 0;
}
if(sqlSession != null) sqlSession.close();
return flag;
}
public ArrayList<BoardTO> boardList() {
ArrayList<BoardTO> boardLists
= (ArrayList)sqlSession.selectList("list");
if(sqlSession != null) sqlSession.close();
return boardLists;
}
public BoardTO boardView(BoardTO to) {
sqlSession.update("view_hit", to);
BoardTO view = (BoardTO)sqlSession.selectOne("view", to);
if(sqlSession != null) sqlSession.close();
return view;
}
public BoardTO boardModify(BoardTO to) {
BoardTO modify = (BoardTO)sqlSession.selectOne("modify", to);
if(sqlSession != null) sqlSession.close();
return modify;
}
public int boardModifyOk(BoardTO to) {
int flag = 2;
int result = sqlSession.update("modify_ok", to);
if(result == 1) {
flag = 0;
} else if (result == 0) {
flag = 1;
}
if(sqlSession != null) sqlSession.close();
return flag;
}
public BoardTO boardDelete(BoardTO to) {
BoardTO delete = (BoardTO)sqlSession.selectOne("delete", to);
if(sqlSession != null) sqlSession.close();
return delete;
}
public int boardDeleteOk(BoardTO to) {
int flag = 2;
int result = sqlSession.update("delete_ok", to);
if(result == 1) {
flag = 0;
} else if (result == 0) {
flag = 1;
}
if(sqlSession != null) sqlSession.close();
return flag;
}
}
MyBatisBoardEx01.log4j
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<!-- log를 출력하는 format -->
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-35c{1}:%-3L) %m%n" />
</layout>
</appender>
<root>
<!--
OFF - 로그 사용 안함
ERROR - 일반적 오류 발생
-->
<level value="ERROR"/>
<appender-ref ref="console"/>
</root>
</log4j:configuration>
AlbumEx01
AlbumEx02 - 강사님이 짜서 준거
SQL> create table album_board1 (
2 seq number not null primary key,
3 subject varchar2(150) not null,
4 writer varchar2(12) not null,
5 mail varchar2(50),
6 password varchar2(12) not null,
7 content varchar2(2000),
8 filename varchar2(200),
9 filesize number,
10 cmt number,
11 hit number not null,
12 wip varchar2(15) not null,
13 wdate date not null
14 );
테이블이 생성되었습니다.
SQL> create table album_comment1 (
2 seq number not null primary key,
3 pseq number not null,
4 writer varchar2(30) not null,
5 password varchar2(10) not null,
6 content varchar2(2000),
7 wdate date not null
8 );
테이블이 생성되었습니다.
AlbumEx02.albummodel1.BoardDAO
package albummodel1;
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class BoardDAO {
private DataSource dataSource = null;
public BoardDAO() {
// TODO Auto-generated constructor stub
try {
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
this.dataSource = (DataSource)envCtx.lookup("jdbc/oracle1");
} catch (NamingException e) {
// TODO Auto-generated catch block
System.out.println("[에러] : " + e.getMessage());
}
}
public void boardWrite() {
}
public int boardWriteOk(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
int flag = 1;
try {
conn = dataSource.getConnection();
String sql = "insert into album_board1 values (board_seq.nextval, ?, ?, ?, ?, ?, ?, ?, 0, 0, ?, sysdate)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSubject());
pstmt.setString(2, to.getWriter());
pstmt.setString(3, to.getMail());
pstmt.setString(4, to.getPassword());
pstmt.setString(5, to.getContent());
pstmt.setString(6, to.getFilename());
pstmt.setLong(7, to.getFilesize());
pstmt.setString(8, to.getWip());
int result = pstmt.executeUpdate();
if(result == 1) {
flag = 0;
}
} catch(SQLException e) {
System.out.println("[에러] : " + e.getMessage());
} finally {
if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
if(conn != null) try { conn.close(); } catch(SQLException e) {}
}
return flag;
}
public BoardListTO boardList(BoardListTO listTO) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int cpage = listTO.getCpage();
int recordPerPage = listTO.getRecordPerPage();
int blockPerPage = listTO.getBlockPerPage();
try {
conn = dataSource.getConnection();
String sql = "select seq, subject, writer, to_char(wdate, 'YYYY-MM-DD HH:mm') wdate, hit, trunc(sysdate-wdate) wgap, filename, cmt from album_board1 order by seq desc";
pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = pstmt.executeQuery();
rs.last();
listTO.setTotalRecord(rs.getRow());
rs.beforeFirst();
listTO.setTotalPage(((listTO.getTotalRecord() - 1) / recordPerPage) + 1);
int skip = (cpage - 1) * recordPerPage;
if(skip != 0) rs.absolute(skip);
ArrayList<BoardTO> boardLists = new ArrayList<>();
for(int i=0 ; i<recordPerPage && rs.next() ; i++) {
BoardTO to = new BoardTO();
to.setSeq(rs.getString("seq"));
to.setSubject(rs.getString("subject"));
to.setWriter(rs.getString("writer"));
to.setWdate(rs.getString("wdate"));
to.setHit(rs.getString("hit"));
to.setWgap(rs.getInt("wgap"));
to.setFilename(rs.getString("filename") == null ? "" : rs.getString("filename"));
to.setCmt(rs.getString("cmt"));
boardLists.add(to);
}
listTO.setBoardList(boardLists);
listTO.setStartBlock(((cpage - 1) / blockPerPage) * blockPerPage + 1);
listTO.setEndBlock(((cpage - 1) / blockPerPage) * blockPerPage + blockPerPage);
if(listTO.getEndBlock() >= listTO.getTotalPage()) {
listTO.setEndBlock(listTO.getTotalPage());
}
} catch(SQLException e) {
System.out.println("[에러] : " + e.getMessage());
} finally {
if(rs != null) try { rs.close(); } catch(SQLException e) {}
if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
}
return listTO;
}
public BoardTO boardView(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = dataSource.getConnection();
String sql = "update album_board1 set hit=hit+1 where seq=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
pstmt.executeUpdate();
pstmt.close();
sql = "select subject, writer, mail, wip, wdate, hit, content, filename, filesize from album_board1 where seq=?q=? and password=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
pstmt.setString(2, to.getPassword());
int result = pstmt.executeUpdate();
if(result == 0) {
flag = 1;
} else if(result == 1) {
flag = 0;
if(filename != null) {
File file = new File("C:/jQuery/eclipse-workspace/AlbumEx02/WebContent/upload", filename);
file.delete();
}
}
} catch(SQLException e) {
System.out.println("[에러] : " + e.getMessage());
} finally {
if(rs != null) try { rs.close(); } catch(SQLException e) {}
if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
}
return flag;
}
public BoardTO boardModify(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = dataSource.getConnection();
String sql = "select subject, writer, mail, content, filename from album_board1 where seq=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
rs = pstmt.executeQuery();
if(rs.next()) {
to.setSubject(rs.getString("subject"));
to.setWriter(rs.getString("writer"));
to.setMail(rs.getString("mail"));
to.setContent(rs.getString("content") == null ? "" : rs.getString("content"));
to.setFilename(rs.getString("filename") == null ? "" : rs.getString("filename"));
}
} catch(SQLException e) {
System.out.println("[에러] : " + e.getMessage());
} finally {
if(rs != null) try { rs.close(); } catch(SQLException e) {}
if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
}
return to;
}
public int boardModifyOk(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int flag = 2;
try {
conn = dataSource.getConnection();
String sql = "select filename from album_board1 where seq=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
rs = pstmt.executeQuery();
String filename = null;
if(rs.next()) {
filename = rs.getString("filename");
}
pstmt.close();
sql = "update album_board1 set subject=?, mail=?, content=?, filename=?, filesize=? where seq=? and password=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSubject());
pstmt.setString(2, to.getMail());
pstmt.setString(3, to.getContent());
pstmt.setString(4, to.getFilename());
pstmt.setLong(5, to.getFilesize());
pstmt.setString(6, to.getSeq());
pstmt.setString(7, to.getPassword());
int result = pstmt.executeUpdate();
if(result == 0) {
flag = 1;
File file = new File("C:/jQuery/eclipse-workspace/AlbumEx02/WebContent/upload", to.getFilename());
file.delete();
} else if(result == 1) {
flag = 0;
if(to.getFilename() != null && filename != null) {
File file = new File("C:/jQuery/eclipse-workspace/AlbumEx02/WebContent/upload", filename);
file.delete();
}
}
} catch(SQLException e) {
System.out.println("[에러] : " + e.getMessage());
} finally {
if(rs != null) try { rs.close(); } catch(SQLException e) {}
if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
}
return flag;
}
public BoardTO boardDelete(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = dataSource.getConnection();
String sql = "select subject, writer from album_board1 where seq=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
rs = pstmt.executeQuery();
if(rs.next()) {
to.setSubject(rs.getString("subject"));
to.setWriter(rs.getString("writer"));
}
} catch(SQLException e) {
System.out.println("[에러] : " + e.getMessage());
} finally {
if(rs != null) try { rs.close(); } catch(SQLException e) {}
if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
}
return to;
}
public int boardDeleteOk(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int flag = 2;
try {
conn = dataSource.getConnection();
String sql = "select filename from album_board1 where seq=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
rs = pstmt.executeQuery();
String filename = null;
if(rs.next()) {
filename = rs.getString("filename");
}
pstmt.close();
sql = "delete from album_board1 where seq=? and password=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
pstmt.setString(2, to.getPassword());
int result = pstmt.executeUpdate();
if(result == 0) {
flag = 1;
} else if(result == 1) {
flag = 0;
if(filename != null) {
File file = new File("C:/jQuery/eclipse-workspace/AlbumEx02/WebContent/upload", filename);
file.delete();
}
}
} catch(SQLException e) {
System.out.println("[에러] : " + e.getMessage());
} finally {
if(rs != null) try { rs.close(); } catch(SQLException e) {}
if(pstmt != null) try { pstmt.close(); } catch(SQLException e) {}
if(conn != null) try { pstmt.close(); } catch(SQLException e) {}
}
return flag;
}
}
AlbumEx02.albummodel1.BoardListTO
package albummodel1;
import java.util.ArrayList;
public class BoardListTO {
private int cpage;
private int recordPerPage;
private int blockPerPage;
private int totalPage;
private int totalRecord;
private int startBlock;
private int endBlock;
private ArrayList<BoardTO> boardList;
public BoardListTO() {
// TODO Auto-generated constructor stub
this.cpage = 1;
this.recordPerPage = 10;
this.blockPerPage = 5;
this.totalPage = 1;
this.totalRecord = 0;
}
public int getCpage() {
return cpage;
}
public void setCpage(int cpage) {
this.cpage = cpage;
}
public int getRecordPerPage() {
return recordPerPage;
}
public void setRecordPerPage(int recordPerPage) {
this.recordPerPage = recordPerPage;
}
public int getBlockPerPage() {
return blockPerPage;
}
public void setBlockPerPage(int blockPerPage) {
this.blockPerPage = blockPerPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
}
public int getStartBlock() {
return startBlock;
}
public void setStartBlock(int startBlock) {
this.startBlock = startBlock;
}
public int getEndBlock() {
return endBlock;
}
public void setEndBlock(int endBlock) {
this.endBlock = endBlock;
}
public ArrayList<BoardTO> getBoardList() {
return boardList;
}
public void setBoardList(ArrayList<BoardTO> boardList) {
this.boardList = boardList;
}
}
AlbumEx02.albummodel1.BoardTO
package albummodel1;
public class BoardTO {
private String seq;
private String subject;
private String writer;
private String mail;
private String password;
private String content;
private String filename;
private long filesize;
private String cmt;
private String hit;
private String wip;
private String wdate;
private int wgap;
public String getSeq() {
return seq;
}
public void setSeq(String seq) {
this.seq = seq;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public long getFilesize() {
return filesize;
}
public void setFilesize(long filesize) {
this.filesize = filesize;
}
public String getCmt() {
return cmt;
}
public void setCmt(String cmt) {
this.cmt = cmt;
}
public String getHit() {
return hit;
}
public void setHit(String hit) {
this.hit = hit;
}
public String getWip() {
return wip;
}
public void setWip(String wip) {
this.wip = wip;
}
public String getWdate() {
return wdate;
}
public void setWdate(String wdate) {
this.wdate = wdate;
}
public int getWgap() {
return wgap;
}
public void setWgap(int wgap) {
this.wgap = wgap;
}
}
AlbumEx02.model1.board_list1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="albummodel1.BoardTO" %>
<%@ page import="albummodel1.BoardListTO" %>
<%@ page import="albummodel1.BoardDAO" %>
<%@ page import="java.util.ArrayList" %>
<%
request.setCharacterEncoding("utf-8");
int cpage = 1;
if(request.getParameter("cpage") != null
&& !request.getParameter("cpage").equals("")) {
cpage = Integer.parseInt(request.getParameter("cpage"));
}
BoardListTO listTO = new BoardListTO();
listTO.setCpage(cpage);
BoardDAO dao = new BoardDAO();
listTO = dao.boardList(listTO);
int recordPerPage = listTO.getRecordPerPage();
int totalRecord = listTO.getTotalRecord();
int totalPage = listTO.getTotalPage();
int blockPerPage = listTO.getBlockPerPage();
int startBlock = listTO.getStartBlock();
int endBlock = listTO.getEndBlock();
ArrayList<BoardTO> boardLists = listTO.getBoardList();
StringBuffer result = new StringBuffer();
int rowCount = 0;
for(BoardTO to : boardLists) {
String seq = to.getSeq();
String subject = to.getSubject();
String writer = to.getWriter();
String filename = to.getFilename() == null ? "../images/noimage.jpg" : "../upload/" + to.getFilename();
String cmt = to.getCmt();
String wdate = to.getWdate();
String hit = to.getHit();
int wgap = to.getWgap();
if(rowCount%5 == 0) {
result.append("<tr>");
}
result.append(" <td class='last2'>");
result.append(" <div class='board'>");
result.append(" <table class='boardT'>");
result.append(" <tr>");
result.append(" <td class='boardThumbWrap'>");
result.append(" <div class='boardThumb'>");
if(!seq.equals("0")) {
result.append(" <a href='board_view1.jsp?cpage=" + cpage + "&seq=" + seq + "'><img src='" + filename + "' border='0' width='100%' /></a>");
} else {
result.append(" <img src='../images/noimage.jpg' border='0' width='100%' />");
}
result.append(" </div>");
result.append(" </td>");
result.append(" </tr>");
result.append(" <tr>");
result.append(" <td>");
result.append(" <div class='boardItem'>");
result.append(" <strong>" + subject +"</strong>");
result.append(" <span class='coment_number'><img src='../images/icon_comment.png' alt='commnet'>" + cmt + "</span>");
if(wgap == 0) {
result.append(" <img src='../images/icon_hot.gif' alt='HOT'>");
}
result.append(" </div>");
result.append(" </td>");
result.append(" </tr>");
result.append(" <tr>");
result.append(" <td><div class='boardItem'><span class='bold_blue'>" + writer + "</span></div></td>");
result.append(" </tr>");
result.append(" <tr>");
result.append(" <td><div class='boardItem'>" + wdate + " <font>|</font> Hit " + hit + "</div></td>");
result.append(" </tr>");
result.append(" </table>");
result.append(" </div>");
result.append("</td>");
if(rowCount%5 == 4) {
result.append("</tr>");
}
}
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<tiong>
</p>
</div>
<div class="contents_sub">
<div class="board_top">
<div class="bold">
<p>총 <span class="txt_orange"><%=totalRecord %></span>건</p>
</div>
</div>
<!--게시판-->
<table class="board_list">
<%=result %>
</table>
<!--//게시판-->
<div class="align_right">
<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='board_write1.jsp'">쓰기</button>
</div>
<!-- 페이지 -->
<div class="paginate_regular">
<div class="board_pagetab" align="middle">
<%
if(startBlock == 1) {
out.println("<span class='on'><<</span>");
} else {
out.println("<span class='off'><a href='board_list1.jsp?cpage=" + (startBlock - blockPerPage) + "'><<</a></span>");
}
out.println(" ");
if(cpage == 1) {
out.println("<span class='on'><</span>");
} else {
out.println("<span class='off'><a href='board_list1.jsp?cpage=" + (cpage-1)+ "'>< </a></span>");
}
out.println(" ");
for(int i=startBlock ; i<=endBlock ; i++) {
if(cpage == i) {
out.println("<span class='on'>[ " + i + " ]</span>");
} else {
out.println("<span class='off'><a href='board_list1.jsp?cpage=" + i + "'>" + i + "</a></span>");
}
}
out.println(" ");
if(cpage == totalPage) {
out.println("<span class='on'>></span>");
} else {
out.println("<span class='off'><a href='board_list1.jsp?cpage=" + (cpage+1)+ "'>></a></span>");
}
out.println(" ");
if(endBlock == totalPage) {
out.println("<span class='on'>>></span>");
} else {
out.println("<span class='off'><a href='board_list1.jsp?cpage=" + (startBlock + blockPerPage) + "'>>></a></span>");
}
%>
</div>
</div>
<!-- //페이지 -->
</div>
</div>
<!--//하단 디자인 -->
</body>
</html>
AlbumEx02.model1.board_write1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String cpage = request.getParameter("cpage");
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../css/board_write.css">
<script type="text/javascript">
window.onload = function() {
document.getElementById('submit1').onclick = function() {
if(document.frm.info.checked == false) {
alert('동의를 하셔야 합니다.');
return false;
}
if(document.frm.writer.value.trim() == "") {
alert('이름을 입력하셔야 합니다.');
return false;
}
if(document.frm.password.value.trim() == "") {
alert('비밀번호를 입력하셔야 합니다.');
return false;
}
if(document.frm.subject.value.trim() == "") {
alert('제목을 입력하셔야 합니다.');
return false;
}
if(document.frm.upload.value.trim() == "") {
alert('파일을 입력하셔야 합니다.');
return false;
} else {
var extension = document.frm.upload.value.split('.').pop();
if(extension != 'png' && extension != 'jpg' && extension != 'gif') {
alert('이미지 파일을 입력하셔야 합니다.');
return false;
}
}
document.frm.submit();
};
};
</script>
</head>
<body>
<!-- 상단 디자인 -->
<div class="contents1">
<div class="con_title">
<p style="margin: 0px; text-align: right">
<img style="vertical-align: middle" alt="" src="../images/home_icon.gif" /> > 커뮤니티 > <strong>여행지리뷰</strong>
</p>
</div>
<form action="./board_write1_ok.jsp" method="post" name="frm" enctype="multipart/form-data">
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top" colspan="3"><input type="text" name="writer" value="" class="board_view_input_mail" maxlength="5" /></td>
</tr>
<tr>
<th>제목</th>
<td colspan="3"><input type="text" name="subject" value="" class="board_view_input" /></td>
</tr>
<tr>
<th>비밀번호</th>
<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>내용</th>
<td colspan="3">
<textarea name="content" class="board_editor_area"></textarea>
</td>
</tr>
<tr>
<th>파일첨부</th>
<td colspan="3"><input type="file" name="upload" value="" class="board_view_input" /></td>
</tr>
<tr>
<th>이메일</th>
<td colspan="3"><input type="text" name="mail1" value="" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="" class="board_view_input_mail"/></td>
</tr>
</table>
<table>
<tr>
<br />
<td style="text-align:left;border:1px solid #e0e0e0;background-color:f9f9f9;padding:5px">
<div style="padding-top:7px;padding-bottom:5px;font-weight:bold;padding-left:7px;font-family: Gulim,Tahoma,verdana;">※ 개인정보 수집 및 이용에 관한 안내</div>
<div style="padding-left:10px;">
<div style="width:97%;height:95px;font-size:11px;letter-spacing: -0.1em;border:1px solid #c5c5c5;background-color:#fff;padding-left:14px;padding-top:7px;">
1. 수집 개인정보 항목 : 회사명, 담당자명, 메일 주소, 전화번호, 홈페이지 주소, 팩스번호, 주소 <br />
2. 개인정보의 수집 및 이용목적 : 제휴신청에 따른 본인확인 및 원활한 의사소통 경로 확보 <br />
3. 개인정보의 이용기간 : 모든 검토가 완료된 후 3개월간 이용자의 조회를 위하여 보관하며, 이후 해당정보를 지체 없이 파기합니다. <br />
4. 그 밖의 사항은 개인정보취급방침을 준수합니다.
</div>
</div>
<div style="padding-top:7px;padding-left:5px;padding-bottom:7px;font-family: Gulim,Tahoma,verdana;">
<input type="checkbox" name="info" value="1" class="input_radio"> 개인정보 수집 및 이용에 대해 동의합니다.
</div>
</td>
</tr>
</table>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./board_list1.jsp?cpage=<%=cpage %>'">목록</button>
</div>
<div class="align_right">
<button type="submit" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">등록</button>
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->
</body>
</html>
AlbumEx02.model1.board_write1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="albummodel1.BoardTO" %>
<%@ page import="albummodel1.BoardDAO" %>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy" %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="java.io.File" %>
<%
String uploadPath = "C:/jQuery/eclipse-workspace/AlbumEx02/WebContent/upload";
int maxFileSize = 1024 * 1024 * 10;
String encoding = "utf-8";
int flag = 1;
MultipartRequest multi = new MultipartRequest(request, uploadPath, maxFileSize, encoding, new DefaultFileRenamePolicy());
BoardTO to = new BoardTO();
to.setSubject(multi.getParameter("subject"));
to.setWriter(multi.getParameter("writer"));
to.setMail(multi.getParameter("mail1") + "@" + multi.getParameter("mail2"));
to.setPassword(multi.getParameter("password"));
to.setContent(multi.getParameter("content"));
to.setFilename(multi.getFilesystemName("upload"));
if(multi.getFile("upload") != null) {
to.setFilesize(multi.getFile("upload").length());
}
to.setWip(request.getRemoteAddr());
BoardDAO dao = new BoardDAO();
flag = dao.boardWriteOk(to);
out.println("<script type='text/javascript'>");
if(flag == 0) {
out.println("alert('글쓰기에 성공했습니다.');");
out.println("location.href='./board_list1.jsp'");
} else {
out.println("alert('글쓰기에 실패했습니다.');");
out.println("history.back();");
}
out.println("</script>");
%>
AlbumEx02.model1.board_view1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="albummodel1.BoardTO" %>
<%@ page import="albummodel1.BoardDAO" %>
<%
request.setCharacterEncoding("utf-8");
String cpage = request.getParameter("cpage");
BoardTO to = new BoardTO();
to.setSeq(request.getParameter("seq"));
BoardDAO dao = new BoardDAO();
to = dao.boardView(to);
String seq = to.getSeq();
String subject = to.getSubject();
String writer = to.getWriter();
String mail = to.getMail();
String wip = to.getWip();
String wdate = to.getWdate();
String hit = to.getHit();
String content = to.getContent();
String filename = to.getFilename().equals("") ? "" : to.getFilename();
String file = to.getFilename().equals("") ? "" : "<a href='./download.jsp?filename=" + to.getFilename() + "'>" + to.getFilename() + "</a> (" + to.getFilesize() + " Byte)";
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../css/board_view.css">
</head>
<body>
<!-- 상단 디자인 -->
<div class="contents1">
<div class="con_title">
<p style="margin: 0px; text-align: right">
<img style="vertical-align: middle" alt="" src="../images/home_icon.gif" /> > 커뮤니티 > <strong>여행지리뷰</strong>
</p>
</div>
<div class="contents_sub">
<!--게시판-->
<div class="board_view">
<table>
<tr>
<th width="10%">제목</th>
<td width="60%"><%=subject %></td>
<th width="10%">등록일</th>
<td width="20%"><%=wdate %></td>
</tr>
<tr>
<th>글쓴이</th>
<td><%=writer + "(" + wip + "/" + mail + ")" %></td>
<th>조회</th>
<td><%=hit %></td>
</tr>
<tr>
<th>첨부 파일</th>
<td><%=file %></td>
<th></th>
<td></td>
</tr>
<tr>
<td colspan="4" height="200" valign="top" style="padding:20px; line-height:160%">
<div id="bbs_file_wrap">
<div>
<img src="../upload/<%=filename %>" width="900" onerror="" /><br />
</div>
</div>
<%=content %>
</td>
</tr>
</table>
<table>
<tr>
<td class="coment_re" >
<strong>54545</strong> (2016.09.19 02:00)
<div class="coment_re_txt">
Test
</div>
</td>
<td class="coment_re" width="20%" align="right">
<input type="password" name="cpassword1" placeholder="비밀번호" class="coment_input pR10" />
<button type="button" class="btn_comment btn_txt02" style="cursor: pointer;">삭제</button>
</td>
</tr>
<tr>
<td class="coment_re">
<strong>하오리</strong> (2016.09.19 07:54)
<div class="coment_re_txt">
우리는 민족 중흥의 역사적 사명을 띄고 이 땅에 태어났다. 조상의 빛난 얼을 오늘에 되살려
</div>
</td>
<td class="coment_re" width="20%" align="right">
<input type="password" name="cpassword2" placeholder="비밀번호" class="coment_input pR10" />
<button type="button" class="btn_comment btn_txt02" style="cursor: pointer;">삭제</button>
</td>
</tr>
</table>
<form action="" method="post" name="cfrm">
<table>
<tr>
<td width="94%" class="coment_re">
글쓴이 <input type="text" name="cwriter" maxlength="5" class="coment_input" />
비밀번호 <input type="password" name="cpassword" class="coment_input pR10" />
</td>
<td width="6%" class="bg01"></td>
</tr>
<tr>
<td class="bg01">
<textarea name="ccontent" cols="" rows="" class="coment_input_text"></textarea>
</td>
<td align="right" class="bg01">
<button type="button" class="btn_re btn_txt01">댓글등록</button>
</td>
</tr>
</table>
</form>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp'">목록</button>
</div>
<div class="align_right">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_modify1.jsp?cpage=<%=cpage %>&seq=<%=seq %>'">수정</button>
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_delete1.jsp?cpage=<%=cpage %>&seq=<%=seq %>'">삭제</button>
<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='board_write1.jsp?cpage=<%=cpage %>'">쓰기</button>
</div>
</div>
<!--//게시판-->
</div>
<!-- 하단 디자인 -->
</div>
</body>
</html>
AlbumEx02.model1.board_modify1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="albummodel1.BoardTO" %>
<%@ page import="albummodel1.BoardDAO" %>
<%
request.setCharacterEncoding("utf-8");
String cpage = request.getParameter("cpage");
BoardTO to = new BoardTO();
to.setSeq(request.getParameter("seq"));
BoardDAO dao = new BoardDAO();
to = dao.boardModify(to);
String seq = to.getSeq();
String subject = to.getSubject();
String writer = to.getWriter();
String mail[] = to.getMail().split("@");
if(mail.length <= 1) {
mail = new String[] { "", "" };
}
String content = to.getContent();
String filename = to.getFilename().equals("") ? "" : "기존 파일명 : " + to.getFilename() + "<br /><br />";
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../css/board_write.css">
<script type="text/javascript">
window.onload = function() {
document.getElementById("submit1").onclick = function() {
if(document.frm.password.value.trim() == "") {
alert("비밀번호를 입력하셔야 합니다.");
return false;
}
if(document.frm.subject.value.trim() == "") {
alert("제목을 입력하셔야 합니다.");
return false;
}
if(document.frm.upload.value.trim() == "") {
alert('파일을 입력하셔야 합니다.');
return false;
} else {
var extension = document.frm.upload.value.split('.').pop();
if(extension != 'png' && extension != 'jpg' && extension != 'gif') {
alert('이미지 파일을 입력하셔야 합니다.');
return false;
}
}
document.frm.submit();
};
};
</script>
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <strong>게시판</strong></p>
</div>
<div class="con_txt">
<form action="./board_modify1_ok.jsp" method="post" name="frm" enctype="multipart/form-data">
<input type="hidden" name="cpage" value="<%=cpage %>" />
<input type="hidden" name="seq" value="<%=seq %>" />
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top" colspan="3"><input type="text" name="writer" value="<%=writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
</tr>
<tr>
<th>제목</th>
<td colspan="3"><input type="text" name="subject" value="<%=subject %>" class="board_view_input" /></td>
</tr>
<tr>
<th>비밀번호</th>
<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>내용</th>
<td colspan="3"><textarea name="content" class="board_editor_area"><%=content %></textarea></td>
</tr>
<tr>
<th>이메일</th>
<td colspan="3"><input type="text" name="mail1" value="<%=mail[0] %>" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="<%=mail[1] %>" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>첨부파일</th>
<td colspan="3">
<%=filename %>
<input type="file" name="upload" value="" class="board_view_input" />
</td>
</tr>
</table>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?cpage=<%=cpage %>'">목록</button>
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?cpage=<%=cpage %>&seq=<%=seq %>'">보기</button>
</div>
<div class="align_right">
<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">수정</button>
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->
</body>
</html>
AlbumEx02.model1.board_modify1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="albummodel1.BoardTO" %>
<%@ page import="albummodel1.BoardDAO" %>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy" %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="java.io.File" %>
<%
String uploadPath = "C:/jQuery/eclipse-workspace/AlbumEx02/WebContent/upload";
int maxFileSize = 1024 * 1024 * 10;
String encoding = "utf-8";
int flag = 2;
MultipartRequest multi = new MultipartRequest(request, uploadPath, maxFileSize, encoding, new DefaultFileRenamePolicy());
String cpage = multi.getParameter("cpage");
BoardTO to = new BoardTO();
to.setSeq(multi.getParameter("seq"));
to.setPassword(multi.getParameter("password"));
to.setSubject(multi.getParameter("subject"));
to.setMail(multi.getParameter("mail1") + "@" + multi.getParameter("mail2"));
to.setContent(multi.getParameter("content"));
to.setFilename(multi.getFilesystemName("upload"));
if(multi.getFile("upload") != null) {
to.setFilesize(multi.getFile("upload").length());
}
BoardDAO dao = new BoardDAO();
flag = dao.boardModifyOk(to);
out.println("<script type='text/javascript'>");
if(flag == 0) {
out.println("alert('글수정에 성공했습니다.')");
out.println("location.href='./board_view1.jsp?cpage=" + cpage + "&seq=" + to.getSeq() + "'");
} else if(flag == 1){
out.println("alert('비밀번호가 틀립니다.')");
out.println("history.back()");
} else {
out.println("alert('글수정에 실패했습니다.')");
out.println("history.back()");
}
out.println("</script>");
%>
AlbumEx02.model1.board_delete1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="albummodel1.BoardTO" %>
<%@ page import="albummodel1.BoardDAO" %>
<%
request.setCharacterEncoding("utf-8");
String cpage = request.getParameter("cpage");
BoardTO to = new BoardTO();
to.setSeq(request.getParameter("seq"));
BoardDAO dao = new BoardDAO();
to = dao.boardDelete(to);
String seq = to.getSeq();
String subject = to.getSubject();
String writer = to.getWriter();
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../css/board_write.css">
<script type="text/javascript">
window.onload = function() {
document.getElementById('submit1').onclick = function() {
if(document.frm.password.value.trim() == "") {
alert('비밀번호를 입력하셔야 합니다.');
return false;
}
document.frm.submit();
};
};
</script>
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <strong>게시판</strong></p>
</div>
<div class="con_txt">
<form action="board_delete1_ok.jsp" method="post" name="frm">
<input type="hidden" name="seq" value="<%=seq %>" />
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top" colspan="3"><input type="text" name="writer" value="<%=writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
</tr>
<tr>
<th>제목</th>
<td colspan="3"><input type="text" name="subject" value="<%=subject %>" class="board_view_input" readonly/></td>
</tr>
<tr>
<th>비밀번호</th>
<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
</table>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?cpage=<%=cpage %>'">목록</button>
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?cpage=<%=cpage %>&seq=<%=seq %>'">보기</button>
</div>
<div class="align_right">
<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">삭제</button>
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->
</body>
</html>
AlbumEx02.model1.board_delete1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="albummodel1.BoardTO" %>
<%@ page import="albummodel1.BoardDAO" %>
<%
request.setCharacterEncoding("utf-8");
BoardTO to = new BoardTO();
to.setSeq(request.getParameter("seq"));
to.setPassword(request.getParameter("password"));
BoardDAO dao = new BoardDAO();
int flag = dao.boardDeleteOk(to);
out.println("<script type='text/javascript'>");
if(flag == 0) {
out.println("alert('글삭제에 성공했습니다.')");
out.println("location.href='./board_list1.jsp'");
} else if(flag == 1){
out.println("alert('비밀번호가 틀립니다.')");
out.println("history.back()");
} else {
out.println("alert('글삭제에 실패했습니다.')");
out.println("history.back()");
}
out.println("</script>");
%>
AlbumEx02.model1.download
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= "UTF-8" trimDirectiveWhitespaces="true" %>
<%@ page import="java.io.FileInputStream"%>
<%@ page import="java.net.URLEncoder" %>
<%
String fileName = request.getParameter("filename");
String downPath = "C:/jQuery/eclipse-workspace/AlbumEx02/WebContent/upload/" + fileName;
byte b[] = new byte[4096];
out.clearBuffer();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
FileInputStream sin = new FileInputStream(downPath);
ServletOutputStream sout = response.getOutputStream();
int data;
while((data = sin.read(b, 0, b.length)) != -1) {
sout.write(b, 0, data);
}
sout.flush();
sout.close();
sin.close();
%>
model1 기존 게시판 pds_board1소스를 사용하여서 해볼려고 했는데 write에서 flag값을 초기값 지정을 안해줘서 NullPointerException에러가 생겼었습니다. 초기값 설정을 해주고 로직 수행되어 flag값이 DAO로 넘어가야 하는데 초기값이 안되어버리니 에러가 생긴 것 같습니다.
리눅스 OS 받기 www.centos.org https://www.vmware.com/kr.html
다음 Lecture부터 Linux 시작하겠습니다.
'Web & Mobile > JSP' 카테고리의 다른 글
Lecture 33 - JSP(2) 우편번호검색, DatabaseMetadata, Callable (0) | 2023.06.20 |
---|---|
Lecture 32 - JSP(1) JDBC API 사용법(Java와 SQL 연동) (0) | 2023.06.20 |
Lecture 61 - JSP(19) ZipcodeController, MyBatis 설정법, Mapper (0) | 2019.06.13 |
Lecture 60 - JSP(18) JSTL, 우편번호검색 (0) | 2019.06.12 |
Lecture 59 - JSP(17) EL, <%= %>, EL을 Model1 게시판에 적용, JSTL (0) | 2019.06.11 |
댓글