package 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 RequestDemo1 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//得到请求行中的资源名部分(常用)
System.out.println(request.getRequestURI());
//返回客户端发出请求时的完整uri
System.out.println(request.getRequestURL());
//返回请求行中的参数部分 http://localhost:8080/requestandresponse/RequestDemo1?name=hhh
System.out.println(request.getQueryString());
//返回发出请求的客户端的ip
System.out.println(request.getRemoteAddr());
//返回发出请求的客户机的完整主机名
System.out.println(request.getRemoteHost());
//返回客户端所使用的网络端口号
System.out.println(request.getRemotePort());
//返回WEB服务器的IP地址
System.out.println(request.getLocalAddr());
//返回WEB服务器的主机名
System.out.println(request.getLocalName());
//得到客户机的请求方式
System.out.println(request.getMethod());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}