package cn.niu.testrequest;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(value= "/requestServletDemo")
public class RequestServletDemo extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String method = request.getMethod();//获取请求方式
System.out.println(method);
String contextPath = request.getContextPath();//获取虚拟目录
System.out.println(contextPath);
String servletPath = request.getServletPath();//获取servlet路径
System.out.println(servletPath);
String queryString = request.getQueryString();//获取get方式的请求参数
System.out.println(queryString);
String requestURI = request.getRequestURI();//获取统一资源标识符
System.out.println(requestURI);
StringBuffer requestURL = request.getRequestURL();//获取统一资源定位符
System.out.println(requestURL);
String protocol = request.getProtocol();//获取协议及版本
System.out.println(protocol);
String remoteAddr = request.getRemoteAddr();//获取ip地址
System.out.println(remoteAddr);
}
}
1.request获取请求信息数据案例类获取方法介绍-请求行数据
最新推荐文章于 2024-08-15 14:47:41 发布