/**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   * @throws java.lang.ClassNotFoundException
   * @throws java.sql.SQLException
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException, ClassNotFoundException, SQLException,
          CloneNotSupportedException {
    response.setContentType("text/html;charset=UTF-8");
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    try (PrintWriter out = response.getWriter()) {
      /* TODO output your page here. You may use following sample code. */
      out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">");
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet CheckLogin</title>");
      out.println("</head>");
      out.println("<body>");
      boolean kt = false;
      String username = request.getParameter("username");
      String password = request.getParameter("password");
      String action = request.getParameter("btAction");
      HttpSession session = request.getSession();
      ArrayList arr = new ArrayList();
      DataServices mydb = new DataServices();
      if (action.equals("Login")) {
        kt = mydb.checkUser(username, password);
        if (kt) {
          String sSql = "select staffName from tbl_staff where staffID='" + username + "'";
          ResultSet rs = mydb.executeQuery(sSql);
          while (rs.next()) {
            session.setAttribute("name", rs.getString("staffName"));
            session.setAttribute("username", username);
          }

          arr = mydb.quyen(username);
          session.setAttribute("quyen", arr);
          RequestDispatcher dispatcher = request.getRequestDispatcher("/JSP/index.jsp");
          dispatcher.forward(request, response);
        } else {
          RequestDispatcher dispatcher = request.getRequestDispatcher("/JSP/login.jsp");
          dispatcher.forward(request, response);
        }
      }
      mydb.closeDB();
      out.println("</body>");
      out.println("</html>");
    }
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/html; charset=UTF-8");
  }
