@Override
	protected void doGet(Request request) throws ServletException, IOException,
			SQLException, IllegalArgumentException, IllegalAccessException {
		if (!request.getSession().isLoggedIn())
			throw new LoginRequiredException();

		request.printHeader();
		final PrintWriter writer = request.getWriter();
		writer.println("<h1>Datacube</h1>");
		request.printNavigationBar();
		try {
			writer.println("<h2>Token</h2>");
			printToolbar(writer);

			if (request.hasParameter("id")) {
				final int id = request.getParameterInt("id");
				final List<core.Token> tokens = Persistence
						.getUserTokens(request.getSession().getUsername());
				core.Token token = null;
				{
					int i = 0;
					for (final core.Token t : tokens) {
						if (i++ == id) {
							token = t;
							break;
						}

					}
				}
				if (token == null) {
					writer.println("<p></b>Token not found</b></p>");
					return;
				} else {
					final html.Table table = new html.Table();
					table.setBorderWidth(1);
					table.addRow().put("<b>Token</b>").put("<b>Table</b>");
					table.addRow()
							.put(new html.TextField("", token.getToken(), true))
							.put("<a href=\"Tables?table="
									+ token.getTablename() + "\">"
									+ token.getTablename() + "</a>");
					table.println(writer);

					writer.println("<p><a href=\"Token?delete="
							+ token.getToken() + "\">[Delete token]</a></p>");
				}

			} else if (request.hasParameter("create")) {
				final List<core.Table> userTables = Persistence
						.getUserTables(request.getSession().getUsername());

				final html.Form form = new html.Form("Token", "POST");
				form.addComponent(new html.HiddenInput("create", "1"));
				final html.Table table = new html.Table();
				final String token = newRandomToken(request.getParameterInt(
						"size", 128));
				form.addComponent(table);
				table.addRow().put("<b>Token</b>")
						.put(new html.TextField("token", token));

				final List<html.ListOption> userTablesOptions = new LinkedList<>();
				for (final core.Table tbl : userTables)
					userTablesOptions.add(new ListOption(tbl.getTablename(),
							tbl.getTablename()));
				table.addRow().put("<b>Table</b>")
						.put(new html.DropdownList("table", userTablesOptions));
				form.addComponent(new html.SubmitButton("Create"));
				form.println(writer);
			} else if (request.hasParameter("delete")) {
				Persistence.deleteToken(request.getParameter("delete"));
				printTokenList(request);
			} else {
				printTokenList(request);
			}
		} finally {
			writer.flush();
			writer.close();
		}
	}