Repository navigation
Expand file tree
/
Copy pathStudyController.java
More file actions
133 lines (120 loc) · 4.68 KB
/
Copy pathStudyController.java
File metadata and controls
133 lines (120 loc) · 4.68 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
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
package com.Study;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.Study.StudyCommand;
import com.Study.StudyDeleteCommand;
import com.Study.StudyDownloadCommand;
import com.Study.StudyListCommand;
import com.Study.StudyModifyCommand;
import com.Study.StudyViewCommand;
import com.Study.StudyWriteCommand;
/**
* Servlet implementation class StudyController
*/
@WebServlet("*.doStudy")
public class StudyController extends HttpServlet {
StudyCommand command = null;
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public StudyController() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("doGet");
doAction(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("doPost");
doAction(request, response);
}
private synchronized void setCommand(StudyCommand command) {
this.command = command;
}
private synchronized void doAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("do PostController");
HttpSession session = request.getSession();
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
String title = null;
String viewPage = null;
String boardId = null;
String requestUri = request.getRequestURI();
String contextPath = request.getContextPath();
String commandName = null;
viewPage = requestUri;
commandName = viewPage.substring(contextPath.length());
title = (String) session.getAttribute("title");
try {
if(commandName.equals("/study_write.doStudy")) {
viewPage = "/semtle/Study/study_board_text.jsp";
boardId = (String) request.getAttribute("boardId");
}else if(commandName.equals("/study_text.doStudy")) {
viewPage = "/semtle/Study/study.jsp";
boardId = (String) request.getAttribute("boardId");
setCommand(new StudyWriteCommand());
command.execute(request, response);
}else if(commandName.equals("/study_view.doStudy")) {
viewPage = "/semtle/Study/study_board_room.jsp";
setCommand(new StudyViewCommand());
command.execute(request, response);
}else if(commandName.equals("/study_download.doStudy")) {
setCommand(new StudyDownloadCommand());
int postId = command.execute(request, response);
viewPage = "study_view.doStudy?postId="+postId;
}else if(commandName.equals("/study_setting.doStudy")) {
viewPage = "/semtle/Study/study_setting.jsp";
setCommand(new StudyViewCommand());
command.execute(request, response);
}else if(commandName.equals("/study_update.doStudy")) {
setCommand(new StudyModifyCommand());
command.execute(request, response);
viewPage = "/semtle/Study/study.jsp";
}else if(commandName.equals("/study_delete.doStudy")) {
viewPage = "/semtle/Study/study.jsp";
setCommand(new StudyDeleteCommand());
command.execute(request, response);
}else if(commandName.equals("/board_list_Study.doStudy")) {
viewPage = "/semtle/Study/study_board.jsp";
title = request.getParameter("title");
boardId = title;
session.setAttribute("title", title);
session.setAttribute("boardId", boardId);
setCommand(new StudyListCommand());
command.execute(request, response);
} else if(commandName.equals("/Study.doStudy")) {
viewPage = "/semtle/Study/study.jsp";
title = "스터디룸";
session.setAttribute("title", title);
}else if(commandName.equals("/study_room.doStudy")) {
viewPage = "/semtle/Study/study_board_room.jsp";
}else {
System.out.println("해당 Command가 없습니다.");
viewPage = "notCommand.jsp";
}
System.out.println("commandName : " + commandName);
System.out.println("boardId = " + boardId);
RequestDispatcher dispatcher = request.getRequestDispatcher(viewPage);
dispatcher.forward(request, response);
}catch(IllegalStateException e) {
System.out.println("Illegal");
}
}
}