Exemplo n.º 1
0
 /**
  * 查看我的数据服务
  *
  * @param request
  * @param response
  * @throws SQLException
  * @throws IOException
  * @throws ServletException
  */
 private void viewmyapps(HttpServletRequest request, HttpServletResponse response) {
   String username = null;
   HttpSession session = request.getSession();
   if (session.getAttribute("username") != null) {
     username = session.getAttribute("username").toString();
   } else if (session.getAttribute("adminname") != null) {
     username = session.getAttribute("adminname").toString();
   }
   APIService apiService = new APIService();
   List<MyApp> myapps;
   try {
     myapps = apiService.queryAll(username);
     for (MyApp app : myapps) {
       // 根据myapp表中的appid得到appname并将他保存在myapp中的appname属性当中
       Apps appModel = new AppService().getById(Integer.toString(app.getAppid()));
       app.setAppname(appModel.getName());
       // System.out.println(app.getDtname());
     }
     try {
       request.getSession().setAttribute("myapps", myapps);
       // request.getRequestDispatcher("/index/core/ucenter.jsp").forward(request, response);
       response.sendRedirect("index/core/ucenter.jsp");
     } catch (IOException e) {
       e.printStackTrace();
     }
   } catch (SQLException e1) {
     e1.printStackTrace();
   }
 }
Exemplo n.º 2
0
  /**
   * 管理员查看每个APP的调用情况
   *
   * @param request
   * @param response
   */
  private void listapps(HttpServletRequest request, HttpServletResponse response) {

    APIService apiService = new APIService();
    List<MyApp> listapps;
    try {
      listapps = apiService.listapps();
      for (MyApp app : listapps) {
        Apps apps = new AppService().getById(Integer.toString(app.getAppid()));
        app.setAppname(apps.getName());
      }
      try {
        request.getSession().setAttribute("listapps", listapps);
        response.sendRedirect("index/core/amanage_dataservices.jsp");
      } catch (IOException e) {

        e.printStackTrace();
      }
    } catch (SQLException e1) {

      e1.printStackTrace();
    }
  }
Exemplo n.º 3
0
  /**
   * 申请APPKEY
   *
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  private void addapi(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // id,usernmae,dtname,appkey,startime,endtime,times
    // 1.准备数据:得到用户传过来的username和dtname,生成aapkey
    String dtname = request.getParameter("dtname");
    String appid = request.getParameter("appid");
    String username = null;
    HttpSession session = request.getSession();
    if (session.getAttribute("username") != null) {
      username = session.getAttribute("username").toString();
    } else if (session.getAttribute("adminname") != null) {
      username = session.getAttribute("adminname").toString();
    }
    String finaluuid = UUID.randomUUID().toString();
    String appkey =
        finaluuid.substring(0, 8)
            + finaluuid.substring(9, 13)
            + finaluuid.substring(14, 18)
            + finaluuid.substring(19, 23)
            + finaluuid.substring(24);
    // 2.将准备好的数据插入到数据库中
    APIService apiService = new APIService();
    try {
      // 插入之前先查看该用户是否已经申请了该数据服务,先根据用户名查出该用户的所有数据服务
      List<MyApp> listmyapps = apiService.queryAll(username);
      for (MyApp myapp : listmyapps) {
        if (dtname.equals(myapp.getDtname())) // 如果存在该数据服务,则返回
        {
          request.setAttribute("message", "您已经申请了该数据服务,不能申请同样的数据服务!错误代码:10011");
          request.getRequestDispatcher("/index/core/message.jsp").forward(request, response);
          return;
        }
      }

      boolean flag = apiService.add(dtname, username, appkey, appid);
      if (flag) // 插入成功
      {
        request.setAttribute("message", "你申请的APPKey为" + appkey);
        // 如果插入成功,则将该用户的所有的appkey查询出来
        List<MyApp> myapps = apiService.queryAll(username);
        if (myapps != null) {
          for (MyApp app : myapps) {
            // 根据myapp表中的appid得到appname并将他保存在myapp中的appname属性当中
            Apps appModel = new AppService().getById(Integer.toString(app.getAppid()));
            app.setAppname(appModel.getName());
          }
        }

        // System.out.println(myapps);
        request.setAttribute("myapps", myapps);
        request.getRequestDispatcher("/index/core/ucenter.jsp").forward(request, response);
      } else {
        request.setAttribute("message", "申请数据失败!");
        request.getRequestDispatcher("/index/core/message.jsp").forward(request, response);
      }
    } catch (SQLException e) {

      e.printStackTrace();
    }
    // 3.成功之后将页面跳转到用户API界面,否则跳转到失败界面

  }