Chapter 3

Using JavaServer Pages

IN THIS CHAPTER

check Seeing how servlets work

check Dealing with page directives

check Trying out expressions

check Putting scriptlets to work

check Devising declarations

check Comprehending classes

In Book 7, Chapter 2, you discover how to create servlets that write HTML data directly to a page by using the PrintWriter object accessed through response.out. Although this technique works, it has one major drawback: You have to compose the HTML manually as a bunch of string literals. If the HTML has an error, you don’t know about it until you run the servlet to see how it looks. Also, handcrafting HTML in out.println statements certainly isn’t the most efficient way to create attractive web pages.

That’s where JavaServer Pages (a technology usually called JSP for short) comes in. A JavaServer Page is an HTML file that has Java servlet code embedded in it in special tags. When you run a ...

Get Java All-in-One For Dummies, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.