wznstlr 2016-11-05 01:05 采纳率: 100%
浏览 1490
已采纳

调用HttpServletRequest对象的getMethod方法为什么无法在控制台显示请求方式

package gz.itcast.b_request;import java.io.IOException;import java.io.PrintWriter;import java.util.Enumeration;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class RequestDemo1 extends HttpServlet { /** * The doGet method of the servlet.
* * 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 { //t1(request); /* * 3.2 请求头 / String host = request.getHeader("Host"); //根据头名称的到头的内容 System.out.println(host); //遍历所有请求头 Enumeration enums = request.getHeaderNames(); //得到所有的请求头名称列表 while(enums.hasMoreElements()){//判断是否有下一个元素 String headerName = enums.nextElement(); //取出下一个元素 String headerValue = request.getHeader(headerName); System.out.println(headerName+":"+headerValue); } } private void t1(HttpServletRequest request) { /* * 3.1 请求行 格式:(GET /day09/hello HTTP/1.1) */ System.out.println("请求方式:"+request.getMethod());//请求方式 System.out.println("URI:"+request.getRequestURI());//请求资源 System.out.println("URL:"+request.getRequestURL()); System.out.println("http协议版本:"+request.getProtocol());//回头tp协议 }}为什么我在浏览器发送http://localhost:8080/day09/RequestDemo1请求,在myeclipse控制台看不到System.out.println("请求方式:"+request.getMethod());System.out.println("URI:"+request.getRequestURI());System.out.println("URL:"+request.getRequestURL());System.out.println("http协议版本:"+request.getProtocol());输出的数据信息

  • 写回答

2条回答 默认 最新

  • wznstlr 2016-11-05 13:18
    关注

    问题已经解决,是由于在本机控制台启动的tomcat服务器,然后在浏览器发送的请求,所以请求信息是在本机控制台上显示的,eclipse 控制台就显示不了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