Chapter 1. Writing Servlets and JSPs
Introduction
The purpose of this chapter is to bring relative newcomers up to speed in writing, compiling, and packaging servlets and JSPs. If you have never developed a servlet or JSP before, or just need to brush up on the technology to jumpstart your development, then the upcoming recipes provide simple programming examples and an overview of the components that you require on the user classpath to compile servlets.
Recipe 1.1 and Recipe 1.2 provide a brief introduction to servlets and JSPs, respectively. A comprehensive description of a servlet or JSP’s role in the Java 2 Platform, Enterprise Edition (J2EE), is beyond the scope of these recipes. However, information that relates directly to J2EE technology, such as databases and JDBC; using servlets with the Java Naming and Directory Interface (JNDI); and using servlets with JavaMail (or email) is distributed throughout the book (and index!).
The “See Also” sections concluding each recipe provide pointers to closely related chapters, an online tutorial managed by Sun Microsystems, and other O’Reilly books that cover these topics in depth.
1.1. Writing a Servlet
Problem
You want to write a servlet that is part of a web application.
Solution
Create
a Java class that extends
javax.servlet.http.HttpServlet.
Make sure to import the
classes from servlet.jar
(or servlet-api.jar)—you’ll
need them to compile the
servlet.
Discussion
A servlet is a Java class that is designed to respond with dynamic content ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access