Identifying the port number where Tomcat is running.

I want to mail the URL of the my application dynamically with the system generated mails. With the help of java.net package I am able to get the IP address of the system, but I have hard coded the port no in the URL. I want to make the port no. also dynamic (E.g. IP address is not hard coded).
The servlet is deployed to the Tomcat server. What code I write to know the port on which the tomcat is running ?
thanks in advance,
Mukesh.

You could use ServletRequest.getServerPort() to find out the port number on which the request is being sent by the client but I don't know if this will help you.
People on the forum help others voluntarily, it's not their job.
Help them help you.
Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
(Yes I know it's on JavaRanch but I think it applies everywhere)
EDIT: ServletRequest.getLocaPort() gives the port at which the request is received; I'm not quite sure what the difference is ( I can guess but I'm not certain ) and I don't know which, if either, will be of use to you.
Edited by: nogoodatcoding on Oct 9, 2007 7:26 PM

Similar Messages

  • Tomcat Server Port Number: Why do I have to enter the port number?

    My ultimate goal is to setup a website that displays data from a database. I will use Java, Apache, Oracle, and whatever else I need to create a website the uses servlets, JavaServer Pages, and JDBC.
    I�ve got four Pentium III computers:
    1. Windows 2000 Server to be the web server (MyWebServer, IP = 10.10.1.1).
    2. Windows 2000 Professional to be the database server (MyDatabaseServer, IP = 10.10.1.2).
    3. Windows 2000 Professional that I use to develop and test (MyDeveloperPC, IP = 10.10.1.3).
    4. Windows 2000 Professional that I use as a client to connect to the website (MyClientPC, IP = 10.10.1.4).
    I installed Java Web Services Developer Pack on MyWebServer. It requires Java 2 Standard Edition (J2SE), so I installed that first. The files I downloaded and installed are as follows:
    J2SE: j2sdk-1_4_0-rc-win.exe
    JWSDP: jwsdp-1_0-ea1-win.exe
    After installing these products, I set the environment variables as follows:
    JAVA_HOME = c:\j2se
    JWSDP_HOME = c:\jwsdp
    Path = c:\j2se\bin;c:\jwsdp\bin; [and other previous statements]
    On MyWebServer I start Tomcat (from the JWSDP menu option). It starts properly (as far as I can tell).
    Then, from MyClientPC I open Internet Explorer and in the address box I type:
    http://10.10.1.1
    �The page cannot be displayed�.
    I then try again and add the port number:
    http://10.10.1.1:8080
    This displays the page c:\jwsdp\webapps\root\index.html.
    Here�s my question: Why do I have to enter the port number to get a page displayed? Do I have to have Apache HTTP Server running on MyWebServer to display pages without entering the port number?
    Thanks for your help.

    Oh simmy1, so silly....
    You have to enter the port number because Tomcat is running on that port (probably 8080). You actually don't NEED apache at all. Most people use it an HTTP listener because historically, servlet engines and application servers had shitty listeners. (WebLogic 5.1 was really bad.) Not sure how they stack up today.
    Port 80 is the default port that browsers will look at. (Try it, hit these forums with http://forum.java.sun.com and then hit it with http://forum.java.sun.com:80. See? Same thing.) If you don't want to have to enter a port number, just make sure whatever is running at the front of your network is serving on port 80. It doesn't matter if its apache, tomcat, weblogic, iis or whatever. There is nothing wrong with running Tomcat on port 80, although using a webserver proxy like apache is generally recommended.
    And don't listen to simmy1, this is his second bonehead post I've seen today: http://forum.java.sun.com/thread.jsp?forum=45&thread=231154

  • Java and Tomcat: Why do I need the port number when accessing Tomcat?

    My ultimate goal is to setup a website that displays data from a database. I will use Java, Apache, Oracle, and whatever else I need to create a website the uses servlets, JavaServer Pages, and JDBC.
    I�ve got four Pentium III computers:
    1. Windows 2000 Server to be the web server (MyWebServer, IP = 10.10.1.1).
    2. Windows 2000 Professional to be the database server (MyDatabaseServer, IP = 10.10.1.2).
    3. Windows 2000 Professional that I use to develop and test (MyDeveloperPC, IP = 10.10.1.3).
    4. Windows 2000 Professional that I use as a client to connect to the website (MyClientPC, IP = 10.10.1.4).
    I installed Java Web Services Developer Pack on MyWebServer. It requires Java 2 Standard Edition (J2SE), so I installed that first. The files I downloaded and installed are as follows:
    J2SE: j2sdk-1_4_0-rc-win.exe
    JWSDP: jwsdp-1_0-ea1-win.exe
    After installing these products, I set the environment variables as follows:
    JAVA_HOME = c:\j2se
    JWSDP_HOME = c:\jwsdp
    Path = c:\j2se\bin;c:\jwsdp\bin; [and other previous statements]
    On MyWebServer I start Tomcat (from the JWSDP menu option). It starts properly (as far as I can tell).
    Then, from MyClientPC I open Internet Explorer and in the address box I type:
    http://10.10.1.1
    �The page cannot be displayed�.
    I then try again and add the port number:
    http://10.10.1.1:8080
    This displays the page c:\jwsdp\webapps\root\index.html.
    Here�s my question: Why do I have to enter the port number to get a page displayed? Do I have to have Apache HTTP Server running on MyWebServer to display pages without entering the port number?
    Thanks for your help.

    When you web server is running at the default Http Port, then you do not have to specify the port yourself.(The browser does it automatically)
    So if you run your web server at port 80, then you will not have to specify the port explicitlyin the url.
    If you want to use tomcat only as a jsp/servlet processing engine then install a web server (either IIS, or apache web server) and run it on port 80. (so that you dont have to specify the port)
    Now configure tomcat to run as a servlet engine for this web server. for this refer to the tomcat documentation.
    If you do not want to have an external webserver then you can configure tomcat itself to run at port 80 (in this case tomcat would do the work of both the web server as well as jsp/servlet engine... but this is not the setup for a production site). this can be done by changing the server.xml file in the conf directory of tomcat installation.
    hope this helps.
    regards,
    Abhishek.

  • Warning: Either the server is already running or the port number is invalid. Shut down the MATLAB process in which the server is running or run the server on a different port number.

    安装好SIT后,matlab 提示
    Warning: Either the server is already running or the port number is invalid. Shut down the MATLAB process in which the server is running or run the server on a different port number.
    怎么解决?

    这个应该和SIT无关,意思是你有个MATLAB进程占用了某个端口号或者matlab的服务器正在运行,导致你现在的程序没法建立这个端口的服务器。 试试刀windows进程管理里把matlab相关的进程kill掉,再启动试试。或者参考链接http://www.cnblogs.com/qiweiwang/archive/2010/07/29/1788281.html  里边有关于建立服务器的描述,就在前半部分。

  • Change the port number

    can i install Oracle server and tomcat server on same machine ?
    how to change the port number in OracleXE 10g. so that i can install oracle Data base and tomcat on same machine.

    can i install Oracle server and tomcat server
    on same machine ?Yes.
    >
    how to change the port number in OracleXE 10g.
    so that i can install oracle Data base and tomcat on
    same machine.Just make sure Tomcat is running while you install Oracle, and it should find the port in use.
    Otherwise, turn tomcat off, install using port 8080, and use the sqlplus command 'exec dbms_xdb.sethttpport(8090); to change the port to 8090 after the fact.
    Before installing:
    1) On WIndows, use a LOCAL machine administrator, not a domain administrator or non-admin user;
    2) On Windows, turn off all firewalls before installing; on Fedora, turn off SELinux;
    3) If there was a previous Oracle on the machine, on windows make sure the registry is clean.

  • How do i find the port number for oracle10g

    Hi,
    I have installed oracle10g on my pc running windows XP. I need to get the port number for JDBC drivers used by Java Application when defining a JDBC source.
    Java is running on the same machine.
    When I installed oracle I was given the links (with port numbers) for EM, ULTRA SEARCH and iSQLPLUS, what I need is the ORACLE10g database port number. Anybody know where I get from ?
    Cheers

    thanks for the reply the portlist does not contain the port of oracle. The file is below.
    [i]Ultra Search HTTP port number =5620
    Enterprise Manager Agent Port =
    iSQL*Plus HTTP port number =5560
    Enterprise Manager Console HTTP Port (oracle10) = 5500
    Enterprise Manager Agent Port (oracle10) = 1830
    However searching through some other threads found the port to be 1521, which
    oracle must set during installation and tell anybody, unless this infor is in the log.
    so configured the oracle JDBC driver as below (PE8.2 --> ConnectionPools)
    Datasource Classname = oracle.jdbc.pool.OracleDataSource
    URL = jdbc:oracle:thin:@localhost:1521:oracle10
    User = abc
    Password = abc
    Now able to ping. Cheers

  • Hiding the port number from the url

    Hi All,
    In our applications built using Weblogic Portal 10.3, the url to access the application doesnt have the port number. It is simply like http://<server-name>/<context> no port at all. Is this some configuration that is available inside weblogic adminstration console? The domain has both the default port and the SSL port enabled which are running in 7001 and 7002 respectively. Please let me know as how to do this configuration as I am growing haywired on this it has been about a week and have not found an answer yet. Please throw some light on this and let me know if you need further details
    Thanks
    Ashwin

    you should install apache server to handle all the requests on port 80 and froward it to weblogic server using wlp plugin
    please check this link
    http://download.oracle.com/docs/cd/E13222_01/wls/docs81/plugins/apache.html
    any request http://yourapp/context will be mapped to http://youapp:7001/context

  • Is it possible to change the port number of an already installed ITS?

    Hello,
    I've done an install of the latest ITS stand-alone application (win2k server , IIS). It was installed on port 81.
    Is there an easy way to change the port number of this ITS installation without doing a new install? I know there are port references in the itsregistrywgate.xml file but was not sure if these were maintained during install or by reading the global.srvc file entries.
    I've taken the simplistic steps of changing the port number in IIS and the global.srvc file but that does not work. I get a 403.2 read access forbidden error.
    Any advice would be much appreciated.
    Thanks,
    Graham

    Hello Graham,
    yes, it is possible but depends on what you want.
    For IIS, WGate is depending on the following items:
    ISAPI wgate (the filter API that triggers on /scripts/wgate) which is normally a general isapi for all webserver instances.
    the virtual directory "SAP-WGate-Scripts" which exists for the according "virtual" webserver instance.
    the (web)servername in wgate registry, which points to your virtual webserver
    the "Port" in the URL section in wgate registry.
    So, if you want to change the port (e.g. from 81 to 82) for both your virtual webserver and the wgate then go ahead.
    But if you want an extra virtual host (e.g. on 82) then:
    create the virtual host on 82
    create a "SAP-WGate-Scripts" directory on this 82 host exactly as the one on the 81 host.
    change the "Port" in the wgate URL section.
    if you also have an own docroot directory you have to copy the SAP mimes from the 81 docroot to the new one.
    The only thing that will be wrong afterwards is the webservername, this will have no effect on the runtime behavior but at the next patch install you will get an extra dialog to identify your webserver again.
    If you wanted to go for the latter scenario then it might be less work to add a new instance by install e.g. a dual host wgate on the new virtual host or a single host install (with a dummy agate).
    Afterwards you can play around with the WGate configuration to change it to your needs.
    Regards,
      Fekke

  • How to change the port number for deployment in JAVA Studio Enterprise 8?

    Hi!
    Yesterday i downloaded this new sun java studio enterprise and found it mind blowing.
    Now i find that all my previous applications which were running on port 8080 can't be run on sun java studio enterprise(sjse) 8.
    Can anyone tell me how to change the port number on this software so i won't have to edit all my applications?

    http://docs.sun.com/source/819-0080/install.html
    In the Admin Configuration page (or at the command line), enter the following:
    Admin User Name�Name of the user who administers the server
    Password�Admin user�s password to access the Admin Server (8-character minimum)
    Admin Port�Administration port number for initial server instance
    HTTP Port�Port number to access the default server instance
    HTTPS Port�Secure port number to access the default server instance

  • How do you change the port number for Apex Listener V2?

    I'm running Apex listener V2 in standalone mode on Linux.  I want to change the port number of the apex listener V2 (e.g 80 to 8080).  How do I do that without re-installing the whole listener again?
    thanks in advance
    PaulP

    Hi PPlatt,
    You can modify your_listener_home_directory/apex/apex.properties
    http.port=8080
    Stop & restart listener.
    HTH
    Zack

  • How to modify the port number and use subdomains

    Couple of things ...
    1 - default port for installation is on 7777 and 7778. Would it be possible to run everything on port 80? I would like to hide the port number and not have people type in http://domain.com:7778
    2 - how can we use subdomains for certain services? For example, webmail should be http://webmail.domain.com and the RTC should be http://conference.biztech.com
    thx

    we're using OCS both inside and outside our network.
    I had my dba modify the port so now everything runs on port 80. However, I dont know how to get virtualhost to work correctly.
    conference.domain.com -> RTC piece
    webmail.domain.com -> webmail piece
    i.e....

  • How do I change the phone number where sms is sent to activate keychain?

    How do I change the phone number where sms message is sent to activate Keychain?  It keeps sendingit to an old phone #, and is most frustrating!

    System preferences > iCloud > Keychain > options.

  • How to hide the PORT NUMBER from the URL

    Hi,
    We have Application on Node 1 and Database on Node 2
    Apps Version: 11.5.10.2
    DB: 9.2.0.6
    We recently added a new node to act as web server for iSupport.
    Now we are able to access the url using public Ip-address which looks like
    http://<Internet Ip-Address>:<PORT NUMBER>
    Eg: http://******.com:8000
    But we dont want the *'PORT NUMBER(8000)'* to be displayed.
    How to hide the port number ?..
    Thanks in Advance,
    Mahesh

    Hi Hsawwan,
    Can you plz explain me the steps how to hide the port number from the url as our network administrator is not aware of this.
    Regards,
    Mahesh

  • I am trying to set up my outlook 2007 account on i pad and the process sticks on verifying.  It would appear to be a problem with outgoing server and I have changed the port number but with no success.

    I have just purchased an i pad 2 and am having trouble with the e-mail set up.  Set up with wi-fi, i-cloud etc has worked fine but the i pad is recognising my outlook 2007 account details but is not verifying it.  The trouble appears to be with the outgoing server and I have tried changing the port number, but to no avail!  Also reset the account settings for holding messages on the server...help!  As you can tell I'm not very techy and I'm desperate to get the bloody thing working as I'm going away on Tuesday! Any suggestions?

    I had a similar issue and it was password case sensitive issue

  • Changing the port number in 10g Discoverer- Middle Tier & Infrasctructural

    Earlier I had insalled 10g discoverer which incudes both Middle Tier & Infrastructural Tier with default port numbers.
    Now i would like to change the default port numbers to other port numbers. This is because , i am got to do another discoverer installation with default port numers.
    In this case i have one question. Is it required to change all the port numbers that exist in the file "portlist.ini" of both Middle Tier & Infrastructural Tier.
    What change still i need to do in Oracle 11i application front.
    Thanks
    Naveen

    I did troubleshooting to verify the group, but this just changed the port number back to the default in the listener.ora & tnsnames.ora.
    So I did all the steps again to change the port number from the default to another - via lsnrctl status, i see that the new port number is being used, I can also log in to the database via Toad using the new port number, in v$parameter i see that the local_listener is registered on the new port number....only under the Fail Safe manager, the port number (under listener parameter) has not changed....it still shows the default port number. Anyone know how to change this???

