posts - 397,comments - 0,views - 25332

获取请求体:

  请求体:只有POST请求方式,才能请求体,在请求体中分装了POST请求参数

步骤:

  获取流对象

    BufferedReader 个体Read():获取字符串输入流,只能操作字符数据

    ServletInputStream getinput():   获取字节输入流,可以操作所有类型的数据

 

@Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader reader = req.getReader();
        String line = null;
        while ((line=reader.readLine())!=null){
            System.out.println(line);
        }
    }
复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="/requestDemo" method="post">
    <input type="text" name="username" placeholder="请输入名"><br>

    <input type="text" name="password" placeholder="请输入密码"><br>
    <input type="submit" value="注册">
</form>
</body>
</html>
复制代码

 

 

 

 

 

 

 

 

 

 

 

 

 

Request_请求参数通用方式介绍

   获取参数方式:

    String getparamter(String name) :根据参数名获取参数值,    username=zs &password=123

    String[] getParametervalue(String name):根据参数名获取参数值的数组  hobby=xx&hobby=game

    Enumeration<String> getParamterNames() 获取所有请求的参数名称

    map<String,String[]> getParamter():获取所有参数的map结合

  请求转发

  共享数据

  获取ServletContext

posted on   淤泥不染  阅读(479)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示