Tomcat Local address E:\soft4develop\apache-tomcat-6.0.18
System.getproperty ("User.dir")//e:\soft4develop\apache-tomcat-6.0.18\bin
System.getproperty ("Catalina.home")//e:\soft4develop\apache-tomcat-6.0.18 also apply to JBoss. No tests were made on other containers.
Here, just a friend in the group asked a question, the situation like this
Login needs to use HTTPS to make the request, after the successful landing, the rest of the other requests all go HTTP.
Like HTTPS://WWW.JB51.NET/ADMIN/USER_MANAGER.APSX.
Find this without having to go to HTTPS and forward to
Http://www.jb51.net/admin/user_manager.apsx
Here's the problem.
Request.getserverport () can only obtain the PORT1 port when HTTPS
So how do I get the Port2 port?
You can get the path to the tomact in the above way, in the XML XPath below to get the
The port configuration in Tomcat's server.xml is spliced to implement.
Methods for getting the tomcat port
Copy Code code as follows:
public static Integer Gettomcatportfromconfigxml (File serverxml) {
Integer Port;
try {
Documentbuilderfactory domfactory = Documentbuilderfactory.newinstance ();
Domfactory.setnamespaceaware (TRUE); Never forget this!
Documentbuilder builder = Domfactory.newdocumentbuilder ();
Document doc = Builder.parse (serverxml);
Xpathfactory factory = Xpathfactory.newinstance ();
XPath XPath = Factory.newxpath ();
XPathExpression expr = Xpath.compile
("/server/service[@name = ' Catalina ']/connector[count (@scheme) =0]/@port [1]");
String result = (string) expr.evaluate (Doc, xpathconstants.string);
Port = result!= null && result.length () > 0? Integer.valueof (Result): null;
catch (Exception e) {
Port = null;
}
return port;
}
Finally with the next system.ge
Copy Code code as follows:
In addition: the string parameters in System.getproperty () are as follows:
System.getproperty () Parameter encyclopedia
# java.version Java Runtime Environment version
# Java.vendor Java Runtime Environment Vendor
# java.vendor.url Java Vendor URL
# java.home Java installation directory
# java.vm.specification.version Java Virtual Machine specification version
# Java.vm.specification.vendor Java Virtual Machine specification vendor
# java.vm.specification.name Java Virtual Machine specification name
# java.vm.version Java Virtual Machine Implementation version
# Java.vm.vendor Java Virtual Machine Implementation Vendor
# 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 Default Temp file path
# Java.compiler Name of JIT compiler to use
# java.ext.dirs Path of extension directory or directories
# Os.name Operating system name
# Os.arch Operating System architecture
# Os.version Operating system version
# file.separator File Separator ("/" on UNIX)
# Path.separator Path Separator (":" On UNIX)
# Line.separator Line Separator ("\ n" on UNIX)
# User.Name user ' s account name
# user.home user ' s home directory
# User.dir user ' s current working directory
File.getcanonicalpath () and File.getabsolutepath () are about just the new File (".") and new File ("..") There is a difference between these two paths.
Copy Code code as follows:
# for the Getcanonicalpath () function, "." Represents the current folder, and the "..." Represents the folder up to the current folder
# for the GetAbsolutePath () function, regardless of ".", "...", return the current path plus the path you set at New File ()
# As for the GetPath () function, you get only the path you set at New File ()
For example, the current path is C:\test:
File directory = new file ("abc");
Directory.getcanonicalpath (); Got a C:\test\abc.
Directory.getabsolutepath (); Got a C:\test\abc.
Direcotry.getpath (); I got ABC.
File directory = new file (".");
Directory.getcanonicalpath (); Got a C:\test.
Directory.getabsolutepath (); Get the C:\test\.
Direcotry.getpath (); Get is.
File directory = new file ("..");
Directory.getcanonicalpath (); Got a c:\.
Directory.getabsolutepath (); Get the C:\test\.
Direcotry.getpath (); Get a..