본문 바로가기

자바 웹/MVC

MVC - 서블릿(컨트롤러)/답변형 게시판 3(수정, 삭제)

728x90

이미지와 글을 수정한 후 수정 사항을 저장하면 컨트롤러는 이 요청을 upload() 메서드를 이용해 수정 데이터를 Map에 저장하고 반환한다. 

 

컨트롤러는 수정된 데이터를 테이블에 반영한 후 temp 폴더에 업로드 된 수정 이미지를 글 번호로 이동시키고, 글 번호 폴더에 있던 원래 이미지 파일을 삭제한다.

 

 

글 상세 페이지로 들어가면 위와 같은 화면이 출력된다 여기서 수정하기를 누르게 되면, disabled로 되어있던 부분이 변경 가능하도록 바뀐다.

 

 

이제 글이나 이미지를 수정하고 수정반영하기를 클릭하면 변경된 데이터로 상세페이지가 다시 출력된다.

 

글을 삭제할 때는 테이블의 글 뿐 아니라 그 글의 자식 글과 이미지 파일도 함께 삭제해야 한다. 자연적으로 삭제된 글에 대한 이미지 파일 저장 폴더도 삭제한다.

 

 

 

 

삭제하기를 선택하면 해당 이미지 저장 폴더인 13번도 함께 삭제되어야 한다.

 

 

 

목록에서도 글이 삭제되었고, 이미지 저장 폴더도 삭제된 것을 확인할 수 있다.

 

BoardController

 

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
@WebServlet("/board/*")
public class BoardController extends HttpServlet {
    
    private static String ARTICLE_IMG_REPO = "C:\\pra_board\\article_img";//이미지 저장 위치
    BoardService boardService;
    ArticleVO articleVO;
    
    @Override
    public void init(ServletConfig config) throws ServletException {
        //서블릿 초기화 시 BoardService 객체 생성
        boardService = new BoardService();
        articleVO = new ArticleVO();
    }
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doHandle(request, response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doHandle(request, response);
    }
    
    private void doHandle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String nextPage ="";
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=utf-8");
        String action = request.getPathInfo();//요청명을 가져옴
        
