Example #application on #servlet to #database software #communication using Approach 1:
Deploment Directory Structure: (When servlet program uses Type 1 JDBC driver):
Need to add servlet-api.jar into classpath
Deploment Directory Structure: (When servlet program uses Type 4 JDBC driver):
jar file in classpath: #servlet-api.jar, #ojdbc14.jar
jar file in WEB-INF\lib : #ojdbc14.jar
- Type 1 JDBC driver is build-in driver of JDK & every server internally uses JDK so, there is no need of adding any jar files to CLASSPATH, and to WEB-INF\lib folder, if servlet program uses Type 1 JDBC driver to interact with Database software.
- Standalone, desktop application compilation, execution takes place from command prompt, whereas servlet program compilation takes from command prompt & execution takes place from servlet-container.
- if Servlet program of java application uses third party API (other than JSE, JEE api) then the third party API related jar files should be added to classpath and also should be added to WEB-INF\lib folder of webapplication deployment directory struture.
- Eg: if servlet program uses Oracle Thin driver then the Oracle Thin driver related ojdbc14.jar file should be added to CLASSPATH & should be added to WEB-INF\lib folder of web application
Here jar files added to classpath will be used by java compiler to recognize third party API during the compilation of servlet program.
Similarly jar files added WEB-INF\lib folder will be used by servlet-container to recognise & use third party API during the execution of servlet program (jar file added to class path will not be visible/used to servlet container because of that reason
we need to supply seperately third party API in WEB-INF\lib folder)
- jar files added to CLASSPATH enviroment variable are not visible to the containers of web server, application server.
add the ojdbc14.jar to classpath , lib folder
Compile java Servlet
- Since every server gives some built in jar files representing servlet-api & other JEE API so , there is no need of adding servlet-api.jar file to WEB-INF\lib folder of our web application eventhogh our servlet program are using servlet api.
- If multiple web application are deployed in a server are using same third party API then instead of keeping the third party API jar realaed files in WEB-INF\lib folder of every web application, so it is recommended to place in server library folder for only one time i.e. for Tomcat (C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib) is the server library folder of Tomcat server.
- The above recommendation is not good if we want to transfer web application from one server to another server.
- Servlet -container recognizes & uses the the third party API used in servlet programs in the following order
1) In deployed web appn of WEB-INF\classes folder
2) In deployed web appn jar files added to WEB-INF\lib folder
3) The jars placed in server library folder (Tomcat home\lib folder)