The value that the System.getproperty () method of 1.java can get
Java.version |
Java Runtime Environment version |
Java.vendor |
Java Runtime Environment Vendor |
Java.vendor.url |
The URL of the Java vendor |
Java.home |
Java installation directory |
Java.vm.specification.version |
Java Virtual Machine Specification version |
Java.vm.specification.vendor |
Java Virtual Machine Specification Provider |
Java.vm.specification.name |
Java Virtual Machine Specification Name |
Java.vm.version |
Java Virtual Machine Implementation version |
Java.vm.vendor |
Java Virtual Machine Implementation Provider |
Java.vm.name |
Java Virtual Machine Implementation name |
Java.specification.version |
Java Runtime Environment Specification version |
Java.specification.vendor |
Java Runtime Environment Specification vendor |
Java.specification.name |
Java Runtime Environment Specification name |
Java.class.version |
Java Class Format version number |
Java.class.path |
Java class Path |
Java.library.path |
List of paths to search when loading libraries |
Java.io.tmpdir |
The default temporary file path |
Java.compiler |
The name of the JIT compiler to use |
Java.ext.dirs |
Path to one or more extended directories |
Os.name |
Name of the operating system |
Os.arch |
Architecture of the operating system |
Os.version |
Version of the operating system |
File.separator |
File delimiter ("/" in UNIX system) |
Path.separator |
Path Delimiter (":" In UNIX system) |
Line.separator |
Row delimiter ("/n" in UNIX system) |
User.Name |
User's account name |
User.home |
User's home directory |
User.dir |
User's current working directory |
2.Java obtains system parameters via System.getproperties ()
Properties props=system.getproperties ();//System Attributes
System.out.println ("Running environment version of Java:" +props.getproperty ("java.version"));
System.out.println ("Running environment provider for Java:" +props.getproperty ("Java.vendor"));
System.out.println ("Java Vendor URL:" +props.getproperty ("Java.vendor.url"));
System.out.println ("Installation path for Java:" +props.getproperty ("Java.home"));
System.out.println ("Java version of the virtual machine specification:" +props.getproperty ("java.vm.specification.version"));
System.out.println ("Virtual machine specification Provider for Java:" +props.getproperty ("Java.vm.specification.vendor"));
System.out.println ("Java Virtual machine Specification Name:" +props.getproperty ("Java.vm.specification.name"));
System.out.println ("virtual machine implementation version of Java:" +props.getproperty ("java.vm.version"));
System.out.println ("Java Virtual machine Implementation provider:" +props.getproperty ("Java.vm.vendor"));
System.out.println ("Java Virtual machine implementation name:" +props.getproperty ("Java.vm.name"));
System.out.println ("Java Runtime Environment Specification version:" +props.getproperty ("java.specification.version"));
System.out.println ("Java Runtime Environment Specification vendor:" +props.getproperty ("Java.specification.vender"));
System.out.println ("Java Runtime Environment Specification name:" +props.getproperty ("Java.specification.name"));
System.out.println ("Java Class format version number:" +props.getproperty ("java.class.version"));
System.out.println ("java classpath:" +props.getproperty ("Java.class.path"));
System.out.println ("List of paths searched when loading library:" +props.getproperty ("Java.library.path"));
System.out.println ("Default temporary file path:" +props.getproperty ("Java.io.tmpdir"));
System.out.println ("path to one or more extended directories:" +props.getproperty ("Java.ext.dirs"));
System.out.println ("Name of the operating system:" +props.getproperty ("Os.name"));
System.out.println ("Architecture of the Operating system:" +props.getproperty ("Os.arch"));
System.out.println ("OS Version:" +props.getproperty ("os.version"));
System.out.println ("File delimiter:" +props.getproperty ("File.separator")); In UNIX systems is "/"
System.out.println ("Path delimiter:" +props.getproperty ("Path.separator")); In a Unix system is ":"
System.out.println ("line delimiter:" +props.getproperty ("Line.separator")); In UNIX systems is "/n"
System.out.println ("User's account name:" +props.getproperty ("User.Name"));
System.out.println ("User's home directory:" +props.getproperty ("User.home"));
System.out.println ("User's current working directory:" +props.getproperty ("User.dir"));
3.
Writing applications accessed through a proxy in Java
This tip will tell you how to write a Java application that can access a Web server on the Internet through a proxy. Adding proxy support to a Java application requires only a few additional lines of code and does not rely on any security "vulnerabilities".
The secret of combining Java and Proxy is to activate specific system properties during Java runtime. These properties are not written to the official file, but are esoteric in Java programmers as part of the Java legend. To support proxies, Java applications need to specify not only the information of the agent itself, but also the user information that is used for authentication. Before you begin to use the Internet Protocol, you need to add the following lines of code to your program:
Notify Java that you want to connect through a proxy
System.getproperties (). Put ("Proxyset", "true");
Specify the server on which the agent resides
System.getproperties (). Put ("ProxyHost", "myproxymachinename");
//Specify the port on which the agent listens
system.getproperties (). Put ("ProxyPort", "no");
Some agents require the user to enter a user name and password before authorizing the user to access the Internet. If you use a Web browser that is located inside a firewall, you may have encountered this situation. Here's how to perform the certification:
urlconnection connection=url.openconnection ();
String password= "Username:password";
String encodedpassword=base64encode (password);
connection.setrequestproperty ("Proxy-authorization", Encodedpassword);
The idea of this piece of code is that you must adjust the HTTP headers to emit user information. This is done by calling Setrequestproperty (). This approach allows you to handle HTTP headers before making a request. HTTP requires the user name and password to be encoded with base64. Fortunately, there is a set of common domain APIs that will perform the encoding on your behalf (see the Reference Resources section).
as you can see, adding proxy support In a Java application does not require much work. With current knowledge, do a little research (you must find out how your agent handles the protocols you are interested in and how you authenticate them), and you can implement proxies with other protocols.
HTTP Proxy: (example)
Properties props = System. getProperties ();
Props.put ("Http.proxyhost", "192.168.0.150");
props.put ("Http.proxyport", "808");
FTP proxy
Scottd.taylor proposes this secret to handle FTP protocol proxies:
defaultproperties.put ("Ftpproxyset", "true");
defaultproperties.put ("Ftpproxyhost", "Proxy-host-name");
defaultproperties.put ("Ftpproxyport", "the");
you can then use the following code to access the file URL using the FTP protocol:
URL url=newurl ("Ftp://ftp.netscape.com/pub/navigator/3.04/windows/readme.txt");
If someone has an example of using other Internet Protocol proxies, I'd like to see it.
Note: The code example (Example.java) was tested only under JDK1.1.4.
follow-up tips!
for developers who are still using JDK1.1.7 (with WebSphere3.0), setting ProxyHost and ProxyPort to System properties does not work; Conn.getinputstream () or returns a connection timeout, Or, the host path could not be found. However, I solved this problem using URL constructors that accept host and port parameters (using my proxy host and port):
Public URL (String protocol,string host,int port,string file).
the method of authenticating with the user name and password does not work. "Basic" should be placed at the beginning of the authentication string, for example:
String encodedpassword=base64encode (password);
should be:
String encodedpassword= "Basic" +base64encode (password);
you do not have to use a separate program for 64-bit encoding. You can use the Sun.misc.BASE64Encoder () class. Here's the code after the two changes are complete:
system.getproperties (). Put ("Proxyset", "true");
system.getproperties (). Put ("ProxyHost", proxyhost);
system.getproperties (). Put ("ProxyPort", proxyport);
String authstring= "Userid:password";
String auth= "Basic" +newsun.misc.base64encoder (). Encode (Authstring.getbytes ());
URL url=newurl ("http://java.sun.com/");
urlconnection conn=url.openconnection ();
conn.setrequestproperty ("Proxy-authorization", auth);
here's how to use the SOCKS4 Proxy server:
system.getproperty ("Socksproxyset", true);
system.getproperty ("Socksproxyhost", proxyhostname);
system.getproperty ("Socksproxyport", proxyport);
usually the ProxyPort for Socks 4 is Port
Java obtains system parameters via System.getproperties ()