1
votes

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

1
this may help. stackoverflow.com/questions/2591135/… edit I think I misread your question. I think what you want may be getRemoteHost() ?Stephanie Peters
Thanks Stephanie...this helps but partially. Now I have the IP address of the system but I would rather have the system name returnedBhaskar

1 Answers

1
votes

By my understanding, if getRemoteHost contains an IP then the requesting machine is not sending its name.

Found this on the web, perhaps it helps: http://docstore.mik.ua/orelly/java-ent/servlet/ch04_03.htm

Google may have more answers for you as well.