Maybe you are looking for

  • Manage music and videos manually from more than one computer

    Hello, I'm triying to transfer music from two computers (work computer and home computer) to my iPhone. The problem is that when I select the Manage music and videos manually on my iTunes and then apply it keep saying that the iPhone is already synch

  • Updated (VORowImpl ) values are not reflected in inline POPUP table

    Hi Expert, Currently i am getting exception when i try to update my iterator binding, Here is my use case, I have view object displayed inside the inline popup as a table. When i modify one of the cell i am firing the value change listener and it is

  • 6111 Bluetooth conection

    Greetings. I am a user new to both the 6111 and Bluetooth. I successfully connected yesterday and was able to transfer music files OK. Today I cannot get the PC to detect/connect to my phone. The phone is properly paired and the Bluesoleil device sea

  • Podcast audiobook episodes in reverse order

    I upgraded my iPod Touch software to 2.2, and all of the chapters in my audiobook podcasts are now in reverse order. (They are downloaded from Librivox.) All of the chapters are in correct order on iTunes and when my iPod is hooked up to iTunes, the

  • How to find the outbound idoc function module?(Urgent)

    Dear All, How to identify the outbound function module if there is process code assigned to message type. For partner profile the mesasge type is assigned and idoc type .This is the only information maintained . Now my question is how to identify the