2. Obtain the current web root directory:
Public StaticString getwebclassespath ()ThrowsUrisyntaxexception {
String Path = globalparameter.Class. Getresource ("/"). Touri (). getpath ();
ReturnPath;
}
Public StaticString getwebinfpath ()ThrowsIllegalaccessexception, urisyntaxexception {
String Path = getwebclassespath ();
If(Path. indexof ("WEB-INF")> 0 ){
Path = path. substring (0, path. indexof ("WEB-INF") + 8 );
}Else{
Throw NewIllegalaccessexception ("Path retrieval Error");
}
ReturnPath;
}
Public StaticString getwebroot ()ThrowsIllegalaccessexception, urisyntaxexception {
String Path = getwebclassespath ();
If(Path. indexof ("WEB-INF")> 0 ){
Path = path. substring (0, path. indexof ("WEB-INF/classes"));
}Else{
Throw NewIllegalaccessexception ("Path retrieval Error");
}
ReturnPath;
}
@ Test
Public VoidTestpath ()ThrowsIllegalaccessexception, urisyntaxexception {
System. Out. println ("Web class Path ="+ Getwebclassespath ());
System. Out. println ("WEB-INF Path ="+ Getwebinfpath ());
System. Out. println ("Webroot path ="+ Getwebroot ());
}
In the development environment (I am eclipse J2EE + Tomcat 7), eclipse uses a server plug-in to simulate Tomcat services, therefore, the webroot path obtained through the above method is usually D: \ workspace \. metadata \. plugins \ Org. eclipse. WST. server. such as core \ tmp0 \ wtpwebapps \ mystruts \. If a dynamically generated file is to be placed in the web directory, find it here. It seems to be a temporary folder, which has not been carefully studied. (Files first placed under the project webroot will be copied to this temporary directory, so they can all be found)
3. Bidirectional map and bimap. Support key search through value
Google collection is used, which is described here.
Usage
Bimap <string, string> map = hashbimap. Create ();
Map. Put ("Kafka0102","1");
System. Out. println (Map. Get ("Kafka0102"));
System. Out. println (Map. Inverse (). Get ("1");// The output reverse data does not provide a separate function, but needs to call inverse (). Get ()
4. I think so much about it now. I will try again later.