标签:请求 -- vax 获取客户端ip over sts 获取 extends cep
方法名 | 作用 |
---|---|
req.getRemoteAddr | 获取客户端IP地址 |
req.getLocalAddr() | 获取服务器IP地址 |
req.getRemoteHost | 获取客户端的主机名 |
req.getRemotePort | 获取客户端的端口号 |
req.getLocalPort | 获取服务器的端口号 |
req.getLocalName | 获取服务器主机名 |
req.getContextPath | 获取ContextPath |
req.getServletPath() | 获取ServletPath |
req.getMethod | 获取请求方式 |
req.getQueryString | 获取请求的参数的值 |
req.getRequestURL | 获取请求全路径 |
package com.szx.servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class Requests extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("客户端ip---------req.getRemoteAddr():"+req.getRemoteAddr());
System.out.println("获取服务器ip------req.getLocalAddr():"+req.getLocalAddr());
System.out.println("客户端主机名------req.getRemoteHost():"+req.getRemoteHost());
System.out.println("客户端端口号------req.getRemotePort():"+req.getRemotePort());
System.out.println("服务器主机名-------req.getLocalName():"+req.getLocalName());
System.out.println("获取ContextPath--req.getContextPath():"+req.getContextPath());
System.out.println("ServletPath()---req.getServletPath():"+req.getServletPath());
System.out.println("请求方式----------req.getMethod():"+req.getMethod());
System.out.println("请求的值----------req.getQueryString():"+req.getQueryString());
System.out.println("请求全路径--------RequestURL():"+req.getRequestURL());
}
}
<servlet>
<servlet-name>Requests</servlet-name>
<servlet-class>com.szx.servlet.Requests</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Requests</servlet-name>
<url-pattern>/requests</url-pattern>
</servlet-mapping>
其中QueryString为null因为没有传入参数
标签:请求 -- vax 获取客户端ip over sts 获取 extends cep
原文地址:https://www.cnblogs.com/xun-/p/12764298.html