Exemple #2
0
 /**
  * The doPost method of the servlet. <br>
  * This method is called when a form has its tag value method equals to post.
  *
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
 public void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   request.setCharacterEncoding("utf-8");
   response.setCharacterEncoding("utf-8");
   // 读取参数
   String search = request.getParameter("search"); // 查询内容
   String key = request.getParameter("searchkey"); // 查询条件
   boolean k = false; // 判断查询方式
   if (key.equals("issue")) {
     k = true; // 按颁发部门查询
   } else {
     k = false; // 按关键字查询
   }
   // 访问数据库
   // LawsSearch laws = new LawsSearch();
   ILawsDao dao = DaoFactory.createLawsDao();
   JSONArray json = new JSONArray();
   ResultSet rs = dao.searchLaws(search, k);
   json = ToJson.resultJSON(rs);
   // 应答
   response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   out.print(json.toString());
   out.flush();
   out.close();
 }
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");
    String first_name = request.getParameter("firstName");
    String last_name = request.getParameter("lastName");
    String email = request.getParameter("email");
    String addrid = request.getParameter("addr");

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date = df.format(new Date());
    String sql =
        "INSERT INTO customer(first_name,last_name,email,address_id,store_id,create_date) VALUES('"
            + first_name
            + "','"
            + last_name
            + "','"
            + email
            + "',"
            + addrid
            + ",1,'"
            + date
            + "')"; // 日期自动添加
    // TODO Auto-generated method stub
    int i = DbOperater.DML(sql);
    response.getWriter().print("<script>alert('success')</script>");
    response.sendRedirect("index.jsp");
  }
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    System.out.println("Tree---------------请求到来!");
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");

    // 获取单击的节点id
    String node = request.getParameter("node");
    System.out.println("获取的节点ID: " + node);
    String json = "";

    if ("0".equals(node)) { // 全部分组
      json +=
          "[{id:'1', checked: false, text: '我的好友'}, {id:'2', checked: false, text: '我的同学'},{id:'3', checked: false, text: '陌生人', leaf: true}]";
    } else if ("1".equals(node)) {
      json +=
          "[{id:'11', checked: false, text: '张三', leaf: true}, {id:'12', checked: false, text: '李四', leaf: true}, {id:'13', checked: false, text: '王五', leaf: true}]";
    } else if ("2".equals(node)) {
      json +=
          "[{id:'21', checked: false, text: '刘备', leaf: true}, {id:'22', checked: false, text: '曹操', leaf: true}, {id:'23', checked: false, text: '孙尚香', leaf: true}]";
    }

    System.out.println("返回数据: " + json);
    response.getWriter().write(json);
    System.out.println("Tree---------------请求结束!");
  }
  /**
   * The doGet method of the servlet. <br>
   * This method is called when a form has its tag value method equals to get.
   *
   * @param request the request send by the client to the server
   * @param response the response send by the server to the client
   * @throws ServletException if an error occurred
   * @throws IOException if an error occurred
   */
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    //		设置接收信息的字符集
    request.setCharacterEncoding("UTF-8");
    // 接收浏览器端提交的信息
    String textfield = codeToString(request.getParameter("textfield"));
    // 设置输出信息的格式及字符集
    response.setContentType("text/xml; charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");
    // 创建输出流对象
    PrintWriter out = response.getWriter();
    // 依据验证结果输出不同的数据信息
    // 连接数据库,判断新建文件名是否存在, 删除是否成功
    // 查询数据库看删除条件是否符合,其下是否有文件,有不能删除。
    // if(success)//删除成功
    // {
    //	out.print("success");
    // }
    // else if(hasFile)//其下有文件不能删除
    // {
    //	out.print("isFther");
    // }
    // else//数据库或系统错误,数据没能正常删除
    // {
    //    out.print("error");
    // }
    out.print("success");
    out.flush();
    out.close();
  }
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");

    String login = request.getParameter("login");
    String email = request.getParameter("email");
    String approuve = request.getParameter("approuve"); // "on" si cochée sinon ""

    if (checkMail(email) && checkLogin(login) && checkApprouve(approuve)) {
      request.getRequestDispatcher("adhesionOkServlet").forward(request, response);
    } else {
      // Renvoyer les paramètres pour les réafficher
      request.setAttribute("login", login);
      request.setAttribute("email", email);
      request.setAttribute("approuve", approuve);

      // gestion du message d'erreur
      if (!checkLogin(login))
        request.setAttribute("wrongLogin", "Login trop court (5 caractères min)");
      if (!checkMail(email)) request.setAttribute("wrongEmail", "Email non conforme");
      if (!checkApprouve(approuve))
        request.setAttribute("wrongApprouve", "Veuillez cocher les conditions générale svp");

      request.getRequestDispatcher("/adhesion.jsp").forward(request, response);
    }
  }
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   request.setCharacterEncoding("UTF-8");
   String action = request.getParameter("action");
   if ("login".equals(action)) {
     Login(request, response);
   } else if ("updatePass".equals(action)) {
     updatePass(request, response);
   } else if ("exit".equals(action)) {
     Exit(request, response);
   } else if ("findName".equals(action)) {
     findName(request, response);
   } else if ("insert".equals(action)) {
     insert(request, response);
   } else if ("list".equals(action)) {
     List(request, response);
   } else if ("delete".equals(action)) {
     Delete(request, response);
   } else if ("blackName".equals(action)) {
     blackName(request, response);
   } else if ("recover".equals(action)) {
     Recover(request, response);
   } else if ("userList".equals(action)) {
     userList(request, response);
   } else if ("deleteUser".equals(action)) {
     deleteUser(request, response);
   } else if ("userBlackName".equals(action)) {
     userBlackName(request, response);
   } else if ("recoverUser".equals(action)) {
     recoverUser(request, response);
   }
 }
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    req.setCharacterEncoding("UTF-8"); // $NON-NLS-1$
    // Set standard HTTP/1.1 no-cache headers.
    resp.setHeader(
        "Cache-Control", //$NON-NLS-1$
        "no-store, no-cache, must-revalidate"); //$NON-NLS-1$

    String response = processRequest(req, resp);
    if ("".equals(response)) { // $NON-NLS-1$
      resp.sendError(400); // bad request; missing parameter
      return;
    }

    String returnType = req.getParameter(Utils.RETURN_TYPE);
    boolean boolIsJSON = (returnType != null && returnType.equalsIgnoreCase(Utils.JSON));

    // If JSON output is required
    if (boolIsJSON) {
      resp.setContentType("text/plain"); // $NON-NLS-1$
      response = getJSONResponse(response);
    }

    resp.getWriter().write(response);
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    request.setCharacterEncoding("UTF-8");

    HttpSession session = request.getSession();
    String subject = request.getParameter("subject");
    String course = new String(request.getParameter("course").getBytes("iso-8859-1"), "utf-8");
    course = "(" + course + ")";
    Studentinfo studentinfo = (Studentinfo) session.getAttribute("user");
    subject = course + studentinfo.getName() + ":" + subject;

    String content = request.getParameter("content");
    String emailAddr = "\n\n\n 发信者邮箱地址:" + studentinfo.getEmail();
    content = content + emailAddr;

    String t_id = request.getParameter("to");
    TeacherinfoDAO teacherinfoDAO = new TeacherinfoDAO();
    Teacherinfo teacherinfo = teacherinfoDAO.findById(t_id);
    String to = teacherinfo.getEmail();

    SendMailServlet sendMailServlet = new SendMailServlet();
    if (!sendMailServlet.sendMail(to, subject, content)) {
      request.getRequestDispatcher("EmailFailure.html").forward(request, response);
    } else {
      request.getRequestDispatcher("EmailSuccess.html").forward(request, response);
    }
  }
