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());输出的数据信息

调用HttpServletRequest对象的getMethod方法为什么无法在控制台显示请求方式
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- wznstlr 2016-11-05 13:18关注
问题已经解决,是由于在本机控制台启动的tomcat服务器,然后在浏览器发送的请求,所以请求信息是在本机控制台上显示的,eclipse 控制台就显示不了
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报