Introduction

Welcome to Sams Teach Yourself JavaServer Pages in 21 Days! This book is designed to be as comprehensive—and as accessible—as it is possible for a single book on JavaServer Pages (JSP) to be. It puts JSP to work in depth, pushing the envelope as far as it can go. The best way to learn any topic like JSP is by example, and this is an example-oriented book. You'll find nearly 200 tested examples here, ready to be used.

Few topics are gaining popularity as fast as JSP these days. Web page authors are demanding more and more power, and JSP is the perfect answer. Not content to simply handle Web pages in browsers any more, people are turning to the server side to do things you just can't do in a browser. Using JSP, you have total control over your Web applications—and the big bonus of JSP is that that doesn't mean it's any harder to write those applications than it is a typical Web page. You can do a lot with a little.

JSP is a dazzling package, and you're getting into it at the right time—when the excitement level is high and new developments appear almost daily. This book tries to be true to that spirit and capture as much of the excitement and power of JSP as possible. And you'll see more JSP here than in any comparable book, doing things you won't see other places, such as drawing JPEG images on the fly in the server and then sending them back to the browser.

Who Is This Book For?

This book is for you if you want to really develop all the power that Web applications are capable of. What you'll see here lets you take control of the server side of things. If you want to start using cookies instead of just having your browser accept them, if you want to handle buttons, text fields, check boxes and more in your Web pages, if you want to track users with sessions, or connect to a database on the server, then this is the book for you.

This book is specially written so that you don't need a lot of experience to use it. You don't need to know Java, for example—you'll learn all the Java you need to use JSP in this book, introduced carefully, step by step. The only requirement to read this book is that you're familiar with HTML (and you don't need to be an expert).

What's Inside?

This book is filled with examples—almost 200 of them—because seeing a working example is the best way to learn this material; there's nothing like seeing it work for yourself. You'll see how to put it all to work yourself—here are just a few included topics:

  • Reading data from a Web page's text fields, radio buttons, check boxes, and list boxes on the server

  • Creating and handling image maps

  • Tracking users with sessions and cookies

  • Writing data to files on the server (such as guest books)

  • Recovering from errors without crashing

  • Creating JavaBeans and using them with JSP

  • Connecting to databases on the server

  • Using SQL to work with databases

  • Drawing JPEG images and sending them back to the browser

  • Creating custom JSP tags

  • Using the Struts framework to build applications

  • Writing Java servlets

  • Handling the Model-View-Controller architecture

  • Interacting with XML and XSLT from JSP

  • Writing your own mini-Web server to interact with JSP

  • Intercepting JSP actions with filters

  • Deploying your Web applications using WAR files

  • Creating client/server applications with JavaScript and JSP

  • The complete JSP syntax

You'll also see a summary at the end of each day's work, as well as additional questions and answers, a self-guided quiz, and exercises designed to help hone your skills.

What Do You Need?

All you need to read this book is some knowledge of HTML. You don't need to know Java, or anything about server-side programming. You'll get all the material you need right here.

As far as software goes, you'll see where to download the Tomcat server (the most popular JSP host) used to host the examples in this book at no cost. You'll see how to use Tomcat on your own computer—no Internet access is even needed to be able to run the examples in this book. You can develop and test your JSP pages all on the samecomputer. All you need to do is to download and install the Tomcat server (it's an easy installation, and not intrusive like some big software packages). You'll also need Java (version 1.4 is used in this book), and this book shows you where to get Java (also free).

Day 19 puts the Struts application framework to work, and you'll see where to download Struts at no cost. There's no special installation involved here except unzipping a few files. Days 16 and 17 show how to connect your JSP code to databases, and the examples use Microsoft's SQL Server, but note that you don't have to have that database system to follow along—the Java Database Connectivity (JDBC) techniques you'll see are applicable to any SQL database system (and you'll see where to get such a database system for free on the Internet).

You don't need Internet access to learn JSP from this book. However, if you want to put your JSP code on the Internet, you'll need to use an ISP that supports JSP. Check with your ISP to find if they support JSP—more and more ISPs are doing so every day.

Where to Download the Code for This Book

The code in this book is available for download on the Sams Publishing Web site at http://www.samspublishing.com/. Enter this book's ISBN (without the hyphens) in the Search box and click Search. When the book's title is displayed, click the title to go to a page where you can download the code.

All the code examples have been tested both by the author and two tech editors on different machines. Installing the examples so that Tomcat can run them is very easy—take a look at the readme.txt file that comes with the downloadable code.

Conventions Used in This Book

The following conventions are used in this book:

  • Code lines, commands, statements, variables, and any text you type or see onscreen appears in a monospace typeface.

  • Italics highlight technical terms when they're being defined.

  • The book contains Notes, Tips, and Cautions to help you spot important or useful information more quickly. These often include shortcuts to help you work more efficiently.

  • When introducing new syntax, this book uses the same conventions that both JSP and Java documentation use, for consistency with those sources. In particular, | means “or,” + means “one or more of,” items in bold are default settings, items in italics are placeholders that you fill in later, items in square brackets—[ and ]— are optional, and you must select one item of those that appear in curly braces, { and }. Here's an example:

    <jsp:useBean id="ID" 
        scope="page|request|session|application"
        {
            class="package.class" [ type="package.class" ]|
            beanName="{package.class | <%= expression %>}"
        }
    { /> | > other elements </jsp:useBean> }
    

    Also, when an example is being developed step by step, you'll see the newly added section of code displayed using shaded text to distinguish it from what's already there, like this:

    public void doFilter(ServletRequest request, ServletResponse response, 
        FilterChain chain)
        throws IOException, ServletException
    {
        System.out.println("In ch14_01.");
        chain.doFilter(request, response);
        System.out.println("Leaving ch14_01.");
            .
            .
            .
    }
    

    The three dots arranged vertically indicate that more code is coming.

A Note From the Author

This book is designed to be at the top of its field. If you have comments, please write to me, care of Sams Publishing. This book is designed to be the new standard in JavaServer Pages programming, more complete and more accessible than ever before. Please do keep in touch with ways to improve it and keep it at the forefront. If you think the book lacks anything, let me know—I'll add it in a future printing, because I want to make sure this book stays on top.

And that's it, you're ready to go. Happy programming!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.128.105