精华内容
下载资源
问答
  • 获取服务器地址

    2014-10-27 14:35:03
    java获取job执行的服务器地址,方便定位问题 可以使用java.net.InetAddress类 InetAddress addr = InetAddress.getLocalHost(); osLoginName = addr.getHostName().toString();  

    java获取job执行的服务器地址,方便定位问题

    可以使用java.net.InetAddress类

    InetAddress addr = InetAddress.getLocalHost();

    osLoginName = addr.getHostName().toString();

     

    展开全文
  • 页面跳转,获取项目路径,获取项目地址,获取端口号,获取项目名称,获取服务器地址 String basePath = "http://" + request.getServerName()// 服务器地址 + ":" + request....
    页面跳转,获取项目路径,获取项目地址,获取端口号,获取项目名称,获取服务器地址



    String basePath = "http://" + request.getServerName()// 服务器地址
    + ":" + request.getServerPort()// 端口号
    + request.getContextPath(); // 项目名称
    response.sendRedirect(basePath + "/tiplogin.html");
    return false;
    展开全文
  • 1

    1原理图

     

     

    2类StaticHostProvider

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements.  See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership.  The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License.  You may obtain a copy of the License at
     * <p>
     * http://www.apache.org/licenses/LICENSE-2.0
     * <p>
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    package org.apache.zookeeper.client;
    
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.net.UnknownHostException;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Collections;
    import java.util.List;
    
    import org.apache.yetus.audience.InterfaceAudience;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    
    /**
     * Most simple HostProvider, resolves only on instantiation.
     */
    @InterfaceAudience.Public
    public final class StaticHostProvider implements HostProvider {
        private static final Logger LOG = LoggerFactory
                .getLogger(StaticHostProvider.class);
    
        private final List<InetSocketAddress> serverAddresses = new ArrayList<InetSocketAddress>(
                5);
        //表示当前正在使用的服务器地址位置
        private int lastIndex = -1;
        //表示循环队列中当前遍历的那个元素位置
        private int currentIndex = -1;
    
        /**
         * Constructs a SimpleHostSet.
         *
         * @param serverAddresses possibly unresolved ZooKeeper server addresses
         * @throws IllegalArgumentException if serverAddresses is empty or resolves to an empty list
         */
        public StaticHostProvider(Collection<InetSocketAddress> serverAddresses) {
            for (InetSocketAddress address : serverAddresses) {
                try {
                    InetAddress ia = address.getAddress();
                    InetAddress resolvedAddresses[] = InetAddress.getAllByName((ia != null) ? ia.getHostAddress() :
                            address.getHostName());
                    for (InetAddress resolvedAddress : resolvedAddresses) {
                        // If hostName is null but the address is not, we can tell that
                        // the hostName is an literal IP address. Then we can set the host string as the hostname
                        // safely to avoid reverse DNS lookup.
                        // As far as i know, the only way to check if the hostName is null is use toString().
                        // Both the two implementations of InetAddress are final class, so we can trust the return value of
                        // the toString() method.
                        if (resolvedAddress.toString().startsWith("/")
                                && resolvedAddress.getAddress() != null) {
                            //serverAddresses为构建的数组
                            this.serverAddresses.add(
                                    new InetSocketAddress(InetAddress.getByAddress(
                                            address.getHostName(),
                                            resolvedAddress.getAddress()),
                                            address.getPort()));
                        } else {
                            this.serverAddresses.add(new InetSocketAddress(resolvedAddress.getHostAddress(), address.getPort()));
                        }
                    }
                } catch (UnknownHostException e) {
                    LOG.error("Unable to connect to server: {}", address, e);
                }
            }
    
            if (this.serverAddresses.isEmpty()) {
                throw new IllegalArgumentException(
                        "A HostProvider may not be empty!");
            }
            //shuffle操作,随机打散
            Collections.shuffle(this.serverAddresses);
        }
    
        public int size() {
            return serverAddresses.size();
        }
    
        public InetSocketAddress next(long spinDelay) {
            ++currentIndex;
            if (currentIndex == serverAddresses.size()) {
                currentIndex = 0;
            }
            /**
             * 如果发现当前游标的位置和上次已经使用的地址位置已经一样,进行spinDelay毫秒等待
             *
             */
            if (currentIndex == lastIndex && spinDelay > 0) {
                try {
                    Thread.sleep(spinDelay);
                } catch (InterruptedException e) {
                    LOG.warn("Unexpected exception", e);
                }
            } else if (lastIndex == -1) {
                // We don't want to sleep on the first ever connect attempt.
                lastIndex = 0;
            }
    
            return serverAddresses.get(currentIndex);
        }
    
        public void onConnected() {
            lastIndex = currentIndex;
        }
    }
    

     

    展开全文
  • java获取服务器地址

    2016-06-29 14:45:28
    摘自:http://blog.csdn.net/wcx11/article/details/5774545 ...ServletActionContext.getRequest().getRemoteHost() ...本应用所在服务器地址: InetAddress myIPaddress=InetAddress.getLocalHost();  

    摘自:http://blog.csdn.net/wcx11/article/details/5774545



    来访者ip

    ServletActionContext.getRequest().getRemoteHost()

    本应用所在服务器地址:

    InetAddress myIPaddress=InetAddress.getLocalHost();
                String mi = myIPaddress.getHostAddress();

    本机ip:

                Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
                while (netInterfaces.hasMoreElements()) {
                    NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
                    InetAddress ip = (InetAddress) ni.getInetAddresses().nextElement();
                    ip.getHostAddress();
                 ///
                }




    展开全文
  • 如题,原本的VPN是可以使用的,更换宽带后换了IP,新的IP使用后登陆提示获取服务端配置信息失败,彻底卸载客户端,重新登陆,还是提示此错误。 处理方法,用IE登陆,登陆成功后会自动下载组件,完成后,可以使用...
  • js获取服务器地址

    千次阅读 2015-01-05 13:39:42
    function getURL(){  var curWwwPath = window.document.location.... //获取主机地址之后的目录,如: test/test/test.htm    var pathName = window.document.location.pathname;  var pos = curWwwPath.in
  • request获取服务器地址

    千次阅读 2015-10-26 16:07:55
    struts2 获取request HttpServletRequest requet=ServletActionContext.getRequest(); requet.getScheme()+"://"+requet.getServerName()+":"+requet.getServerPort() (例如)结果为:...
  • 使用: window.location.host
  • 关于PHP获取服务器地址的方法

    千次阅读 2017-11-06 17:43:52
    1、获取服务器本地地址,最先想到的方法是根据$_SERVER['SERVER_ADDR']。 但在命令行运行程序时,获取就获取不到结果。 php var_dump($_SERVER['SERVER_ADDR']);   网页访问结果:string(14) "172.16.152....
  • 获取服务器地址 C#

    千次阅读 2010-04-25 21:41:00
    Request.ServerVariables["http_host"]可以获取服务器地址,注意,很多地方的都说Request.ServerVariables("http_host")可以,但是,其实如果用()的话,是不可以的,必须使用[] 例如...
  • 一:服务器地址: $host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); <br />二:客户端...
  • java如何获取服务器地址&端口

    千次阅读 2017-07-27 14:41:01
    public static String getLocalPort() throws MalformedObjectNameException{ MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();  Set objectNames = beanServer.queryNames(new Obje
  • 在外网访问通过路由器映射过端口的服务器,或者使用代理访问的时候,request.getServerName()获得的始终是服务器的内网地址,导致外网很多操作无法进行。 原因: request.getServerName()获得的是离服务器最近...
  • HttpServletRequest request = ServletActionContext.getRequest(); String savePath=request.getRealPath("ewmImages")+"/"+time+".jpeg"; String codeInfo=&...+request...
  • JAVA + Struts2获取服务器地址

    千次阅读 2011-08-26 10:02:04
    //访问服务器所带有的参数信息 String queryInfo=request.getQueryString(); if(queryInfo!=null&&(!queryInfo.equals(""))){ actionPath=actionPath+"?"+queryInfo; } logger.debug("用户访问的路径是:"+...
  • uchome的index文件中的二级域名功能判断,使用了php的$_SERVER...在php中,我们一般通过$_SERVER['HTTP_HOST']来活得URL中网站的域名或者ip地址。 php手册中的解释如下: “HTTP_HOST” 当前请求的 Ho
  • uchome的index文件中的二级域名功能判断,使用了php的$_SERVER...在php中,我们一般通过$_SERVER['HTTP_HOST']来活得URL中网站的域名或者ip地址。 php手册中的解释如下: “HTTP_HOST” 当前请求的 Ho
  • 前台获取服务器ip地址

    千次阅读 2019-05-12 16:20:25
    前台获取服务器地址 1.获取当前路径url:var urlName= window.document.location.href; 2.获取当前路径名称:var pathName = window.document.location.pathname; 3.获取http协议长度:var index = urlName.indexOf...
  • 1.通过服务器名称获取IP地址 ping 服务器名称 2. 通过IP地址获取服务器名称 nslookup 160.48.243.122(IP地址)
  • 1、InetAddress ip3 = InetAddress.getByName("tt"); //tt为计算机名称   ip4 = ip3.getHostAddress(); //获取服务器地址 2、InetAddress.getLocalHost().getHostAddress()//获取本地地址
  • 获取服务器下载地址

    2018-12-05 14:29:34
    // 注: 开发环境(获取webpack代理地址)、生产环境(获取线上服务器地址) export function getServerPath () { const http = 'http://' return process.env.NODE_ENV === 'development' ? `${dev.proxyTable['/...
  • 通过js获取 服务器 ip 服务器端口 服务器地址  var address=window.location.href;  thisDLoc = document.location;  var hostport=document.location.host;
  • 获取服务器IP地址

    2008-06-06 11:07:48
    获取HTTP头文件中Host的值: 获取HTTP头文件中accept-encoding的值: 获取客户的IP地址: 获取客户机的名称: ...获取服务器的名称: 获取服务器的端口号: ...
  • PHP cli模式下获取服务器ip地址 背景 PHP写服务的时候只能在cli模式运行,PHP无默认获取服务器ip的方法 解决思路 用PHP来执行shell的 ifconfig 命令来获取网关信息,然后用grep 来匹配出 ip function get_server_ips...
  • 获取当前网络IP和服务器IP地址

    千次阅读 2019-06-04 09:36:46
    获取当前网络IP和服务器IP地址1, 获取当前网络IP2, 获取服务器地址3 ,根据网络接口获取IP地址 1, 获取当前网络IP /** * 获取当前网络ip * @param request * @return */ public static String getIpAddr...
  • 获取服务器地址

    2011-02-16 01:37:00
    有时我们需要获取网站在服务器上运行的详细地址(含端口),使用request.url可以很方便的获取

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 17,401
精华内容 6,960
关键字:

获取服务器地址