• <small id='jvlZb'></small><noframes id='jvlZb'>

    1. <i id='jvlZb'><tr id='jvlZb'><dt id='jvlZb'><q id='jvlZb'><span id='jvlZb'><b id='jvlZb'><form id='jvlZb'><ins id='jvlZb'></ins><ul id='jvlZb'></ul><sub id='jvlZb'></sub></form><legend id='jvlZb'></legend><bdo id='jvlZb'><pre id='jvlZb'><center id='jvlZb'></center></pre></bdo></b><th id='jvlZb'></th></span></q></dt></tr></i><div id='jvlZb'><tfoot id='jvlZb'></tfoot><dl id='jvlZb'><fieldset id='jvlZb'></fieldset></dl></div>
        <bdo id='jvlZb'></bdo><ul id='jvlZb'></ul>
    2. <legend id='jvlZb'><style id='jvlZb'><dir id='jvlZb'><q id='jvlZb'></q></dir></style></legend>
    3. <tfoot id='jvlZb'></tfoot>

        将 JVM/JRE 设置为自动使用 Windows 代理

        Setting JVM/JRE to use Windows Proxy Automatically(将 JVM/JRE 设置为自动使用 Windows 代理)
          <legend id='l0Meh'><style id='l0Meh'><dir id='l0Meh'><q id='l0Meh'></q></dir></style></legend>
        1. <tfoot id='l0Meh'></tfoot>

          <small id='l0Meh'></small><noframes id='l0Meh'>

          • <i id='l0Meh'><tr id='l0Meh'><dt id='l0Meh'><q id='l0Meh'><span id='l0Meh'><b id='l0Meh'><form id='l0Meh'><ins id='l0Meh'></ins><ul id='l0Meh'></ul><sub id='l0Meh'></sub></form><legend id='l0Meh'></legend><bdo id='l0Meh'><pre id='l0Meh'><center id='l0Meh'></center></pre></bdo></b><th id='l0Meh'></th></span></q></dt></tr></i><div id='l0Meh'><tfoot id='l0Meh'></tfoot><dl id='l0Meh'><fieldset id='l0Meh'></fieldset></dl></div>
              • <bdo id='l0Meh'></bdo><ul id='l0Meh'></ul>

                    <tbody id='l0Meh'></tbody>
                1. 本文介绍了将 JVM/JRE 设置为自动使用 Windows 代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我确实看到了有关为 JVM 设置代理的问题,但我想问的是如何利用已配置的代理(在 Windows 上).

                  这是我的问题的演示:

                  <块引用><块引用>

                  1. 转到您的控制面板->Java 并设置代理地址.
                  2. 运行以下简单的小程序代码(我使用的是 Eclipse IDE):

                  导入java.awt.Graphics;导入 javax.swing.JApplet;导入 java.util.*;公共类 Stacklet 扩展 JApplet {私人字符串消息;公共无效初始化(){属性 props = System.getProperties();message = props.getProperty("http.proxyHost", "NONE");message = (message.length() == 0)?无":消息;}公共无效油漆(图形g){g.drawString(消息, 20, 20);}}

                  Applet 显示NONE",与您在 Java 控制面板中放置的设置无关.如果我可以确定 Windows 代理设置(通常在 Internet Explorer 中设置),但在 Java 控制面板中执行额外的配置步骤仍然是可接受的解决方案,那么最好的办法是.

                  谢谢!

                  解决方案

                  可以使用 ProxySelector 类并通过使用 System类的setProperty方法:

                  System.setProperty("java.net.useSystemProxies", "true");System.out.println("检测代理");列表 l = null;尝试 {l = ProxySelector.getDefault().select(new URI("http://foo/bar"));}捕捉(URISyntaxException e){e.printStackTrace();}如果(l!= null){for (Iterator iter = l.iterator(); iter.hasNext();) {java.net.Proxy 代理 = (java.net.Proxy) iter.next();System.out.println("代理类型:" + proxy.type());InetSocketAddress 地址 = (InetSocketAddress) proxy.address();if (addr == null) {System.out.println("无代理");} 别的 {System.out.println("代理主机名:" + addr.getHostName());System.setProperty("http.proxyHost", addr.getHostName());System.out.println("代理端口:" + addr.getPort());System.setProperty("http.proxyPort", Integer.toString(addr.getPort()));}}}

                  I did see the question about setting the proxy for the JVM but what I want to ask is how one can utilize the proxy that is already configured (on Windows).

                  Here is a demonstration of my issue:

                  1. Go to your Control Panel->Java and set a proxy address.
                  2. Run the following simple applet code (I'm using the Eclipse IDE):

                  import java.awt.Graphics;
                  import javax.swing.JApplet;
                  import java.util.*;
                  
                  public class Stacklet extends JApplet {
                      private String message;
                      public void init(){
                          Properties props = System.getProperties();
                          message = props.getProperty("http.proxyHost", "NONE");      
                          message = (message.length() == 0)? "NONE": message;
                      }
                  
                      public void paint(Graphics g)
                      {
                          g.drawString(message, 20, 20);
                      }
                  }
                  

                  The Applet displays "NONE" without regard to the settings you've placed in the Java Control Panel. What would be best would be if the Windows proxy settings (usually set in Internet Explorer) were what I could determine but doing an extra configuration step in the Java Control Panel would still be an acceptable solution.

                  Thanks!

                  解决方案

                  It is possible to detect the proxy using the ProxySelector class and assign the system proxy by assigning environment variables with the setProperty method of the System class:

                  System.setProperty("java.net.useSystemProxies", "true");
                  System.out.println("detecting proxies");
                  List l = null;
                  try {
                      l = ProxySelector.getDefault().select(new URI("http://foo/bar"));
                  } 
                  catch (URISyntaxException e) {
                      e.printStackTrace();
                  }
                  if (l != null) {
                      for (Iterator iter = l.iterator(); iter.hasNext();) {
                          java.net.Proxy proxy = (java.net.Proxy) iter.next();
                          System.out.println("proxy type: " + proxy.type());
                  
                          InetSocketAddress addr = (InetSocketAddress) proxy.address();
                  
                          if (addr == null) {
                              System.out.println("No Proxy");
                          } else {
                              System.out.println("proxy hostname: " + addr.getHostName());
                              System.setProperty("http.proxyHost", addr.getHostName());
                              System.out.println("proxy port: " + addr.getPort());
                              System.setProperty("http.proxyPort", Integer.toString(addr.getPort()));
                          }
                      }
                  }
                  

                  这篇关于将 JVM/JRE 设置为自动使用 Windows 代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bytecode features not available in the Java language(Java 语言中不可用的字节码功能)
                  ClassCastException because of classloaders?(ClassCastException 因为类加载器?)
                  How can I add a Javaagent to a JVM without stopping the JVM?(如何在不停止 JVM 的情况下将 Javaagent 添加到 JVM?)
                  Cannot load 64-bit SWT libraries on 32-bit JVM ( replacing SWT file )(无法在 32 位 JVM 上加载 64 位 SWT 库(替换 SWT 文件))
                  Encourage the JVM to GC rather than grow the heap?(鼓励 JVM 进行 GC 而不是增加堆?)
                  Why a sawtooth shaped graph?(为什么是锯齿形图形?)
                  <i id='vyUpA'><tr id='vyUpA'><dt id='vyUpA'><q id='vyUpA'><span id='vyUpA'><b id='vyUpA'><form id='vyUpA'><ins id='vyUpA'></ins><ul id='vyUpA'></ul><sub id='vyUpA'></sub></form><legend id='vyUpA'></legend><bdo id='vyUpA'><pre id='vyUpA'><center id='vyUpA'></center></pre></bdo></b><th id='vyUpA'></th></span></q></dt></tr></i><div id='vyUpA'><tfoot id='vyUpA'></tfoot><dl id='vyUpA'><fieldset id='vyUpA'></fieldset></dl></div>
                  • <small id='vyUpA'></small><noframes id='vyUpA'>

                      1. <tfoot id='vyUpA'></tfoot>
                          <tbody id='vyUpA'></tbody>
                          <bdo id='vyUpA'></bdo><ul id='vyUpA'></ul>

                            <legend id='vyUpA'><style id='vyUpA'><dir id='vyUpA'><q id='vyUpA'></q></dir></style></legend>