获取请求行信息

1.请求行信息:  GET /day36/demo2 HTTP/1.1
2.请求行信息 = 请求方式(GET) + 请求的资源(/day36/demo2 ) + 协议的版本(http1.1)
3.需求: 通过request对象获取请求行信息。 
4.例子代码
public class RequstLineServlet extends HttpServlet {
 
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//请求行  = 请求方式 + 请求资源+ 协议版本
		//请求方式
		String methName = request.getMethod();
		//请求资源
		String uri = request.getRequestURI();
		//使用http协议版本
		String protocol = request.getProtocol();
		
		System.out.println("请求方式:"+methName+ "请求的资源:"+ uri +" 使用的协议版本:"+ protocol);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
 
}

猜你喜欢

转载自blog.csdn.net/chenzuen113113/article/details/80796157