• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting a computer name in Java  RSS feed

 
Vidya Krishnamurthi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All
I have a JSP/MS SQLapplication on a intranet .the application has been on one machine and is being accessed by all other machines.Now the requirement is that in one of the machines (other than server) needs to act as a library terminal from which books can be borrowed.So if the url is typed in any machine the application has to track as to the request is coming from which machine and allow or disallow acccessing the borrowing of books.That is only one terminal can be used for borrowing books.

Can anyone help me on how to implement this.Can IP address or computer name be captured from the application in Java so that we know from which machine the application is being accessed.

Please help me out .I tried searching on net but mostly found that computer name cannot be cpptured in Java .Its only the server IP address which can be captured .In that case how can this be implemented.

any help will be highly appreciated.
Thanks in advance..
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can capture the place where the request to the JSP originated.
That will yield an IP address.

From the API docs of HttpServletRequest (which is available inside a jsp as the jsp variable "request"):


getRemoteAddr
public java.lang.String getRemoteAddr()Returns the Internet Protocol (IP) address of the client that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR.
Returns:
a String containing the IP address of the client that sent the request

--------------------------------------------------------------------------------

getRemoteHost
public java.lang.String getRemoteHost()Returns the fully qualified name of the client that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address. For HTTP servlets, same as the value of the CGI variable REMOTE_HOST.
Returns:
a String containing the fully qualified name of the client


Of course your mechanism will fail if the client machines use dynamic IP addresses.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!