[java]代码库
package pm_cn.itcast.request;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
* 获得 客户机信息的 api详解 :
*
*/
public class RequestDemo1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StringBuffer requestURL = request.getRequestURL();
// 返回 请求的 资源 名称
String requestURI = request.getRequestURI();
// URI (universal resource identifier) 与 URL(universal resource link) 区别 ? http://www.sina.com chrome://
// 返回 查询路径
String queryString = request.getQueryString();
// addr -->> address 表示 地址, 返回 来访者的 ip 地址
String ipDizhi = request.getRemoteAddr();
// 请求方式
String method = request.getMethod();
// 获得 web 工程 的 对外 访问 路径 : /day11
String contextPath = request.getContextPath();
System.out.println("requestURL : " + requestURL);
System.out.println("requestURI : " + requestURI);
System.out.println("queryString : " + queryString);
System.out.println("ipDizhi : " + ipDizhi);
System.out.println("method : " + method);
System.out.println("contextPath : " + contextPath);
System.out.println("请求的资源 名称 : " + requestURI.substring(contextPath.length()));
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}