Intro to Servlets Lec 26
Web-Based Enterprise Applications in Java Figure shows a simplified view of one application and its layers.
Java Servlets Client/ browser Server Request Response Servlet JVM Extends the functionality of the server by Generating HTML pages dynamically
What Do They Do? Anything that java can do (e.g. connect to database services) Handle data/requests sent by users (clients) Create and format results Send results back to user
Java Servlets Advantages over other SSP technologies: Can use the Java APIs e.g. JDBC. Persistent between invocations, avoiding process instantiations. Portable across operating systems and servers. Good security. Is integrated closely with the J2EE environment.
Software Requirements
To use Java servlets, following softwares will be needed J2SE Additional J2EE based libraries for servlets such as servlet-api.jar, jsp-api.jar. You can download these APIs separately but they are also available with the web server you’ll be using. A capable servlet web engine (web server)
Jakarta Servlet Engine (Tomcat) Jakarta is an Apache project Tomcat is one of its subprojects Tomcat is the official reference implementation for the Java servlet and JavaServer pages technologies (according to Sun’s specifications) Tomcat is developed in an open and participatory environment and released under the Apache software license
Environment Setup
Steps 1. Download the Apache Tomcat Server 2. Install Tomcat 3. Set the JAVA_HOME variable 4. Set the CATALINA_HOME variable 5. Set the CLASSPATH variable 6. Test the Server
1.Download the Apache Tomcat Server From the Download the zip file for the current release of Jakarta Tomcat For windows, there is also a.exe installer
2.Install Tomcat Installing.zip file Unzip the file into a location (e.g. C:\) The zip file had embedded subdirectories (e.g., jakarta-tomcat ). C:\ jakarta-tomcat generally referred as install_dir Installing.exe file Check the handouts
3.Set the JAVA_HOME variable Set the JAVA_HOME environment variable to tell Tomcat where to find Java This variable should list the base JDK installation directory, not the bin subdirectory JAVA_HOME = c:\j2sdk1.5.0
4.Set the CATALINA_HOME variable Set the CATALINA_HOME environment variable to refer to the top-level directory of the Apache Tomcat installation, not the bin subdirectory CATALINA_HOME = c:\jakarta-tomcat-5.5.9
5.Set the CLASSPATH variable Since servlets and JSP are not part of the J2SE, javac doesn’t know about the servlet and jsp classes The standard Tomcat locations for these files are install_dir/common/lib/servlet-api.jar install_dir/common/lib/jsp-api.jar You need to include both files in your CLASSPATH
6.Test the Server Before making your own Servlets and JSP, verify that the server can start Run install_dir/bin/startup.bat Enter the URL in your browser and make sure you will get the Tomcat homepage
Lets do it LIVE
Tomcat Directory Structure my-app