The Web application descriptor file (/WEB-INF/web. xml) can be used to set the creation and reference of resources.
There are three elements used for setting:
L <env-entry>
L <resource-ref>
L <resource-env-ref>
If Tomcat cannot identify the appropriate resource factory, or you need to set other information. You must set the necessary information before creating resources in Tomcat. This information is generally found in $ CATALINA_BASE/conf/server. set in the xml file, preferably in the context setting file for each Web application (META-INF/context. xml. The following elements are used for setting:
L <Environment>
L <Resource>
L <ResourceLink>
L <Transaction>
Resources defined in context. xml do not need to be defined in web. xml. We recommend that you retain the definition in web. xml to demonstrate the resource requirements of web applications.
If resources with the same name are defined in context. xml and web. xml, the override attribute is set to true only in context. xml.
Global settings
The element <GlobalNamingResources> in $ CATALINA_BASE/conf/server. xml is used to set global resources of the server. <ResourceLink> can be used in context. xml of a Web application to include these resources. There is no need to define such resources in web. xml. We recommend that you keep the definition in web. xml to describe the resource requirements of web applications.
Web. xml file example:
<Resource-ref>
<Description>
Resource reference to a factory for java. SQL. Connection
Instances that may be used for talking to a participant
Database that is configured in the <Context>
Login artion for the web application.
</Description>
<Res-ref-name>
Jdbc/EmployeeDB
</Res-ref-name>
<Res-type>
Javax. SQL. DataSource
</Res-type>
<Res-auth>
Container
</Res-auth>
</Resource-ref>
Context. xml file example:
<Context...>
...
<Resource name = "jdbc/EmployeeDB"
Auth = "Container"
Type = "javax. SQL. DataSource"
Username = "dbusername"
Password = "dbpassword"
DriverClassName = "org. hsql. jdbcDriver"
Url = "jdbc: HypersonicSQL: database"
MaxActive = "8"
MaxIdle = "4"/>
...
</Context>