Chapter 2. Deploying Servlets and JSPs

Introduction

This chapter describes how to take servlets or Java Server Pages (JSPs) and make them available to receive web requests on Tomcat’s servlet container or BEA WebLogic Server 7.0. This discussion begins with deploying servlets and JSPs; in other words, getting them running on Tomcat or WebLogic, either alone or as part of a web application.

Developing and compiling a servlet or JSP within an integrated development environment (IDE) is one thing. Having the web component respond to HTTP requests is another. This is what deployment is all about with web-related software: placing the software into service within a web container like Tomcat or an application server such as BEA WebLogic Server 7.0. The following recipes detail deployment of servlets and JSPs on these web containers, first individually, and then as part of a web application.

The wonderful open source Jakarta Ant build and automation tool is commonly used for this purpose. It is mentioned wherever it is relevant in the following recipes, and Chapter 4 is completely devoted to installing and using Ant.

2.1. Deploying an Individual Servlet on Tomcat

Problem

You want to take a compiled servlet and install it in Tomcat to find out if it is working. You are doing a preliminary test and do not want to take the time to build a complete web application for the servlet.

Solution

Copy and paste the class file into Tomcat’s default web application (or into a web application that you have ...

Get Java Servlet & JSP Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.