开发者

Get URL of the request sender with HttpServletRequest

开发者 https://www.devze.com 2023-04-01 14:25 出处:网络
How do you get the source domain using HttpServletRequest? S开发者_运维知识库ource domain is the requester\'s domain.

How do you get the source domain using HttpServletRequest? S开发者_运维知识库ource domain is the requester's domain.

Thanks.


You could do either

// gets client (browser)'s hostname
String host = request.getRemoteHost(); 

OR

// get the server's domain name.
String domain = new URL(request.getRequestURL().toString()).getHost(); 


To get the source domain you can use request.getHeader("origin") especially if the requests have to pass through a proxy server.


Hostname request

InetAddress ip = InetAddress.getLocalHost();
String hostname = ip.getHostName();
out.print("Your current IP address : " + ip+"\n");
out.print("Your current Hostname : " + hostname);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号