1 | package jquery.datatables.controller;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import javax.servlet.ServletException;
|
---|
5 | import javax.servlet.annotation.WebServlet;
|
---|
6 | import javax.servlet.http.HttpServlet;
|
---|
7 | import javax.servlet.http.HttpServletRequest;
|
---|
8 | import javax.servlet.http.HttpServletResponse;
|
---|
9 |
|
---|
10 | import jquery.datatables.model.Company;
|
---|
11 | import jquery.datatables.model.DataRepository;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Handling adding new data
|
---|
15 | */
|
---|
16 | @WebServlet("/AddData")
|
---|
17 | public class AddData extends HttpServlet {
|
---|
18 | private static final long serialVersionUID = 1L;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * @see HttpServlet#HttpServlet()
|
---|
22 | */
|
---|
23 | public AddData() {
|
---|
24 | super();
|
---|
25 | // TODO Auto-generated constructor stub
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
---|
30 | */
|
---|
31 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
---|
32 |
|
---|
33 | String name = request.getParameter("name");
|
---|
34 | String address = request.getParameter("address");
|
---|
35 | String town = request.getParameter("town");
|
---|
36 | int country = Integer.parseInt(request.getParameter("country"));
|
---|
37 |
|
---|
38 | Company c = new Company(name, address, town, country);
|
---|
39 | DataRepository.GetCompanies().add(c);
|
---|
40 |
|
---|
41 | response.getWriter().print(c.getId());
|
---|
42 | }
|
---|
43 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
---|
44 | doPost(request, response);
|
---|
45 | }
|
---|
46 | }
|
---|