Exemple #10
0
  /**
   * Parse the case id from the url and then delete it. Finally redirects the response and the
   * request to admCase.jsp
   *
   * @see DatabaseMethods#caseDelete(int)
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub

    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    DatabaseMethods dbPoint = new DatabaseMethods();
    HttpSession userSession = request.getSession();

    if (Integer.parseInt(userSession.getAttribute("isadmin").toString()) == 1) {
      int caseId = Integer.parseInt(request.getParameter("caseId"));

      int success = dbPoint.caseDelete(caseId);

      if (success != 0) {
        userSession.setAttribute("caseDelete", "1");
      } else {
        userSession.setAttribute("caseDelete", "0");
      }
    }
    RequestDispatcher rd = getServletContext().getRequestDispatcher("/admCase.jsp");
    if (rd != null) {
      rd.forward(request, response);
    }
  }
Exemple #11
0
  protected void execute(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter out = response.getWriter();
    request.setCharacterEncoding("utf-8");
    String page = request.getParameter("page");
    EmpDAO dao = new EmpDAO();
    if (page != null) {
      int p = Integer.parseInt(page);
      List<Emp> empList = dao.findAll(p);
      JSONObject jobj = new JSONObject();
      jobj.put("ret", 0);
      jobj.put("msg", "ok");
      jobj.put("list", empList);
      out.print(jobj);
    } else {
      List<Emp> empList = dao.findAll();
      // 相应JSON的格式:{ret:xxxx,msg:xxxxx,......}
      // JSONArray arr = JSONArray.fromCollection(empList);
      JSONObject jobj = new JSONObject();
      jobj.put("ret", 0);
      jobj.put("msg", "ok");
      jobj.put("list", empList);
      out.print(jobj);
    }

    //        for (Emp emp : empList) {
    //            out.print(emp.toString()+"<br />");
    //        }
  }
  public void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String dossier_prive = "/WEB-INF/";
    request.setCharacterEncoding("UTF-8");
    String param_vue = (String) request.getParameter("vue");
    String param_action = (String) request.getParameter("action");
    if (!StringUtils.estVide(param_vue)) {
      vue = dossier_prive + param_vue;
    }
    if (!StringUtils.estVide(param_action)) {
      Action classeAction = actions.get(param_action);
      String reponse_action = classeAction.execute(request);
      if (reponse_action.contains(".jsp")) {
        vue = dossier_prive + reponse_action;
      } else {
        vue = reponse_action;
      }
    }

    if (vue != null) {
      RequestDispatcher rd = request.getRequestDispatcher(vue);
      rd.forward(request, response);
    }
  }
  @SuppressWarnings("unused")
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    req.setCharacterEncoding("utf-8");
    resp.setCharacterEncoding("utf-8");
    int i;
    String result = null;
    try {
      GoodsSportGoodsService gws = new GoodsSportGoodsServiceImpl();
      List<GoodsSportGoods> goodsSportGoodsList = new ArrayList<GoodsSportGoods>();
      if (goodsSportGoodsList != null) {
        i = 1;
        result = "{\"state\":\"i\",\"sportGoodsList\":" + goodsSportGoodsList + "}";
      } else {
        result = "{\"state\":\"0\",\"sportGoodsList\":" + goodsSportGoodsList + "}";
      }

    } catch (Exception e) {
      result = "{\"state\":\"-1\"}";
    }

    //   		JSONArray json = new JSONArray(result);
    //
    //   		Writer writer = resp.getWriter();
    //   		writer.write(result);
    //   		writer.close();
  }
 @Override
 protected void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   request.setCharacterEncoding("utf-8");
   response.setCharacterEncoding("utf-8");
   request.getRequestDispatcher("/user/individual.jsp").forward(request, response);
 }
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   response.setCharacterEncoding("UTF-8");
   request.setCharacterEncoding("UTF-8");
   response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   String teacherId = request.getParameter("teacherId");
   String userId = request.getParameter("userId");
   if (StringUtil.isInteger(userId)) {
     int uId = Integer.parseInt(userId);
     if (StringUtil.isInteger(teacherId)) {
       int tId = Integer.parseInt(teacherId);
       querryIsAttention(uId, tId);
       if (attention == null) {
         result = JsonUtil.getRetMsg(3, "您还没关注");
       } else {
         result = JsonUtil.getRetMsg(0, "已经关注");
       }
     } else {
       result = JsonUtil.getRetMsg(1, "讲师id数字格式化异常");
     }
   } else {
     result = JsonUtil.getRetMsg(2, "您还没登陆");
   }
   out.print(result);
   out.flush();
   out.close();
 }
Exemple #16
0
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    res.setContentType("text/html;charset=utf-8");
    req.setCharacterEncoding("utf-8");
    Pubclient ps = (Pubclient) req.getSession().getAttribute("pubclient");
    // 得到用户请求的URI
    String request_uri = req.getRequestURI();
    // 得到web应用程序的上下文路径
    String ctxPath = req.getContextPath();
    // 去除上下文路径,得到剩余部分的路径
    String uri = request_uri.substring(ctxPath.length());
    //
    //	if(ps!=null||uri.startsWith("/login")||uri.startsWith("/skin")||uri.startsWith("/js")||uri.endsWith("/")){
    if (ps == null) {
      System.out.println("会话失效:" + uri);
      String inval = "会话失效请重新登录";
      req.setAttribute("loginFail", inval);
      request.getRequestDispatcher("/login.jsp").forward(request, response);
      return;

    } else {
      System.out.println("通过:" + uri);
      chain.doFilter(request, response);
    }
  }
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    req.setCharacterEncoding("UTF-8");

    searchContent = req.getParameter("searchContent");

    System.out.println("search content: " + searchContent);

    if (searchContent.trim().equals("")) {
      req.getRequestDispatcher("/search.jsp").forward(req, resp);
    }

    // queryStr = "教育部重点实验室评估";

    queryService = new QueryService(searchContent);

    try {
      resultList = queryService.excuteQuery();
      req.setAttribute("resultList", resultList);
      req.setAttribute("searchContent", searchContent);
      req.getRequestDispatcher("/search.jsp").forward(req, resp);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public void doPost(HttpServletRequest request, HttpServletResponse response) {
   try {
     request.setCharacterEncoding("UTF-8");
   } catch (UnsupportedEncodingException e1) {
     e1.printStackTrace();
   }
   Usuario user = usuarioDAO.localiza(request.getParameter("user"));
   if (user != null) {
     request.setAttribute("user", user);
     String caminho = "perfil.jsp";
     if (request.getParameter("page") != null) {
       caminho = "perfilGrupo.jsp";
     }
     try {
       Usuario usuario = ((Usuario) request.getSession().getAttribute("user"));
       usuario.setRelacionamentos(
           relacionamentoDao.localizarPorParametros(
               usuario.getEmail(), usuario.getEmail(), null, true, true));
       request.getSession().setAttribute("user", usuario);
       Relacionamento relacionamentoPendente =
           relacionamentoDao.localiza(usuario.getEmail(), user.getEmail());
       if (relacionamentoPendente != null) {
         request.setAttribute("relacionamentoPendente", true);
       } else {
         request.setAttribute("relacionamentoPendente", false);
       }
       getServletContext().getRequestDispatcher("/" + caminho).forward(request, response);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
  /**
   * 导出excel
   *
   * @throws IOException
   */
  public String OutputExcel() throws IOException {
    // excel表格名字
    String filedisplay = "未匹配的产品清单.xls";
    // excel标题
    String title = "POI测试";
    filedisplay = URLEncoder.encode(filedisplay, "UTF-8");

    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/x-download");
    response.addHeader("Content-Disposition", "attachment;filename=" + filedisplay);

    ExportExcel<Student> ex = new ExportExcel<Student>();
    String[] headers = {"学号", "姓名", "年龄", "性别", "出生日期"};
    List<Student> dataset = new ArrayList<Student>();
    dataset.add(new Student(10000001, "张三", 20, "男", new Date()));
    dataset.add(new Student(20000002, "李四", 24, "女", new Date()));
    dataset.add(new Student(30000003, "王五", 22, "女", new Date()));

    // OutputStream out = new FileOutputStream("d://a.xls");
    OutputStream out = response.getOutputStream();
    ex.exportExcel(title, headers, dataset, out);
    out.close();
    // JOptionPane.showMessageDialog(null, "导出成功!");
    return null;
  }
