Beginning JSpm 2 API: From Novice to Professional PETER DEN HAAN, LANCE LAVANDOWSKA, SATHYANARAYANAPANDURANGA, AND KRISHNARAJ PERRUMAL EDITED BYMATTHEWMOODIE APress Media, LLC Beginning Jspm 2 API: From Novice to Professional ISBN978-1-59059-339-4 ISBN978-1-4302-0693-4(eBook) DOI 10.1007/978-1-4302-0693-4 Copyright @2004 by Peter den Haan, Lance Lavandowska, Sathya Narayana Panduranga, and Krishnaraj Perrumal OriginallypublishedbyApressin2004. Allrightsreserved.Nopartofthisworkmaybereprodueedortransmittedinanyform orbyany means,eleetronieormechanicaI,includingphotoeopying,reeording,orbyanyinformationstorage orretrievaIsystem,withoutthe priorwrittenpermissionofthecopyrightownerandthepublisher. Trademarkednamesmayappearinthisbook.Ratherthanuseatrademarksymbolwithevery oeeurreneeofatrademarkedname,weusethenamesonlyinan editorialfashionandtothe benefitofthetrademarkowner, withno intentionofinfringementofthetrademark. Iava>andallIava-basedmarksare trademarksorregisteredtrademarksofSunMicrosystems, Ine.intheUSandothercountries.Apress,Ine.isnotaffiliatedwithSun Microsystems,Ine.,and thisbookwaswrittenwithoutendorsementfrom SunMicrosystems,Ine. LeadEditor:MatthewMoodie TeehnicalReviewers:ScottDavisandMatthewMoodie EditorialBoard:SteveAnglin, DanAppleman,GaryComell,IamesCox,TonyDavis,Iohn Franklin,ChrisMills,SteveRyeroft,DominicShakeshaft.IulianSkinner,[imSumser,Karen Watterson,GavinWray,lohnZukowski ProjeetManager:SofiaMarchant CopyManager:NicoleLeClere CopyEditor: KimWimpsett ProductionManager:KariBrooks ProductionEditor:LauraCheu Compositor:Kinetie PublishingServices,LLC Proofreader:LizWelch Indexer:MichaelBrinkman Artist: KinetiePublishingServices, LLC CoverDesigner:KurtKrames ManufacturingManager:TomDebolski IntheUnitedStates:phoneI-BOO-SPRINGER,[email protected] http://www.springer-ny.com.OutsidetheUnitedStates:fax+496221345229,e-mail [email protected],orvisithttp://www.springer.de. Forinformationon translations,pleasecontactApressdirectlyat2560NinthStreet,Suite219, Berkeley,CA94710.Phone510-549-5930,fax510-549-5939,[email protected],orvisit http://www.apress.com. Theinformationinthisbookisdistributedon an"asis"basis,withoutwarranty.Althoughevery precautionhasbeentakeninthepreparationofthiswork, neithertheauthor(s)norApressshall haveanyliabilitytoanypersonorentitywithrespeettoanyloss ordamageeausedorallegedto be causeddireetlyorindirectlybytheinformationcontainedinthiswork. Thesoureecodeforthisbookisavailabletoreadersat http://www.apress.comintheSourceCode section. Contents at a Glance About the Authors ix About the Editor xi About the Technical Reviewer xiii Introduction xv Chapter 1 Creating Your First JSP Page 1 Chapter 2 Learning How HTML Works 23 Chapter 3 Introducing JSP 61 Chapter 4 Working with Data 87 Chapter 5 Making Decisions, Decisions 125 Chapter 6 Reusing Code 167 Chapter 7 Performing Time Management 207 Chapter 8 Using JSP and XML Together 223 Chapter 9 Going Behind the Scenes 255 Chapter 10 Implementing the Model 2 Architecture and Using Struts 299 Appendix A JSP Syntax Reference 363 Appendix B JSP Implicit Objects 381 Appendix C XML Configuration Files 405 Appendix D Getting More Information 431 Index 441 iii Contents About the Authors ix About the Editor xi About the Technical Reviewer xiii Introduction xv Chapter 1 Creating Your First J5P Page 1 Installing the Software 1 Creating Your First Web Application 9 Exploring aBrief History of Java and the Web 13 Summary 21 Chapter 2 Learning How HTML Works 23 Summarizing HTML 23 Creating HTML Forms 40 Using HTML Elements 43 Finding Further Resources 58 Summary 59 Chapter 3 Introducing J5P 61 Understanding the Available Object Scope 61 Understanding JSP Code Types 62 Using the Java Standard Tag Library (JSTL) 74 Processing Forms with the JSTL 79 Summary 85 Chapter 4 Working with Data 87 Introducing Databases 87 Introducing SQL 97 Manipulating the Database 107 Revisiting the Pizza Application 119 Summary 124 v Contents Chapter 5 Making Deeisions, Deeisions 125 Introducing Arrays 126 Comparing Data Values 133 Using Logical Operators 134 Making Decisions 135 Introducing Conditional Statements 136 Understanding Loops and Iteration 153 Introducing Branching Statements 158 Summary 165 Chapter 6 Reusing Code 167 Introducing Code Reuse 168 Planning for Reuse 169 Understanding Mechanisms for Reuse 179 Going Beyond JSP 189 Summary 205 Chapter 7 Performing Time Management 207 Introducing the Date Class 207 Formatting Dates with the JSTL 215 Summary 221 Chapter 8 Using JSP and XML Together 223 Introducing XML 223 Understanding the Structure of XML Data 225 Defining Validity with Schemas 232 Understanding XSL Transformations 249 Summary 254 Chapter 9 Going Behind the Seenes 255 Web Applications and web.xml 256 Introducing the Java Servlet Technology 263 The Servlet Architecture 266 The Servlet Life Cycle 270 Collaboration Between Servlets 276 Getting Initialization Information 284 vi Contents Filters 288 Summary 297 Chapter 10 Implementing the Model 2 Architecture and Using Struts 299 Architecture of Web Applications 300 The Struts Framework 304 Installing and Configuring Struts 308 The Struts Configuration File 313 Core Struts Components 330 Introducing the Struts Tag Libraries 339 Finishing the View 356 Summary 361 Appendix A JSP Syntax Reference 363 Preliminaries 364 Directives 365 Scripting Elements 369 Standard Actions 371 Tag Libraries 378 Implicit Objects 379 Appendix B JSP Implicit Objects 381 The request Object 382 The response Object 389 The out Object 394 The session Object 397 The application Object 399 The exception Object 402 The config Object 403 The page Object 403 The pageContext Object 403 Appendix CXML Configuration Files 405 Common Elements of web.xml 405 Common Elements of the Tag Library Descriptor 418 Common Elements of the Struts Config File 423 vii Contents Appendix DGetting More Information 431 Java Development Kit Documentation 431 Tomcat and JSP/Servlet Documentation 436 Other Resources 439 Index 441 viii About the Authors Peter den Haan PeterdenHaanisaseniorsystemsengineerat Objectivity Ltd.,aUK-based sys temsintegrationcompany.Hestartedoutprogrammingat 13on aRadioShack TRS-80modelIwith 16KBofmemory, buthe has progressedsince to becomea J2EEsystemsarchitectandlead developerforInternetandintranetprojectsfor customersrangingfrom theUKFootballAssociationPremierLeagueto Shell Finance. Peterhas previouslywrittenthesecurityandcryptographychaptersfor BeginningJavaNetworking. He'saSunCertifiedJava2developer, aJavaRanchbar tender,aself-confessedgeek;he has adoctoratedegree intheoreticalphysics and playsbass inthe localworshipband.Youcan reach hirnat [email protected]. Lance Lavandowska LanceLavandowskahas beenworkingwithJSPsince1998.Hehas contributed to severalApache Jakarta projects,theCastorproject,andtheRollerWeblogger project.Lancehasalsoservedas atechnicalreviewer on severalJSPbooksand was acoauthoronProfessionalJSPSiteDesign. Sathya Narayana Panduranga SathyaNarayanaPandurangaisasoftwaredesignengineerlivinginBangalore, theSoftware CapitalofIndia.Hehas expertisein Microsoft andJavatechnolo giesandhas workedinthedomainsofInternet,telecom, andconvergence.His favorite areasofinterestare distributedandcomponent-basedapplication architecturesandobject-orientedanalysis anddesign.Contributingto arangeof technicalarticlesandbooks isahobbythatgiveshirn theimmensesatisfaction ofsharinghis knowledge.Youcancontacthirn at [email protected]. ix AbouttheAuthors Krishnaraj Perrumal Krishnaraj PerrumalisfounderanddirectorofAdarshSoftech. Hehas success fullydevelopedandmanagedanumberofsoftwareprojectsande-projects, and his programmingexperiencespansthepast15years. Heregularly givespresen tationson Javatechnology,XML,informationsystemssecurity, andaudits. He'saSun Certified JavaProgrammer, aCertified NovellNetWareEngineer, andaCertified InformationSystemsAuditor.Currentlyhe spendsmostofhis timeprovidingconsultancyandsolutionsforcomputersecurity, in additionto Webdevelopment.Helovesto spendallhis freetimewith children,butbeing techsavvy, informationtechnologyconstitutesbothhis professionandhis hobby.YoucancontactKrishnaraj at [email protected]. x
Description: