Introduction to Servlets
Concepts
- Understanding the role of servlets
- Building Web pages dynamically
- Looking at servlet code
- Evaluating servlets vs. other technologies
- Understanding the role of JSP
A Servlet’s Job

- Read the data sent by the browser
- Generate the results
- Send the data back to the browser
Why Build Web Pages Dynamically?
- Often, a pre-built, static html page is all you need.
- But, sometimes a page has to be different depending on different factors:
- The Web page is based on data sent by the client
- The Web page is derived from data that changes frequently
- The page uses information from databases
A Quick Peek at Servlet Code
- Let’s look at a TrivialServlet.
- Key points about this code
- It is regular Java code
- It has unfamiliar import statements
- It has some weird thing that looks like this
@WebServlet
- It extends a standard class (HttpServlet)
- It overrides the doGet() method
Advantages of Servlets
- Efficient
- Convenient
- Powerful
- Portable
- Inexpensive
- Secure
- Mainstream