Environment: NetBeans 6.9.1, GlassFish 3.1
I have a Java Web Application. How to get the server address and the application name dynamically? The '2in1' solution would be the best for me: http://localhost:8080/AppName/
.
Is there a practical way to get that information?
Let's say the value of AppName
will be fixed, so I only need the host address. Is it possible to retrieve it via JMX? Any other ways?
Following are the 3 ways you can check website IP address:Check your Welcome Mail: IP address of the server is typically mentioned in the welcome email by the company. Use Ping Command: You can ping the webserver with the CLI, and find the webserver. Global DNS Checker for IP Lookup: Use Global DNS checker tool online ...
In Java, you can use InetAddress. getLocalHost() to get the Ip Address of the current Server running the Java app and InetAddress. getHostName() to get Hostname of the current Server name.
The HttpServletRequest
object will give you what you need:
HttpServletRequest#getLocalAddr()
: The server's IP address as a stringHttpServletRequest#getLocalName()
: The name of the server receiving the requestHttpServletRequest#getServerName()
: The name of the server that the request was sent toHtppServletRequest#getLocalPort()
: The port the server received the request onHttpServletRequest#getServerPort()
: The port the request was sent toHttpServletRequest#getContextPath()
: The part of the path that identifies the applicationIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With