Repository navigation
Expand file tree
/
Copy pathStudyListCommand.java
More file actions
84 lines (65 loc) · 2.42 KB
/
Copy pathStudyListCommand.java
File metadata and controls
84 lines (65 loc) · 2.42 KB
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
package com.Study;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.Post.postDAO;
import com.Post.postDTO;
public class StudyListCommand implements StudyCommand{
@Override
public int execute(HttpServletRequest request, HttpServletResponse response) throws IOException {
// TODO Auto-generated method stub
//Paging
String cpStr = request.getParameter("cpage");
String psStr = request.getParameter("pageSize");
if(cpStr == null || cpStr.trim().isEmpty())
cpStr = "1";
HttpSession session = request.getSession();
if(psStr == null || psStr.trim().isEmpty()) {
psStr = (String) session.getAttribute("pageSize");
if(psStr == null)
psStr = "5";
}
session.setAttribute("pageSize", psStr);
int cpage = Integer.parseInt(cpStr);
int pageSize = 5;
if(psStr != null)
pageSize = Integer.parseInt(psStr);
String title = (String) session.getAttribute("title");
System.out.println("title = " + title);
String boardId = (String) session.getAttribute("boardId");
int post_count = 0;
postDAO dao = postDAO.getInstance();
List<postDTO> lists = null;
post_count = dao.getPostCount(boardId);
int pageCount = (post_count - 1)/pageSize + 1;
if(cpage < 1)
cpage = 1;
else if (cpage > pageCount)
cpage = pageCount;
int end = pageSize*cpage;
int start = end-pageSize + 1;
System.out.println("start = " + start);
System.out.println("end = " + end);
lists = dao.getPosts(boardId, start, end);
int pagingBlock = 5;
int prevBlock = 0, nextBlock = 1;
prevBlock = (cpage-1)/pagingBlock * pagingBlock;
nextBlock = prevBlock + pagingBlock + 1;
request.setAttribute("cpage", cpage);
request.setAttribute("pageCount", pageCount);
request.setAttribute("pagingBlock", pagingBlock);
request.setAttribute("prevBlock", prevBlock);
request.setAttribute("nextBlock", nextBlock);
System.out.println("cpage = " + cpage);
System.out.println("pageCount = " + pageCount);
System.out.println("pagingBlock = " + pagingBlock);
System.out.println("prevBlock = " + prevBlock);
System.out.println("nextBlock = " + nextBlock);
request.setAttribute("list", lists);
request.setAttribute("post_count", post_count);
request.setAttribute("title", title);
return 1;
}
}