Exemple #20
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    if (request.getCharacterEncoding() == null) request.setCharacterEncoding("UTF-8");
    response.setContentType("application/json;charset=UTF-8");
    response.setCharacterEncoding("UTF-8");

    JSONObject ret = new JSONObject();

    PrintWriter out = response.getWriter();
    Enumeration<String> enumTest = request.getParameterNames();
    HashMap<String, Object> requestMap = new HashMap<String, Object>();
    while (enumTest.hasMoreElements()) {
      String tmp = enumTest.nextElement().toString();
      requestMap.put(tmp, request.getParameter(tmp));
    }
    try {
      Kayttaja kayttaja =
          new Kayttaja(SecurityContextHolder.getContext().getAuthentication().getName());
      int orgId = Integer.parseInt(requestMap.get("org_id").toString());
      String lang = requestMap.get("lang").toString();
      if (lang == null || lang == "") lang = "fi";

      org = new Organisation(lang);
      MapData md = new MapData(lang);
      ret = md.getExtentByType(MapData.TYPE_ORGANISATIONS, orgId);
      ret.put("success", true);
      out.println(ret.toString());

    } catch (Exception e) {
      log.error(ExceptionUtils.getStackTrace(e));
      out.println("{'success':'false', 'msg': 'Tapahtui odottamaton virhe sovelluksessa.'}");
    }
  }
