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条)

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格