"synopsis" may belong to another edition of this title.
The examples themselves are immediately practical. First off, a date-time script--and an example--gives out a random "tip of the day" read from a text file on the server. Then it's on to basic database programming with ADO and ASP. After a quick tour of database basics, readers learn some expert techniques for generating forms based on any database table without changing ASP code. (Not only will you be able to easily generate HTML forms on the fly, you'll also find out how to update databases from forms automatically--again without changing ASP code.) This flexible, "soft" approach to working with databases will help you write ASP code that's a lot easier to maintain.
The book culminates in a full-featured shopping cart example for an e-commerce site. Techniques demonstrated include maintaining state with cookies. Throughout, the book does a fine job of showing how ASPs often work together to get the job done, instead of creating monolithic (and unmaintainable) scripts. For instance, the shopping cart example uses no less than 11 ASP files. (A quick "site map" diagram shows the organization.) Besides the basics, Essential ASP also offers a guide to some best practices, ensuring you'll learn the right way to do things, as well as pick up the basics quickly.
Efficiently packaged, yet filled with some very useful code, this is a truly worthwhile tutorial for ASP development that's exactly what the busy Web professional needs to get started with this powerful standard. --Richard Dragan
Welcome to the book.
This is an ASP cookbook. Each chapter contains one or more recipes that work together in a useful way. Briefly:
Chapter 1 is basically a tutorial, with a couple of very simple scripts that add dates to HTML pages.
Chapter 2 has two recipes: a tip-of-the-day application (a quick and dirty way to add dynamic content to a Web page) and a guest book.
Chapter 3 has a complicated recipe for publishing the contents of a database onto a Web site.
Chapter 4 has a more complicated recipe that creates a Web site that lets you edit the database.
Chapter 5 has a recipe for a shopping cart. It's the most complicated recipe in this book and the one that's most likely to make you some bucks.
Chapter 6 gets simple again with a recipe for e-mail.
Tim Berners-Lee started things off with a great way to publish documents called HTML, which is a wonderful way to publish static documents.
Pretty quickly thereafter, something called CGI was added to Web servers to let programmers generate HTML pages on the fly. With CGI, when the Web server gets a request for page, it starts a program and hands the request to the program. If the program generates any output, that output is returned to the browser.
CGI is a pretty great way to do a lot of things, but it's a very program-ish solution, which is to say it's not very HTML-ish. When you look at a CGI program, most of the time, it doesn't look much like an HTML page, even though that's usually the end result. And if there's a lot of HTML in the program, a lot of the time it has to be carefully wrapped in quotes to separate the program parts from the HTML parts, which can get tiring.Too Many CGI Scripts in the Kitchen
Then there's the performance issues: Most CGI programs are written using scripting languages like Perl, which is ideally suited for this kind of thing.
The problem with this is that every time a Web browser asks for a Web page that's generated by a CGI program, a new process is launched on the server. Launching new processes is kind of slow and takes up a lot of resources. Programs with too many simultaneous CGI programs can get very bogged down.
There are, of course, ways around this, but they involve doing fancy technical things that are a lot harder than writing Perl scripts.
So it became clear that there needed to be an easier way to generate dynamic Web pages.Mixing HTML and Scripts in One Place
The solution that has emerged to the HTML vs. CGI debate is to do both. Increasingly, Web servers are getting smarter, so that it's possible to drop little program snippets inside of Web pages instead of having to maintain programs and HTML separately.
This isn't the end-all, be-all for the Web. Small sites that don't need dynamic content should still be created with HTML.
Very large sites with millions of pages and complicated applications need to be built using complicated publishing systems and application servers.
But for a lot of things, being able to mix HTML and programming is an excellent solution. And that's what ASP is all about.
ASP is probably the best way to mix HTML and simple programming in a Windows environment. ASP pages can also be hosted on a UNIX server, using software from ChiliSoft. But most people use ASP with Windows NT and Windows 2000, because it's built into IIS, it's easy to use, and it's powerful.
ASP is not the only game in town. Other products that let you mix HTML and programming include PHP, Cold Fusion, and JSP. But if you're interested in building dynamic product on the Windows platform, you'll find that ASP is often the first choice for developing dynamic Web sites.How to Add ASP Code to an HTML Page
If you're comfortable with HTML source code, adding ASP to your arsenal will feel like the logical next step.Warning
This book assumes that you are comfortable with HMTL source code. If you are not familiar with HTML source code, you will want to get a good HTML book to refer to while you work with this book.
Let's start with a real simple HTML page called hello_world.html:
If your Web server is IIS (you need IIS or a Web server that supports Active Server Pages for this to work), you can take this file and rename it hello_world.asp:
<% Response.Write("Hello World") %>
Three things have changed:
Instead of ending with .html, the file now ends with .asp. This tells the Web server that there may be some code on the page. Instead of just giving the page to a Web browser when someone types in the URL of the page, the Web server checks the page for <% ... %> tags first. If it finds any, it removes the tags and their contents, and replaces them with the output of any program that is inside of them.
The next piece of code that the server finds (remember that it's looking for <% ... %> tags) is the line <% Response.Write("Hello World") %>. The Response.Write() command is a lot like the print() command in many programming and scripting languages. In the context of ASP, this code tells the server to send the string "Hello World" to the browser.
The net result is that the .asp page and the .html shown above have exactly the same result: a Web page with the words "Hello World" on it.
For the last couple of years, there's been something called ECMA Script that's supposed to be an open protocol that will bring everything back together or something.
Whatever.ASP Objects and Other Useful Objects
One of the tasks that used to be a real hassle in the early CGI days was collecting information from a form. For example, if a form collects a variable called email that contains an e-mail address, you can easily access it with the Request object:email_address = Request("email");
Another fun trick is the ability to redirect a visitor to a different page, using the ASP Response object:Response.Redirect("lovejoy/redirect_page.asp");
which is a lot faster way to redirect someone than using a tag.
As the name implies, ASP objects are collections of logically related methods and properties. The table below lists the most commonly used ASP objects and the purposes they serve.
ASP Object Purpose
Request Manages information about the request that the browser sends to the Web server. Often, the most important element of this request is incoming form information.
Response Manages information that is being sent to the browser in response to the browser's request to the Web server. For example, the Response.Write() command can be used to send HTML to the browser.
Server Manages information that is related to the server. For example, the Server object can be used to find the URL of the current script.
Session Manages information about a user's total visit. For example, if a user looks at five pages when visiting a site, the Session object can be used to keep track of that user as she looks at the five pages.
In addition to objects that are unique to ASP, it is possible to use Microsoft scripting objects from within the ASP environment. For example:
Microsoft Scripting Object Purpose
FileSystem Can be used to read and write information to and from the filesystem, including looking at the contents of existing files and creating new files.
ADODB A database technology that can be used to read and write information stored in databases such as MicrosoftAccess, Microsoft SQL Server, or Oracle.
CDONTS Contains an object called NewMail that can be used tosend email from a script.
Date Does the legwork necessary to work with dates—who has time to keep track of days, months, years, etc...?
Math A variety of useful math tricks such as generatingrandom numbers and rounding off real numbers.
How to Use This Book
This book consists of a series of fully working programs that can usually be set up in a matter of minutes. Unlike CGI scripts, where you often have to worry about permissions and other configuration issues, the ASP scripts in this book can be FTPd to just about any Windows NT or Windows 2000 server (or even a Win95/98 PC with personal Web server installed) and be up and running immediately.
If you're new to Web scripting/programming, it's probably a good idea to use Chapter 1 as a tutorial.
After that, this book can be used as a cookbook: Simply jump directly to the script that looks interesting or otherwise meets your needs, and you should be up and running quickly, whether you're a novice or an experienced programmer working with ASP for the first time.
The appendixes contain reference information on topics that relate in one way or another to getting ASP scripts up and running quickly and easily.Conventions
All code examples are identified by the use of the Courier fixed width font. If there are line numbers next to an example of code:
// Some code examples
// have line numbers next to them.
The code will usually be followed by detailed explanations of how the code works.
Note that, in some cases, a line of code will wrap to the next line. That does not mean that there is a line break in the code! You can generally tell a wrapped line because there is no line number next to the part of the line that has wrapped. Putting a line break where a line wraps can cause some odd behavior that's surprisingly difficult to track down, so be careful with this one. Don't want to worry about line breaks? Don't! Go to the companion Web site and download the code: phptr/essential/.How Chapters Are Structured
Each chapter is structured as follows:
Introduction: Some kind of effort to give you a sense of what the chapter is about.
Source Code: The source code is listed, followed by a detailed description of how it works.
Recap: A brief summary of what was in the chapter.
Advanced Projects: Some ideas on how you could hack the script presented in the chapter.
This book assumes that you've got at least a passing familiarity with HTML. If you haven't worked directly with HTML before, you'll probably want an HTML resource to turn to. Case Sensitivity
"About this title" may belong to another edition of this title.
Book Description Prentice Hall PTR, 2000. Paperback. Book Condition: New. book. Bookseller Inventory # 130304999
Book Description Prentice Hall PTR, 2000. Paperback. Book Condition: New. Bookseller Inventory # DADAX0130304999
Book Description Prentice Hall PTR, 2000. Paperback. Book Condition: New. book. Bookseller Inventory # 0130304999
Book Description Prentice-Hall. Book Condition: New. pp. 304. Bookseller Inventory # 5818128