首页 > 其他 > 详细

黑马day04 request获取客户机的信息

时间:2015-06-18 13:35:37      阅读:258      评论:0      收藏:0      [点我收藏+]

使用request可以获取请求中过程中的信息:

package cn.itheima.request;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//1.得到客户机的完整的url地址
		String url = request.getRequestURL().toString();
		System.out.println(url);
		//2.得到客户机的uri
		String uri = request.getRequestURI();
		System.out.println(uri);
		//3.请求参数的参数部分
		String params = request.getQueryString();
		System.out.println(params);
		//4.客户机的ip地址
		String ip = request.getRemoteAddr();
		System.out.println(ip);
		//5.得到客户机的请求方式get post
		String method = request.getMethod();
		System.out.println(method);
		//6.得到当前web应用虚拟目录,工程中不要求写死
		String contextPath = request.getContextPath();
		System.out.println(contextPath);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}


}
运行结果:
http://localhost:8080/day04/servlet/RequestServlet
/day04/servlet/RequestServlet
username=liweikang&password=123
0:0:0:0:0:0:0:1
GET
/day04


黑马day04 request获取客户机的信息

原文:http://blog.csdn.net/u014010769/article/details/46546471

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!