Exemple #21
0
 public void _jspService(
     javax.servlet.http.HttpServletRequest request,
     javax.servlet.http.HttpServletResponse response)
     throws java.io.IOException, javax.servlet.ServletException {
   com.caucho.server.webapp.WebApp _jsp_application = _caucho_getApplication();
   javax.servlet.ServletContext application = _jsp_application;
   com.caucho.jsp.PageContextImpl pageContext =
       _jsp_application
           .getJspApplicationContext()
           .allocatePageContext(
               this, _jsp_application, request, response, null, null, 8192, true, false);
   javax.servlet.jsp.PageContext _jsp_parentContext = pageContext;
   javax.servlet.jsp.JspWriter out = pageContext.getOut();
   final javax.el.ELContext _jsp_env = pageContext.getELContext();
   javax.servlet.ServletConfig config = getServletConfig();
   javax.servlet.Servlet page = this;
   response.setContentType("text/html;charset=UTF-8");
   request.setCharacterEncoding("UTF-8");
   try {
     out.write(_jsp_string0, 0, _jsp_string0.length);
   } catch (java.lang.Throwable _jsp_e) {
     pageContext.handlePageException(_jsp_e);
   } finally {
     _jsp_application.getJspApplicationContext().freePageContext(pageContext);
   }
 }
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  public void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    request.setCharacterEncoding("UTF-8");

    PrintWriter out = response.getWriter();
    try {
      SubjectDAO subdao = new SubjectDAO();
      DatastreamDAO dstreamDao = new DatastreamDAO();
      List<JsonSubject> jsubList = new ArrayList<JsonSubject>();
      List<Subject> subList = new ArrayList<Subject>();
      String loginID = "leoncool";
      if (request.getParameter(AllConstants.api_entryPoints.request_api_loginid) != null) {
        loginID = request.getParameter(AllConstants.api_entryPoints.request_api_loginid);
      }
      UserDAO userDao = new UserDAO();
      if (!userDao.existLogin(loginID)) {
        ReturnParser.outputErrorException(
            response, AllConstants.ErrorDictionary.Unauthorized_Access, null, null);
        return;
      }
      if (request.getParameter(AllConstants.api_entryPoints.request_api_onlyParentSubjects) != null
          && request
              .getParameter(AllConstants.api_entryPoints.request_api_onlyParentSubjects)
              .equalsIgnoreCase(AllConstants.api_entryPoints.request_api_true)) {
        subList = subdao.findOnlyParentSubjectsByLoginID(loginID);
      } else {
        subList = subdao.findSubjectsByLoginID(loginID);
      }
      DBtoJsonUtil dbtoJUtil = new DBtoJsonUtil();
      for (Subject sub : subList) {
        if (sub.getVisibleSet() != null
            && sub.getVisibleSet().equalsIgnoreCase(AllConstants.ProgramConts.visibleSet_PUBLIC)) {
          jsubList.add(dbtoJUtil.convert_a_Subject(sub));
        }
      }
      System.out.println(jsubList.size());
      Gson gson = new Gson();
      JsonElement je = gson.toJsonTree(jsubList);
      JsonObject jo = new JsonObject();
      jo.addProperty(AllConstants.ProgramConts.result, AllConstants.ProgramConts.succeed);
      jo.add("subject_list", je);
      JsonWriter jwriter = new JsonWriter(response.getWriter());
      //            if (request.getParameter("callback") != null) {
      //                System.out.println("using callback");
      //                out.print(request.getParameter("callback")+"("+ gson.toJson(jo) + ");");
      //            } else {
      //                gson.toJson(jo, jwriter);
      //                jwriter.close();
      //            }
      gson.toJson(jo, jwriter);
      jwriter.close();

    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      out.close();
    }
  }
 /**
  * @author : 林俊钦
  * @date : Mar 17, 2012 1:38:24 PM @Method Description :
  */
 private Map setGoodsMap(Map pageMap) throws UnsupportedEncodingException {
   HttpServletRequest request = getRequest();
   request.setCharacterEncoding("UTF-8");
   // 搜索会员名称
   if (this.cust_name_s != null && !this.cust_name_s.equals("")) {
     pageMap.put("cust_name_s", this.cust_name_s);
   }
   // 搜索的商品名称
   if (this.name_s != null && !this.name_s.equals("")) {
     pageMap.put("name_s", this.name_s);
   }
   // 搜索的团购标题
   if (this.title_s != null && !this.title_s.equals("")) {
     pageMap.put("title_s", this.title_s);
   }
   // 是否免运费
   if (this.ship_s != null && !this.ship_s.equals("")) {
     pageMap.put("ship_s", this.ship_s);
   }
   // 搜索的状态
   if (this.state_s != null && !this.state_s.equals("")) {
     pageMap.put("state_s", this.state_s);
   }
   // 获取搜索的所属分类
   if (request.getParameter("cat_attr_s") != null) {
     String cat_attr = request.getParameter("cat_attr_s");
     pageMap.put("cat_attr", cat_attr);
   }
   // 操作者为会员则默认加入搜索条件
   if (this.session_cust_type.equals(Constants.MEMBER_TYPE)) {
     pageMap.put("cust_id", this.session_cust_id);
   }
   return pageMap;
 }
 @RequestMapping(value = URLFinalController.UPDATEMEMBER, method = RequestMethod.GET)
 public @ResponseBody String updateMember(
     @PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response)
     throws ParseException {
   try {
     request.setCharacterEncoding("utf-8");
     response.setCharacterEncoding("utf-8");
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
   }
   Member member = new Member();
   member.setName(request.getParameter("name"));
   member.setBirthday(new SimpleDateFormat("yyyy/MM/dd").parse(request.getParameter("birthday")));
   member.setSex(Integer.parseInt(request.getParameter("sex")));
   member.setPhone(request.getParameter("phone"));
   member.setAvatar(request.getParameter("avatar"));
   member.setEmail(request.getParameter("email"));
   member.setAddress(request.getParameter("address"));
   member.setStar(Integer.parseInt(request.getParameter("star")));
   member.setJoinDate(new SimpleDateFormat("yyyy/MM/dd").parse(request.getParameter("joinDate")));
   member.setIntroduce(request.getParameter("introduce"));
   member.setActivity(Integer.parseInt(request.getParameter("activity")));
   this.memberService.updateMember(member);
   return "Member: " + member;
 }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");
    response.setContentType("text/html;charset=UTF-8");

    Cookie[] cookies = request.getCookies();
    if (cookies != null && cookies.length > 0) {
      for (Cookie c : cookies) {
        System.out.println("cookie domain :" + c.getDomain());
        System.out.println("cookie path :" + c.getPath());
        System.out.println("cookie comment :" + c.getComment());

        System.out.println("cookie maxAge :" + c.getMaxAge());
        System.out.println("cookie version :" + c.getVersion());
        System.out.println("cookie name :" + c.getName());
        System.out.println("cookie value:" + c.getValue());
      }
    } else {
      System.err.println("不存在cookie");
    }

    // 创建cookie
    Cookie cookie = new Cookie("myCookie", "mycookieServlet");

    // 将cookie信息通知浏览器
    response.addCookie(cookie);
  }
