1

I am trying to write a java code that will return the name of the machine on which it is running as in the name of the remote machine from which I am accessing the code instead of the machine where it is actually running. I have this code but it returns the name of parent machine in output instead of the remote machine:

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter();

String remoteUser = req.getRemoteUser();
}

This code is on a system with name : Animesh I am trying to access the code through another machine named: Bhaskar using the system's IP address as in :8080/website/home

I am expecting it to return Bhaskar as username but it returns Animesh instead

4

1 回答 1

1

据我了解,如果 getRemoteHost 包含 IP,则请求机器不会发送其名称。

在网上找到这个,也许它有帮助:http ://docstore.mik.ua/orelly/java-ent/servlet/ch04_03.htm

谷歌可能也会为您提供更多答案。

于 2013-02-03T00:42:59.077 回答