How to get Domain Name via JSP?

Discussion in 'Java' started by Ed, May 18, 2004.

  1. Ed

    Ed Guest

    What is the quick and easiest way to get the domain name in JSP?
     
    Ed, May 18, 2004
    #1
    1. Advertisements

  2. What or whose domain name are you talking about?
     
    Christophe Vanfleteren, May 18, 2004
    #2
    1. Advertisements

  3. Ed

    Ed Guest

    I need the domain name when I login into my jsp application. I need the
    domain name of my local network but I don't want to hard code it.
     
    Ed, May 18, 2004
    #3
  4. Ed

    Chris Smith Guest

    request.getServerName()

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, May 18, 2004
    #4
  5. Ed

    Ed Guest

    That only gives me the name of the web server. I need the domain...
     
    Ed, May 18, 2004
    #5
  6. Ed

    Chris Smith Guest

    Then you'll need to clarify what you mean by "domain name". The name
    returned by getServerName() is the name which was looked up via DNS
    (which is the "domain name service") by the client.

    If you want only the domain part of it, the following code will work:

    int index = serverName.indexOf('.');
    if (index == -1) domainName = null;
    else domainName = serverName.substring(index + 1);

    Is that what you want? Or something else?

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, May 18, 2004
    #6
  7. Ed

    Chris Smith Guest

    Oh, you want the name of the client. In that case, try
    request.getRemoteHost() instead.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, May 18, 2004
    #7
  8. Ed

    Ed Guest

    What I'm looking for is the actually name of the domain where a user logs
    onto their network. For example when you log onto your machine at work if
    it is on a windows environment you have a User Name:, Password: and Log on
    to: fields to input. I want to know what is the value that a user inputs
    for the Log on to: field, which should be the domain of the network. I need
    this value for a authentication process.
     
    Ed, May 18, 2004
    #8
  9. Ed

    Chris Smith Guest

    Oh, that's completely different then. You want to know the Windows NT
    network domain. Unfortunately, I don't know how you can find this out.
    You're more likely to have luck hiding your servlets behind IIS, which
    is designed more for these kinds of Microsoft-specific networks than the
    core servlet API.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, May 18, 2004
    #9
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.