Exemple #26
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    String authorName = request.getParameter("userName");
    /*String hello = request.getParameter("123");
    System.out.println(hello);*/
    ArrayList<Plan> ap = new ArrayList<Plan>();
    StringBuilder sb = new StringBuilder();
    System.out.println("userName:"******"qq");
      for (Iterator iterator = ap.iterator(); iterator.hasNext(); ) {
        Plan plan1 = (Plan) iterator.next();
        sb.append("mmm");
        sb.append(plan1.toString());

        if (iterator.hasNext()) {
          sb.append("qwert");
        }
      }
      System.out.println("-------------" + sb.toString());
      response.getWriter().write(sb.toString());
    } catch (SQLException e) {
      System.out.println("23234");
      // TODO 自动生成的 catch 块
      e.printStackTrace();
    }
  }
  public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    req.setCharacterEncoding("UTF-8");

    Map<String, String[]> parametersMap = req.getParameterMap();
    ServletContext context = req.getSession().getServletContext();

    List<JavaWorldNews> yourList = (List<JavaWorldNews>) context.getAttribute("javaNews");

    Boolean archiveFlag = false;

    if ((Boolean) req.getSession().getAttribute("javaWorldIndexFlag") == false) {
      archiveFlag = true;
    }
    req.getSession().setAttribute("javaWorldAchiveFlag", archiveFlag);

    for (JavaWorldNews list : yourList) {
      JavaWorldNewsArchive javaWorldNewsArchive =
          new JavaWorldNewsArchive(list.getTitle(), list.getDescription(), list.getLink());
      JavaWorldArchiveJpaDao javaWorldArchiveJpaDao = new JavaWorldArchiveJpaDao();
      if (javaWorldArchiveJpaDao.create(javaWorldNewsArchive).equals("duplicate")) {
        break;
      }
    }

    res.sendRedirect("JavaWorldNewsController");
  }
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");

    Long bookid = Long.parseLong(request.getParameter("bookid"));
    Long num = Long.parseLong(request.getParameter("num"));
    // Date orderdate=new Date();

    ServletContext sc = super.getServletContext();
    Map<Long, Book> books = (Map<Long, Book>) sc.getAttribute("books");
    Book book = books.get(bookid);
    // BrwList orderLine=new BrwList(book,1,num);
    // System.out.println(book.getId());
    BrwList orderLine = new BrwList();
    orderLine.setId(bookid);
    orderLine.setBook(book);
    // orderLine.setOrderdate(orderdate.getTime());
    orderLine.setNum(num);
    // System.out.println(orderLine.getBook().getName());

    HttpSession session = request.getSession(); // 取得session
    System.out.println("sessionListener监听之前。。。。");
    BrwCart cart = (BrwCart) session.getAttribute("brwCart");

    // System.out.println(orderLine.getBook().getId());
    if (cart == null) {
      cart = new BrwCart();
      session.setAttribute("brwCart", cart);
    }
    cart.add(orderLine);

    RequestDispatcher rd = request.getRequestDispatcher("listBookStore.jsp");
    rd.forward(request, response);
  }
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // 接收时设置的编码
    request.setCharacterEncoding("utf-8");
    // 转发时设置的编码
    response.setCharacterEncoding("utf-8");
    // 以 超文本格式 方式转发
    response.setContentType("text/html");
    // 获取了一个输出流
    PrintWriter out = response.getWriter();

    // 修改库存数量Ajax
    String id = request.getParameter("id");
    String number = request.getParameter("number");
    NeProductsDao neProductsDao = new NeProductsDaoImpl();
    int count = neProductsDao.updateNumber(Integer.parseInt(id), Integer.parseInt(number));
    if (count > 0) {
      out.println("商品" + id + "库存数量修改成功");
    } else {
      out.println("商品" + id + "库存数量修改失败");
    }

    out.flush();
    out.close();
  }
Exemple #30
0
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   req.setCharacterEncoding("UTF-8");
   resp.setCharacterEncoding("UTF-8");
   String carname = req.getParameter("carname");
   String carinfo = req.getParameter("carinfo");
   float carprice = Float.parseFloat(req.getParameter("carprice"));
   String imgpath = req.getParameter("imgpath");
   int num = Integer.parseInt(req.getParameter("num"));
   if (!(carname.equals("") && carinfo.equals("") && imgpath.equals(""))
       && carprice > 0
       && num > 0) {
     CarDao cd = new CarDao();
     try {
       if (cd.updateCar(imgpath, carinfo, carprice, num, carname)) {
         resp.sendRedirect("carinfo.jsp?ok=1");
       } else {
         System.out.println("更新失败!");
       }
     } catch (SQLException e) {
       e.printStackTrace();
     }
   } else {
     resp.sendRedirect("carinfo.jsp?ok=0");
   }
 }