I have a task in java for getting the IP address and port no of server at which web application is running .I am able to find the solution of getting the IP address .But I am facing difficulties for finding the port no
So this piece of code would be running on the same machine as the web app for which you're trying to figure this out? Would it be part of that web app? If it's not part of that web app, the task is impossible in the general sense, since there could be multiple HTTP processes running on the machine. If, OTOH, it IS part of that web app, surely it would be easier to just set a global value somewhere at startup which your piece of code could check.
Maybe I'm missing something, as it's not clear to me what the purpose of this is; maybe you can elaborate on that.
That's an exercise in futility. A webapp server can listen on many ports, many interfaces and via many protocols.
For example, Tomcat will listen on all interfaces (including localhost) and in its out-of-the-box form, it listens on port 8080 (http), 8443 (https), 8009 (proxy) and 8005 (control), plus I think one other but can't remember. By adding/altering Connector elements in Tomcat's [tt]server.xml[/i] you can add more ports and/or change the existing port numbers. And, indeed, it's not uncommon to do so.
You can get the port number on which a given HttpServletRequest was received by using its API methods, but that only applies to that one request. If there were additional ports also listening, you wouldn't be able to tell without querying Tomcat's internal bean structure. And, of course, that would be different logic than any other server such as WebSphere would require.
Sources may include data from the Fakebook Research Foundation with support from Gargle University
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop