// sign up
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String login = request.getParameter("login");
    String pass = request.getParameter("password");

    try {
      long userId = dbService.addUser(login, pass);
    } catch (DBException e) {
      e.printStackTrace();
    }
  }
  public static void main(String[] args) throws Exception {
    DBService dbService = new DBService();
    dbService.printConnectInfo();

    try {
      long userId = dbService.addUser("tully", "querty");
      System.out.println("Added user id: " + userId);

      UsersDataSet dataSet = dbService.getUser(userId);
      System.out.println("User data set: " + dataSet);

    } catch (DBException e) {
      e.printStackTrace();
    }

    createServlets(dbService);
  }
Example #3
0
  // sign up
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // todo: module 2 home work
    String login = request.getParameter("login");
    String pass = request.getParameter("password");
    if (login == null || pass == null) {
      response.setContentType("text/html;charset=utf-8");
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    try {
      service.addUser(login, pass);
    } catch (DBException e) {
      e.printStackTrace();
    }
  }
Example #4
0
  public static void main(String[] args) {
    DBService dbService = new DBService();
    dbService.printConnectInfo();
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    //        context.setContextPath("/");
    //        context.addServlet(new ServletHolder(new MainServlet()), "/");
    context.addServlet(new ServletHolder(new SignUpServlet(dbService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(dbService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("./public_html");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {resource_handler, context});

    Server server = new Server(8080);
    server.setHandler(handlers);

    try {
      long userId = dbService.addUser("test1", "test1");
      System.out.println("Added user id: " + userId);

      UsersDataSet dataSet = dbService.getUser(userId);
      System.out.println("User data set: " + dataSet);

      //            dbService.cleanUp();
    } catch (DBException e) {
      e.printStackTrace();
    }
    try {
      server.start();
      System.out.println("Server started");
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }