美文网首页
Request获取请求流getReader

Request获取请求流getReader

作者: 开心的小哈 | 来源:发表于2022-01-13 21:30 被阅读0次

    regist.html

    <!DOCTYPE html>  
    <html lang="en">  
    <head>  
     <meta charset="UTF-8">  
     <title>Title</title>  
    </head>  
    <body>  
    <form action="/Demo3" method="post">  
     <input type="text" name="username" placeholder="请输入账号">  
     <input type="password" name="pwd" placeholder="请输入密码">  
     <input type="submit" value="注册">  
    </form>  
    </body>  
    </html>
    

    Demo3.java

    package com.example.demo1;  
      
    import javax.servlet.*;  
    import javax.servlet.http.*;  
    import javax.servlet.annotation.*;  
    import java.io.BufferedReader;  
    import java.io.IOException;  
      
    @WebServlet(name = "Demo3", value = "/Demo3")  
    public class Demo3 extends HttpServlet {  
        @Override  
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
      
        }  
      
        @Override  
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
            //获取请求消息体--请求参数  
      
     //1.获取字节流  
     BufferedReader reader = request.getReader();  
     //2.读取数据  
     String line=null;  
     while((line=reader.readLine())!=null){  
                System.out.println(line);  
     }  
        }  
    }
    

    运行程序查看控制台结果报错啦[[TldScanner.scanJars 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录]]
    再次重新访问页面并提交数据
    ![[Pasted image 20220102194219.png]]
    结果页面还出现了乱码解决方案:问题2[[解决IDEA乱码问题]]
    再次运行查看结果:
    ![[Pasted image 20220102194159.png]]

    相关文章

      网友评论

          本文标题:Request获取请求流getReader

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