Get URL of the request sender with HttpServletRequest

China☆狼群 提交于 2020-01-01 04:16:09

问题


How do you get the source domain using HttpServletRequest? Source domain is the requester's domain.

Thanks.


回答1:


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(); 



回答2:


Hostname request

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


来源:https://stackoverflow.com/questions/7246543/get-url-of-the-request-sender-with-httpservletrequest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!