summaryrefslogtreecommitdiff
path: root/app/v2_java/src/org/usi2011/User.java
blob: 091b4ebc45ae349cd9bbc59ca4ed441b8075951d (plain)
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
package org.usi2011;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class User
 */
public class User extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Connection connection;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public User() {
        super();
        connection = Database.getConnection();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			String firstname = request.getParameter("firstname");
			String lastname = request.getParameter("lastname");
			String mail = request.getParameter("mail");
			String password = request.getParameter("password");
			
			System.out.println(firstname);
			System.out.println(lastname);
			System.out.println(mail);
			System.out.println(password);
			
			String query = "INSERT INTO game(firstname, lastname, mail) VALUES ('"+firstname+"', '"+lastname+"', '"+mail+"', '"+password+"')";
			Statement statement = connection.createStatement();
			ResultSet resultset = statement.executeQuery(query);
			
			response.setStatus(response.SC_CREATED);
			
		} catch (SQLException e) {
			System.out.println(e.getMessage());
			response.sendError(400);
		}
	}

}