@Override
	protected void doPost(final Request request) throws ServletException,
			IOException, SQLException, IllegalArgumentException,
			IllegalAccessException {
		if (!request.getSession().isLoggedIn())
			throw new LoginRequiredException("Not logged in");

		// Process request, depending on action
		final String action = request.getParameter("action");
		if (action.equalsIgnoreCase("change")) {
			// Change row count. Nothing else changes
			initPage(request);
			printCreateForm(request);
			return;
		} else if (action.equalsIgnoreCase("create")) {
			// Request to create new table
			initPage(request);
			final PrintWriter writer = request.getWriter();
			writer.println("<p>Creating table ... <br>");

			final String tableName = request.getParameter("tablename");

			if (tableName == null || tableName.isEmpty()) {
				writer.println("<b>Tablename not given</b></p>");
				printCreateForm(request);
				return;
			} else if (Persistence.getTable(tableName) != null) {
				writer.println("<b>Table exists already!</b></p>");
				printCreateForm(request);
				return;
			} else {

				final int maxRows = request.getParameterInt("maxRows");
				final List<TableRow> rows = new LinkedList<>();
				for (int i = 0; i < maxRows; i++) {
					final String id = Integer.toString(i);
					final String rowname = request.getParameter("name" + id);
					String type = request.getParameter("type" + id);
					final boolean primary = request
							.getParameter("primary" + id).equalsIgnoreCase(
									"true");
					final boolean index = request.getParameter("index" + id)
							.equalsIgnoreCase("true");

					if (type.isEmpty())
						type = "TEXT";

					if (rowname.length() > 0)
						rows.add(new TableRow(rowname, type, primary, index));
				}

				Persistence.insertTable(tableName, rows, request.getSession()
						.getUsername());

				writer.println("Table created</p>");
				writer.println("<p> <a href=\"Token?create=1&table="
						+ tableName + "\">[Create token]</a></p>");
			}
		}
	}