-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController
More file actions
34 lines (27 loc) · 1.38 KB
/
Controller
File metadata and controls
34 lines (27 loc) · 1.38 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
package by.autoServiceStation.controller;
import by.autoServiceStation.navigation.Command;
import by.autoServiceStation.navigation.CommandFactory;
import static by.autoServiceStation.resources.constants.Constants.PARAM_COMMAND;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class Controller extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
performAction(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
performAction(request, response);
}
private void performAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String currentCommand = request.getParameter(PARAM_COMMAND);
Command command = CommandFactory.getCommand(currentCommand.toUpperCase());
String nextPage = command.execute(request, response);
if (!response.isCommitted()) {
RequestDispatcher requestDispatcher = request.getRequestDispatcher(nextPage);
requestDispatcher.forward(request, response);
}
}
}