-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionController.java
More file actions
51 lines (44 loc) · 1.56 KB
/
QuestionController.java
File metadata and controls
51 lines (44 loc) · 1.56 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
package mvc.controllers;
import java.io.IOException;
import java.sql.SQLException;
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 mvc.models.QuestionsViewModel;
@WebServlet("/Questions")
public class QuestionController extends HttpServlet {
private static final long serialVersionUID = 1L;
public QuestionController() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher rd = null;
//make model that connects to the database/gets data
QuestionsViewModel result;
try {
result = new QuestionsViewModel();
rd = request.getRequestDispatcher("/view/questionview.jsp");
request.setAttribute("viewModel", result);
rd.forward(request, response);
}
catch (SQLException e) {
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String theQuestion = request.getParameter("theQuestion");
//make model that adds the new question, then get the data
QuestionsViewModel adder;
try{
adder = new QuestionsViewModel();
adder.add(theQuestion);
}
catch(SQLException e){
e.printStackTrace();
}
this.doGet(request, response);
}
}