I. Gets the initialization parameters for the tomcat context.
1. Gets the initialization parameters for the context set in Tomcat's Server.xml.
For example:
Copy Code code as follows:
<context path= "/testcontext" docbase= "/context"
Privileged= "true" antiresourcelocking= "false" antijarlocking= "false"
debug= "0" reloadable= "true" >
<parameter name= "name" value= "Yangqisheng"/>
</Context>
Mode: Getservletcontext (). Getinitparameter (String name)
2. Gets the initialization parameters for setting the context in the Web.xml under the project.
For example:
Copy Code code as follows:
<context-param>
<param-name>age</param-name>
<param-value>24</param-value>
</context-param>
Mode: Getservletcontext (). Getinitparameter (String name)
Second, record Tomcat log
1. Set up log files
In the Server.xml file, use the logger element to set up the log file.
Copy Code code as follows:
<logger classname= "Org.apache.catalina.logger.FileLogger"
Prefix= "Localhost_log." suffix= ". txt" timestamp= "true"/>
Write log: This.getservletcontext (). log ("test")
Third, access to resource files
3.1 GetResource (String Parh) method where path must be/start representing the root directory of the current Web application. Returns a URL object that represents a resource.
3.2 Getresoutceasstream (String Parh), returns the file stream. The advantage is that you can access all the files in the Web directory using a path relative to the root directory without having to know the absolute path.
For example, under Web-inf, create a new file me.properties, which reads:
Name=yangqisheng
Age=25
Copy Code code as follows:
This.getservletcontext (). getResourceAsStream ("/web-inf/me.properties");
Properties me = new properties ();
Me.load (IS);
Out.write (Me.getproperty ("name"));
Out.write (Me.getproperty ("Age"));
Then execute in the servlet:
Will print out the Yangqisheng25