We are using request.getRemoteHost() in the jsp page to get the hostname of the client but it ll return only IP address of the client system
Is any other way to get the client system host name from java-script,jsp,...
If you server has enableLookups ( for example for Tomcat ) on false this getRemoteHost() will return only ip . Simplest solution would be to just change property and force resolving of ip to hostname.
Related
I can connect to my tomcat7 server using IP address but when I replace IP Address with my URL, I'm unable to connect to the host.
Error Message displayed:
This web page is not available
ERR_CONNECTION_REFUSED
The website may be down or your network may not be properly configured.
Try add pair host_ip host_name to host's file in your compruter.
I have set up a Tomcat 6 server on Linux that is accessible from the internet and locally by different host names. The hostnames are set in /etc/hosts like this
# IP Address Full-Qualified-Hostname Short-Hostname
123.123.123.123 my-server.subdomain.domain.com my-server
From the web the server is accessible by the full qualified hostname and from the intranet by both names.
In one of my services I refer to java.net.URI getBaseUri() for getting the URI of a service. Unfortunately it always returns the URI using the Short-Hostname. What I want is that it uses the Full-Qualified-Hostname. How can I tell Tomcat to use it?
resolving a hostname to an IP address is rather easy in Java by using the InetAddress class like this:
InetAddress address = InetAddress.getByName("www.example.com");
But this method uses the DNS server which is used by the running system.
Is there any way to specify the DNS server that should be used for resolving?
If you use Sun Java, you can use this code:
//Override system DNS setting with Google free DNS server
System.setProperty("sun.net.spi.nameservice.nameservers", "8.8.8.8");
System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");
See this blog post: How to set a custom DNS server with Java System properties for more details.
I am trying to connect to a msql db using tablet
my connection string is such like
connString ="jdbc:jtds:sqlserver://10.0.0.28:1433/foodserv;user=align;password=alignminds;";
it work fine .
Now i want to connect to the db using name of the server Like ip 10.0.0.28 has server name suresh-pc
Then how the string will change
my point is to replace ip with name and i am connection using tablet
Server name is nothing but an alias for the IP of a host. If you use the server's name insted of IP the DNS server will resolve its ip for you. Check the link for ho DNS works http://www.howstuffworks.com/dns.htm. So simply replace the IP with server's name.
HttpServletRequest.getRemoteAddr() in Tomcat returns IPv6 formatted IP address, but I would like to configure it that returns IPv4.
I access the servlet via 'localhost'. If I access it via '127.0.0.1' then returns IPv4 formatted IP address (see this answer).
Environment:
Windows 7 x64
Tomcat 6.0.35-windows-x64
My LAN connection properties:
IPv6 is checked off, but it doesn't work neither if I check it on.
try adding this parameter -Djava.net.preferIPv4Stack=true to your tomcat startup commandline.
when you use localhost/xxx, your browser first have to find the mapped address for the name "localhost".In system host file you will find:
# 127.0.0.1 localhost
# ::1 localhost
both definition disabled by default.
to change browser's default matching rules, you have to enable the definition.
e.g: remove "#" from the first host file line, your brower will know directily "localhost" equals 127.0.0.1
Cheers