美文网首页
HttpServlet GET请求 POST请求

HttpServlet GET请求 POST请求

作者: AlwaysLuckyMa | 来源:发表于2020-11-09 20:15 被阅读0次

    GET

            Map<String, Object> map = new HashMap<String, Object>();
            String type      = req.getParameter("type");
    
            System.out.println("fsdfsdfsdsddsf" + type);
    
            String resultStr = null;
    
            if (type.equals("login")) {
    
                String phoneNum = req.getParameter("phoneNum");
                String pass     = req.getParameter("pass");
    
                UserScerviceImpl userScervice = new UserScerviceImpl();
    
                userInfoModel userTestModel = new userInfoModel();
                String userPhoneNum         = phoneNum;
                String userPass             = pass;
                userTestModel.setUserName(userPhoneNum);
                userTestModel.setUserPass(userPass);
                map = userScervice.userLogin(userTestModel);
            }
    
    

    POST

    ServletInputStream servletInputStream = req.getInputStream();
    
            StringBuilder content = new StringBuilder();
            byte[] b = new byte[1024];
            int lens;
            while ((lens = servletInputStream.read(b)) > 0) {
                content.append(new String(b, 0, lens));
            }
    
            String strContent = content.toString(); // 请求体内容
    
    
            HashMap hashMap = JSON.parseObject(strContent, HashMap.class);
    
            String s = hashMap.get("phoneNum").toString();
            System.out.println("post请求"+s);
    

    相关文章

      网友评论

          本文标题:HttpServlet GET请求 POST请求

          本文链接:https://www.haomeiwen.com/subject/cdbtnctx.html