This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes get port number in tomcat 7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "get port number in tomcat 7" Watch "get port number in tomcat 7" New topic
Author

get port number in tomcat 7

Angei Angie
Greenhorn

Joined: Feb 05, 2013
Posts: 1
Hi

I have currently moved to tomcat 7 where i need to access the port .A sample code which wrks fine on tomcat 6
Server server = ServerFactory.getServer();
Service[] services = server.findServices();
for (Service service : services) {
for (Connector connector : service.findConnectors()) {
ProtocolHandler protocolHandler = connector.getProtocolHandler();
if (protocolHandler instanceof Http11Protocol
|| protocolHandler instanceof Http11AprProtocol
|| protocolHandler instanceof Http11NioProtocol) {
serverPort = connector.getPort();
System.out.println("HTTP Port: " + connector.getPort());
}
}


}


is there something similar in tomcat 7 ?
I tried this but this aint working either ..
import javax.management.*;
import org.apache.catalina.Server;

MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
ObjectName name = new ObjectName("Catalina", "type", "Server");
Server server = (Server) mBeanServer.getAttribute(name, "managedResource");


Thanks in advance



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get port number in tomcat 7
 
Similar Threads
How to Enable SSL on Tomcat 7 on Linux?
Suspending/Pausing a MDB's Consumption Programmatically
How to reference a JMX MBean ?
How to get MBeanServer from Servlet?
Running Tomcat from Eclipse