        try {
            List<ArticleVO> articleList = new ArrayList<ArticleVO>();
            if(action == null) {
                articleList = boardService.listArticles();
                request.setAttribute("articleList", articleList);
                nextPage = "/board01/listArticles.jsp";
            }
            //액션 값이 아래와 같으면 전체 글을 조회
            else if(action.equals("/listArticles.do")) {
                articleList = boardService.listArticles();//전체 글 조회
                request.setAttribute("articleList", articleList);//articleList로 바인딩
                nextPage = "/board01/listArticles.jsp";//listArticles.jsp로 포워딩
            }
            //액션 값이 아래와 같으면 글쓰기 페이지로 이동
            else if(action.equals("/articleForm.do")) {
                nextPage = "/board01/articleForm.jsp";
            }        
            //액션 값이 아래와 같으면 새 글 추가 작업 실행
            else if(action.equals("/addArticle.do")) {
                int articleno = 0;
                //파일 업로드 기능을 사용하기 위해서 upload()로 요청을 전달
                Map<StringString> articleMap = upload(request,response);
                //articleMap에 저장한 글 정보를 다시 가져옴
                String title = articleMap.get("title");
                String content = articleMap.get("content");
                String imagefilename = articleMap.get("imagefilename");
                System.out.println(title+","+content+","+imagefilename);
                
                //글쓰기 창에서 입력된 정보를 VO 객체에 설정한 후 addArticle()로 전달
                articleVO.setParentno(0);//새 글의 부모 글 번호를 0으로 설정
                articleVO.setId("hong");//새 글 작성자 ID를 hong으로 설정
                articleVO.setTitle(title);
                articleVO.setContent(content);
                articleVO.setImagefilename(imagefilename);
                articleno = boardService.addArticle(articleVO);//테이블에 새 글을 추가한 후 새 글에 대한 글 번호 가져옴                
                
                //파일을 첨부한 경우에만 수행
                if(imagefilename != null && imagefilename.length() != 0) {
                    //temp 폴더에 임시로 업로드 될 파일 객체를 생성
                    File srcFile = new File(ARTICLE_IMG_REPO+"\\"+"temp"+"\\"+imagefilename);
                    System.out.println("srcFile = "+srcFile);
                    
                    //CURR_IMAGE_REPO_PATH의 경로 하위에 글 번호로 폴더를 생성
                    File destDir = new File(ARTICLE_IMG_REPO+"\\"+articleno);
                    System.out.println("destDir = "+destDir);
                    destDir.mkdirs();
                    
                    //temp 폴더의 파일을 글 번호를 이름으로 하는 폴더로 이동
                    FileUtils.moveFileToDirectory(srcFile, destDir, true);
                }
                //새 글 등록 메시지를 나타낸 후 자바스크립트 location 객체의 href 속성을 이용해 글 목록을 요청
                PrintWriter writer = response.getWriter();
                writer.print("<script>" + " alert('새 글을 추가했습니다.');"
                                        + " location.href='"
                                        + request.getContextPath()
                                        + "/board/listArticles.do';"+"</script>");
                return;
                
            }
            else if(action.equals("/viewArticle.do")) {
                String articleno = request.getParameter("articleno");//글 상세창을 요청할 경우 articleno 값을 가져옴
                
                //articleno에 대한 글 정보를 조회하고 article 속성으로 바인딩
                articleVO = boardService.viewArticle(Integer.parseInt(articleno));
                request.setAttribute("article", articleVO);
                
                nextPage = "/board01/viewArticle.jsp";
            }
            else if(action.equals("/modArticle.do")) {
                Map<String,String> articleMap = upload(request,response);
                int articleno = Integer.parseInt(articleMap.get("articleno"));
                articleVO.setArticleno(articleno);
                System.out.println("articleno = "+articleno);
                
                String title = articleMap.get("title");
                String content = articleMap.get("content");
                String imagefilename = articleMap.get("imagefilename");
                
                articleVO.setParentno(0);
                articleVO.setId("hong");
                articleVO.setTitle(title);
                articleVO.setContent(content);
                articleVO.setImagefilename(imagefilename);
                
                boardService.modArticle(articleVO);//전송된 글 정보를 이용해 글을 수정
                
                if(imagefilename != null && imagefilename.length() != 0) {
                    String originalFileName = articleMap.get("originalFileName");
                    
                    //수정된 이미지 파일을 폴더로 이동
                    File srcFile = new File(ARTICLE_IMG_REPO+"\\"+"temp"+"\\"+imagefilename);
                    File destDir = new File(ARTICLE_IMG_REPO+"\\"+articleno);
                    destDir.mkdirs();
                    FileUtils.moveFileToDirectory(srcFile, destDir, true);
                    
                    //전송된 originalFileName을 이용해 기존의 파일을 삭제
                    File oldFile = new File(ARTICLE_IMG_REPO+"\\"+articleno+"\\"+originalFileName);
                    oldFile.delete();
                }
                //새 글 등록 메시지를 나타낸 후 자바스크립트 location 객체의 href 속성을 이용해 글 목록을 요청
                PrintWriter writer = response.getWriter();
                writer.print("<script>" + " alert('글을 수정했습니다.');"
                                        + " location.href='"
                                        + request.getContextPath()
                                        + "/board/viewArticle.do?articleno="+articleno+"';"+"</script>");
                return;
            }
            else if(action.equals("/removeArticle.do")) {
                int articleno = Integer.parseInt(request.getParameter("articleno"));
                //articleno 값에 대한 글을 삭제한 후 삭제된 부모 글과 자식 글의 articleno 목록을 가져옴
                List<Integer> articleNoList = boardService.removeArticle(articleno);
                
                //삭제된 글들의 이미지 저장 폴더들을 삭제
                for(int _articleno : articleNoList) {
                    File imgDir = new File(ARTICLE_IMG_REPO+"\\"+_articleno);
                    if(imgDir.exists()) {
                        FileUtils.deleteDirectory(imgDir);
                    }
                }
                
                PrintWriter writer = response.getWriter();
                writer.print("<script>" + " alert('글을 삭제했습니다.');"
                                        + " location.href='"
                                        + request.getContextPath()
                                        + "/board/listArticles.do';"+"</script>");
                return;
            }
            else {
                nextPage = "/board01/listArticles.jsp";
            }
            
            RequestDispatcher dispatch = request.getRequestDispatcher(nextPage);
            dispatch.forward(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private Map<StringString> upload(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map<StringString> articleMap = new HashMap<StringString>();
        String encoding = "utf-8";
        File currentDirPath = new File(ARTICLE_IMG_REPO);//글 이미지 저장 폴더에 대해 파일 객체를 생성
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setRepository(currentDirPath);
        factory.setSizeThreshold(1024*1024);
        ServletFileUpload upload = new ServletFileUpload(factory);
        
        try {
            List items = upload.parseRequest(request);//request 객체에서 매개변수를 List로 가져옴
            for (int i = 0; i < items.size(); i++) {
                FileItem fileItem = (FileItem) items.get(i);//파일 업로드창에서 업로드된 항목들을 하나씩 가져옴
                
                //폼 필드면 전송된 매개변수 값을 출력
                if (fileItem.isFormField()) {
                    System.out.println(fileItem.getFieldName()+"="+fileItem.getString(encoding));
                    //파일 업로드로 같이 전송된 새 글 관련 매개변수를 Map에 저장한 후 반환하고, 새 글과 관련된 title, content를 Map에 저장
                    articleMap.put(fileItem.getFieldName(), fileItem.getString(encoding));
                }
                else {
                    //업로드한 파일이 존재하는 경우 업로드한 파일의 파일 이름으로 저장소에 업로드
                    if(fileItem.getSize() > 0) {
                        int idx = fileItem.getName().lastIndexOf("\\");
                        
                        if(idx == -1) {
                            idx = fileItem.getName().lastIndexOf("/");
                        }
                        //첨부한 파일을 먼저 temp 폴더에 업로드,
                        String fileName = fileItem.getName().substring(idx+1);
                        System.out.println("파일명 = "+fileName);
                        articleMap.put(fileItem.getFieldName(), fileName);//익스플로러에서 업로드 파일의 경로 제거 후 map에 파일명 저장
                        File uploadFile = new File(currentDirPath+"\\temp\\"+fileName);
                        
                        fileItem.write(uploadFile);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return articleMap;
    }
}
cs

 

DAO

 

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
public class BoardDAO {
    private static BoardDAO instance = new BoardDAO();
    private Connection con = null;
    private PreparedStatement pstmt = null;
    private ResultSet rs = null;
 
    public static BoardDAO getInstance() {
        return instance;
    }
 
    public Connection getConnection() throws Exception {
        Context ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/oracle");
        return ds.getConnection();
    }
    
    public List<ArticleVO> selectAllArticles() {
        List<ArticleVO> articleList = new ArrayList<ArticleVO>();
        
        try{
            con = getConnection();
            //오라클 계층형 SQL문 실행
            String sql = "select level, articleno, parentno, title, content, id, writedate from t_board "
                    + "start with parentno=0 "
                    + "connect by prior articleno=parentno "
                    + "order siblings by articleno desc";
            pstmt = con.prepareStatement(sql);
            rs = pstmt.executeQuery();
 
            while (rs.next()) {
                int level = rs.getInt("level");//각 글의 계층을 저장
                int articleno = rs.getInt("articleno");
                int parentno = rs.getInt("parentno");
                String title = rs.getString("title");
                String content = rs.getString("content");
                String id = rs.getString("id");
                Date writedate = rs.getDate("writedate");
                //글 정보를 ArticleVO 객체의 속성에 설정
                ArticleVO article = new ArticleVO();
                article.setLevel(level);
                article.setArticleno(articleno);
                article.setParentno(parentno);
                article.setTitle(title);
                article.setContent(content);
                article.setId(id);
                article.setWritedate(writedate);
 
                articleList.add(article);
            }
            rs.close();
            pstmt.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return articleList;
    }
    
    //insertNewArticle 메서드의 쿼리를 실행하기 전에 새 글에 대한 글 번호를 먼저 가져옴
    private int getNewArticleNO() {
        int re = 0;
        try{
            con = getConnection();
            String sql = "select max(articleno) from t_board";//기본 글 번호 중 가장 큰 번호 조회
            System.out.println(sql);
            pstmt = con.prepareStatement(sql);
            rs = pstmt.executeQuery();
 
            //가장 큰 번호에 1을 더한 번호를 반환
            if (rs.next()) {
                re = rs.getInt(1)+1;
                return re;
            }
            rs.close();
            pstmt.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return re;
    }
 
    public int insertNewArticle(ArticleVO article) {
        int articleno = getNewArticleNO();//새 글을 추가하기 전에 새 글에 대한 글 번호를 가져옴
 
        try{
            con = getConnection();
            
            int parentno = article.getParentno();
            String title = article.getTitle();
            String content = article.getContent();
            String id = article.getId();
            String imagefilename = article.getImagefilename();
 
            String sql = "insert into t_board (articleno, parentno, title, content, id, imagefilename) values(?,?,?,?,?,?)";
            pstmt = con.prepareStatement(sql);
            pstmt.setInt(1, articleno);
            pstmt.setInt(2, parentno);
            pstmt.setString(3, title);
            pstmt.setString(4, content);
            pstmt.setString(5, id);
            pstmt.setString(6, imagefilename);
            System.out.println("dao imagefilename = "+imagefilename);
            pstmt.executeUpdate();
            
            pstmt.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("dao articleno = "+articleno);
        return articleno;
    }
    
    public ArticleVO selectArticle(int articleno) {
        ArticleVO article = new ArticleVO();
 
        try{
            con = getConnection();
            String sql = "select articleno, parentno, title, content, imagefilename, id, writedate from t_board where articleno=?";
            pstmt = con.prepareStatement(sql);
            pstmt.setInt(1,articleno);
            rs = pstmt.executeQuery();
 
            if (rs.next()) {
                int _articleno = rs.getInt("articleno");
                int parentno = rs.getInt("parentno");
                String title = rs.getString("title");
                String content = rs.getString("content");
                String imagefilename = rs.getString("imagefilename");
                String id = rs.getString("id");
                Date writedate = rs.getDate("writedate");
 
                article.setArticleno(_articleno);
                article.setParentno(parentno);
                article.setTitle(title);
                article.setContent(content);
                article.setImagefilename(imagefilename);
                article.setId(id);
                article.setWritedate(writedate);
            }
            rs.close();
            pstmt.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return article;
    }
    
    public void updateArticle(ArticleVO article) {
        int articleno = article.getArticleno();
        String title = article.getTitle();
        String content = article.getContent();
        String imagefilename = article.getImagefilename();
        
        try{
            con = getConnection();
            String sql = "update t_board set title=?, content=?";
            //수정된 이미지 파일이 있을 때만 imagefilename을 sql문에 추가
            if (imagefilename != null && imagefilename.length() != 0) {
                sql += ",imagefilename=?";
            }
            sql += "where articleno=?";
 
            pstmt = con.prepareStatement(sql);
            pstmt.setString(1, title);
            pstmt.setString(2, content);
            //이미지 파일을 수정하는 경우와 그렇지 않은 경우를 구분해서 실행
            if (imagefilename != null && imagefilename.length() != 0) {
                pstmt.setString(3, imagefilename);
                pstmt.setInt(4, articleno);
            }else{
                pstmt.setInt(3, articleno);
            }
            pstmt.executeUpdate();
            pstmt.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    //전달된 articleno에 대한 글을 삭제
    public void deleteArticle(int articleno) {
        try{
            con = getConnection();
            //오라클 계층형 sql문을 이용해 삭제 글과 관련된 자식 글까지 모두 삭제
            String sql = "delete from t_board " +
                    "where articleno in (" +
                    "select articleno from t_board " +
                    "start with articleno = ? " +
                    "connect by prior articleno = parentno)";
 
            pstmt = con.prepareStatement(sql);
            pstmt.setInt(1, articleno);
            pstmt.executeUpdate();
            pstmt.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    //삭제할 글에 대한 글 번호를 가져옴
    public List<Integer> selectRemovedArticles(int articleno) {
        List<Integer> articleNoList = new ArrayList<Integer>();
 
        try{
            con = getConnection();
            //삭제한 글들의 articleno를 조회
            String sql = "select articleno from t_board " +
                    "start with articleno = ? " +
                    "connect by prior articleno = parentno";
 
            pstmt = con.prepareStatement(sql);
            pstmt.setInt(1, articleno);
            rs = pstmt.executeQuery();
 
            while (rs.next()) {
                articleno = rs.getInt("articleno");
                articleNoList.add(articleno);
            }
            rs.close();
            pstmt.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return articleNoList;
    }
}
cs

 

서비스

 

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
public class BoardService {
    BoardDAO boardDAO;
 
    public BoardService() {
        //생성자 호출 시 BoardDAO()객체 생성
        boardDAO = new BoardDAO();
    }
 
    public List<ArticleVO> listArticles() {
        List<ArticleVO> articleList = boardDAO.selectAllArticles();
        return articleList;
    }
    
    public int addArticle(ArticleVO article) {
        return boardDAO.insertNewArticle(article);
    }
    
    public ArticleVO viewArticle(int articleno) {
        ArticleVO article = null;
        article = boardDAO.selectArticle(articleno);
        return article;
    }
    
    public void modArticle(ArticleVO article) {
        boardDAO.updateArticle(article);
    }
    
    public List<Integer> removeArticle(int articleno) {
        List<Integer> articleNoList = boardDAO.selectRemovedArticles(articleno);
        boardDAO.deleteArticle(articleno);
        return articleNoList;
    }
}
cs

 

viewArticle.jsp

 

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>  
<%request.setCharacterEncoding("utf-8"); %>      
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>    
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
 
<style type="text/css">
    #tr_btn_modify{
        display:none;
    }
</style>
 
<script  src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
    function readURL(input) {
        if(input.files && input.files[0]){
            var reader = new FileReader();
            reader.onload = function (e) {
                $('#preview').attr('src', e.target.result);
            }
            reader.readAsDataURL(input.files[0]);
        }
    }
    
    function fn_enable(obj) {//수정하기 클릭 시 텍스트 박스 활성화
        //텍스트 박스의 id로 접근해 disabled 속성을 false로 설정
        document.getElementById("i_title").disabled = false;
        document.getElementById("i_content").disabled = false;
        document.getElementById("i_imagefilename").disabled = false;
        document.getElementById("tr_btn_modify").style.display = "block";
        document.getElementById("tr_btn").style.display = "none";
    }
    
    //수정반영하기 클릭 시 컨트롤러에 수정 데이터를 전송
    function fn_modify_article(obj) {
        obj.action = "${contextPath}/board/modArticle.do";
        obj.submit();
    }
    
    function backToList(obj) {
        obj.action = "${contextPath}/board/listArticles.do";
        obj.submit();
    }
    
    function fn_remove_article(url, articleno) {
        //자바스크립트를 이용해 동적으로 <form>태그 생성
        var form = document.createElement("form");
        form.setAttribute("method""post");
        form.setAttribute("action", url);
        
        //자바스크립트를 이용해 동적으로 <input> 태그를 생성한 후 name과 value를 articleno와 글 번호로 설정
        var articleNoInput = document.createElement("input");
        articleNoInput.setAttribute("type""hidden");
        articleNoInput.setAttribute("name""articleno");
        articleNoInput.setAttribute("value", articleno);
        
        form.appendChild(articleNoInput);//동적으로 생성된 <input>을 동적으로 생성한 <form>에 append
        
        //<form> 태그를 <body> 태그에 추가(append)한 후 서버에 요청
        document.body.appendChild(form);
        form.submit();
    }
</script>
</head>
<body>
    <form name="frmArticle" method="post" enctype="multipart/form-data">
        <table>
            <tr>
                <td width="150" align="center">글번호</td>
                <td>
                    <input type="text" value="${article.articleno}" disabled>
                    <!-- 글 수정 시 글 번호를 컨트롤러로 전송하기 위해 미리 hidden 태그를 이용해 글 번호 저장 -->
                    <input type="hidden" value="${article.articleno}" name="articleno">
                </td>
            </tr>
            <tr>
                <td width="150" align="center">작성자 아이디</td>
                <td><input type="text" value="${article.id}" disabled name="id"></td>
            </tr>
            <tr>
                <td width="150" align="center">제목</td>
                <td><input type="text" value="${article.title}" disabled name="title" id="i_title"></td>
            </tr>
            <tr>
                <td width="150" align="center">내용</td>
                <td>
                    <textarea rows="20" cols="60"  name="content"  id="i_content"  disabled />${article.content }</textarea>
                </td>
            </tr>
        <!-- imagefilename 값이 있으면 이미지를 표시 -->
        <!-- 이미지 수정에 대비해 hidden 태그에 원래 이미지 파일 이름을 저장 -->
        <!-- FileDownloadController 서블릿에 이미지 파일 이름과 글 번호를 전송해서 이미지를 img 태그에 표시 -->
        <!-- imagefilename으로 수정된 이미지 파일 이름을 전송 -->
        <c:if test="${not empty article.imagefilename && article.imagefilename != 'null'}">
            <tr>
                <td width="20%" align="center" rowspan="2">이미지</td>
                <td>
                    <input type="hidden" name="originalFileName" value="${article.imagefilename }">
                    <img src="${contextPath}/download.do?imagefilename=${article.imagefilename}&articleno=${article.articleno}" id="preview">
                </td>
            </tr>
            <tr>
                <td>
                    <input type="file" name="imagefilename" id="i_imagefilename" onchange="readURL(this);" disabled>
                </td>
            </tr>
        </c:if>
            <tr>
                <td width="20%" align="center">등록일자</td>
                <td>
                    <input type="text" value='<fmt:formatDate value="${article.writedate}"/>' disabled>
                </td>
            </tr>
            <tr id="tr_btn_modify">
                <td colspan="2" align="center">
                    <input type="button" value="수정반영하기" onclick="fn_modify_article(frmArticle)">
                    <input type="reset" value="취소" onclick="backToList(frmArticle)">
                </td>
            </tr>
            <tr id="tr_btn">
                <td colspan="2" align="center">
                    <input type="button" value="수정하기" onclick="fn_enable(this.form)">
                    <!-- 삭제하기 클릭 시 fn_remove_article() 자바스크립트 함수를 호출하면서 articleno를 전달 -->
                    <input type="button" value="삭제하기" onclick="fn_remove_article('${contextPath}/board/removeArticle.do',${article.articleno})">
                    <input type="button" value="리스트로 돌아가기" onclick="backToList(this.form)">
                    <%-- <input type="button" value="답글쓰기" onclick="fn_reply_form('${contextPath/board/replyForm.do}',${article.articleno})"> --%>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
cs

 

728x90