Get IP address of client in JSP

前端 未结 4 688
慢半拍i
慢半拍i 2021-02-09 11:36

I need to get the IP address of the client in the JSP page. I have tried the following ways:

request.getRemoteAddr()
request.getHeader(\"X_FORWARDED_FOR\")
reque         


        
4条回答
  •  粉色の甜心
    2021-02-09 12:01

    <%
    out.print( request.getRemoteAddr() );
    out.print( request.getRemoteHost() );
    %>
    

    You may not get the real client IP if a the client is behind a proxy, you will get the IP of the proxy and not the client. However, the proxy may include the requesting client IP in a special HTTP header.

    <%
    out.print( request.getHeader("x-forwarded-for") );
    %>
    

提交回复
热议问题