Designing Active Server Pages
Total Page:16
File Type:pdf, Size:1020Kb
Designing Active Server Pages Designing Active Server Pages Scott Mitchell Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo Designing Active Server Pages by Scott Mitchell Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Printed in the United States of America. Published by O’Reilly & Associates, Inc., 101 Morris Street, Sebastopol, CA 95472. Editor: Ron Petrusha Production Editor: Mary Sheehan Cover Designer: Edie Freedman Printing History: September 2000: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly & Associates, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly & Associates, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. ActiveX, JScript, Microsoft, Microsoft Internet Explorer, Visual Basic, Visual C++, Windows, and Windows NT are registered trademarks of Microsoft Corporation. The association between the image of a night monkey and the topic of designing Active Server Pages is a trademark of O’Reilly & Associates, Inc. While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. Library of Congress Cataloging-in-Publication Data Mitchell, Scott Designing Active Server Pages/Scott Mitchell p. cm. ISBN 0-596-00044-8 (alk. paper) 1. Active Server Pages. 2. Web sites --Design. 3. Web publishing I. Title. TK5105.8885.A26 M58 2000 005.7'2--dc21 00-062331 ISBN: 0-596-00044-8 [M] About the Author Scott Mitchell is the cofounder of one of the most popular ASP resource destina- tions on the Internet, http://www.4guysfromrolla.com. Originally started as a college project, the site quickly blossomed into a community of serious web developers. 4Guys attracts tens of thousands of experienced ASP developers every day; unlike other communities, it offers a warm welcome and advice for those new to Active Server Pages. In addition to http://www.4guysfromrolla.com, Scott has extensive experience building real-world web sites using Active Server Pages, including building intranet tools for Microsoft’s Office Group. Colophon Our look is the result of reader comments, our own experimentation, and feed- back from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. The animal on the cover of Designing Active Server Pages is a night monkey (Aotus). The night monkey, also known as the owl monkey, is found in South America, specifically in Northern Argentina, Bolivia, Brazil, Colombia, Costa Rica, Equador, Guyana, Panama, Paraguay, Peru, and Venezuela. It lives in trees and subsists on a diet of fruit, leaves, insects, flowers, and bird eggs. As its name suggests, it is nocturnal and in fact, is the only nocturnal member of the monkey species. It is one of the smaller primates; adults usually weigh about two pounds and are about 11–16 inches long. A night monkey’s eyes are larger than any other South American primate’s and are a great asset to their nighttime lifestyle. Night monkeys are monogamous and travel in family packs. The mother cares for a newborn in its first week of life; after that, the father takes over all parental duties except for nursing. The father carries the baby for approximately six months. The baby begins easing more into family play and foraging for food on its own in the second half of its first year. A night monkey reaches maturity between two and three years of age, at which point it leaves its family group and strikes out on its own. Mary Sheehan was the production editor and proofreader for Designing Active Server Pages. Nancy Kotary was the production manager. Ellie Maden was the copyeditor, and Colleen Gorman and Mary Anne Weeks Mayo provided quality control. John Bickelhaupt and Brenda Miller wrote the index. Edie Freedman designed the cover of this book, using an image from Johnson’s Natural History. Emma Colby produced the cover layout with QuarkXPress 4.1 using Adobe’s ITC Garamond font. Alicia Cech and David Futato designed the interior layout based on a series design by Nancy Priest. Mike Sierra implemented the design in FrameMaker 5.5.6. The text and heading fonts are ITC Garamond Light and Garamond Book. The illustra- tions that appear in the book were produced by Robert Romano using Macromedia FreeHand 8 and Adobe Photoshop 5. This colophon was written by Mary Sheehan. Whenever possible, our books use a durable and flexible lay-flat binding. If the page count exceeds this binding’s limit, perfect binding is used. Table of Contents Preface ................................................................................................................... vii 1. Introduction ................................................................................................ 1 What Is Application Design? ............................................................................ 1 What’s Wrong with ASP Design? ..................................................................... 3 Why Hasn’t ASP Design Advanced? ................................................................ 4 What Can Be Done to Improve ASP Design? ................................................. 5 Further Reading .............................................................................................. 18 2. Choosing a Server-Side Scripting Language ................................. 19 The Popularity of VBScript ............................................................................ 19 Specifying the Scripting Language ................................................................ 20 Creating ASP Pages with JScript .................................................................... 25 Creating ASP Pages with PerlScript ............................................................... 31 Creating ASP Pages with Python ................................................................... 37 Further Reading .............................................................................................. 37 3. Exception Handling ............................................................................... 39 A Bit of Terminology ..................................................................................... 40 Detecting When Exceptions Occur ............................................................... 42 Responding to Exceptions ............................................................................. 65 Creating Custom HTTP Error Pages .............................................................. 73 Further Reading .............................................................................................. 77 v Oracle 8i Internal Services for Waits, Latches, Locks, and Memory, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. vi Table of Contents 4. Regular Expressions, Classes, and Dynamic Evaluation and Execution ................................................................................................... 78 Using the RegExp Object ............................................................................... 79 Using Object-Oriented Programming with VBScript .................................... 85 Using Dynamic Evaluation and Execution ................................................... 99 Further Reading ............................................................................................ 103 5. Form Reuse ............................................................................................. 104 The Importance of Code Reuse .................................................................. 104 A Primer on Form Use ................................................................................. 106 Form Validation ............................................................................................ 111 Creating Reusable Server-Side Form Validation Routines .......................... 116 Developing Reusable Form Creation Routines ........................................... 124 The Practicality of Reuse ............................................................................. 136 Further Reading ............................................................................................ 137 6. Database Reuse ..................................................................................... 138 Examining Database Usage ......................................................................... 138 The Building Blocks for Creating Reusable Administration Pages ............ 140 Creating Reusable Administration Pages .................................................... 149 Further Reading ............................................................................................ 246 7. Using Components ............................................................................... 247 COM—A Quick Overview ........................................................................... 248 Lesser-Known Microsoft COM Components ............................................... 249 Enhancing Microsoft’s COM Components .................................................. 275 Building Components .................................................................................. 276 Further Reading ...........................................................................................