Kĩ thuật lập trình - Chương 26: Web applications: Part 1
Java Studio Creator 2 can automatically import any missing packages your Java file needs. For example, after adding the Properties object to Options.java, you can right click in the Java editor window and select Fix Imports to automatically import java.util.Properties.
145 trang |
Chia sẻ: huyhoang44 | Lượt xem: 751 | Lượt tải: 0
Bạn đang xem trước 20 trang tài liệu Kĩ thuật lập trình - Chương 26: Web applications: Part 1, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
26Web Applications:Part 11If any man will draw up his case, and put his name at the foot of the first page, I will give him an immediate reply. Where he compels me to turn over the sheet, he must wait my leisure.Lord SandwichRule One: Our client is always right Rule Two: If you think our client is wrong, see Rule One.Anonymous2A fair question should befollowed by a deed in silence.Dante AlighieriYou will come here and get books that will open your eyes, and your ears, and your curiosity, and turn you inside out or outside in.Ralph Waldo Emerson3OBJECTIVESIn this chapter you will learn: Web application development using Java Technologies and Java Studio Creator 2.0.To create JavaServer Pages with JavaServer Faces components.To create web applications consisting of multiple pages.To validate user input on a web page.To maintain state information about a user with session tracking and cookies.426.1 Introduction26.2 Simple HTTP Transactions26.3 Multitier Application Architecture26.4 Java Web Technologies 26.4.1 Servlets 26.4.2 JavaServer Pages 26.4.3 JavaServer Faces 26.4.4 Web Technologies in Java Studio Creator 226.5 Creating and Running a Simple Application in Java Studio Creator 2 26.5.1 Examining a JSP File 26.5.2 Examining a Page Bean File 26.5.3 Event-Processing Life Cycle 26.5.4 Relationship Between the JSP and Page Bean Files5 26.5.5 Examining the XHTML Generated by a Java Web Application 26.5.6 Building a Web Application in Java Studio Creator 226.6 JSF Components 26.6.1 Text and Graphics Components 26.6.2 Validation Using Validator Components and Custom Validators26.7 Session Tracking 26.7.1 Cookies 26.7.2 Session Tracking with the SessionBean Object26.8 Wrap-Up26.9 Web Resources626.1 IntroductionWeb-based applications create web content for web browser clientsAJAX—provides interactivity and responsiveness users typically expect of desktop applications726.2 Simple HTTP TransactionsHypertext Transfer Protocol (HTTP) set of methods and headers that allow clients and servers to interact and exchange informationSimple web page Typically an XHTML document Contains markup that describes to a web browser how to display the documentHypertext data (hyperlinks) link to different pages or to other parts of the same page when the user clicks the link826.2 Simple HTTP TransactionsURIs (Uniform Resource Identifiers) Identify data on the InternetThose that specify the locations of documents are called URLs (Uniform Resource Locators) Common URLs refer toFiles Directories Objects that perform complex tasksURL directs a browser to the resource (hosted on a web server) that the user wishes to access926.2 Simple HTTP TransactionsHTTP GET method indicates that the client wishes to obtain a resource from the serverHTTP headers provide information about the data sent to a client, such as the MIME typeMultipurpose Internet Mail Extensions (MIME) Internet standard that specifies data formats so that programs can interpret data correctly10Fig. 26.1 | Client interacting with web server. Step 1: The GET request. 11Fig. 26.2 | Client interacting with web server. Step 2: The HTTP response. 1226.3 Multitier Application ArchitectureWeb-based applications are multitier (or n-tier) applications that divide functionality into separate tiers that typically reside on separate computersBottom tier Also called the data tier or the information tierMaintains the application’s dataTypically stores data in a relational database management system (RDBMS)Middle tier Implements business logic, controller logic and presentation logic Acts as an intermediary between data in the information tier and the application’s clientsController logic processes client requests and retrieves data from the databasePresentation logic processes data from the information tier and presents the content to the client1326.3 Multitier Application ArchitectureWeb applications typically present data to clients as XHTML documents.Business logic in the middle tierenforces business rules ensures that data is reliable before the server application updates the database or presents the data to usersBusiness rules dictateHow clients can and cannot access application dataHow applications process dataTop tierAlso called client tierThe application’s user interface, which gathers input and displays outputUsers interact with the application through the user interface, typically in a web browser. 1426.3 Multitier Application ArchitectureIn response to user actionsClient tier interacts with middle tier to make requests and to retrieve data from information tierClient tier then displays data retrieved for the userClient tier never directly interacts with the information tier15Fig. 26.3 | Three-tier architecture. 1626.4 Java Web TechnologiesContinually evolve to provide developers with higher levels of abstraction and greater separation of the application’s tiersSeparation makes web applications more maintainable and extensibleJava Studio Creator 2 Drag-and-drop web-application GUI developmentBusiness logic placed in separate Java classes1726.4.1 ServletsUse the HTTP request-response model of communication between client and serverExtend a server’s functionality by allowing the server to generate dynamic contentServlet container executes and interacts with servletsPackages javax.servlet and javax.servlet.http contain the servlet classes and interfaces. 1826.4.1 ServletsServlet container Receives HTTP requests from clientsDirects each request to the appropriate servletServlet processes the request and returns response to the client—typically an XHTML or XML documentServlets implement the Servlet interface of package javax.servletEnsures that each servlet can execute in the framework Declares methods used by the servlet container to manage the servlet’s life cycle 1926.4.1 ServletsServlet life cycle Begins when the servlet container loads it into memory—usually in response to the first request for the servletinit methodCalled only once by container during a servlet’s life-cycle to initialize the servletservice methodCalled once per requestReceives the requestProcesses it Sends a response to the clientdestroy methodCalled to release any resources held by the servlet when container terminates servlet 2026.4.2 JavaServer PagesExtension of servlet technologyEach JSP is translated by the JSP container into a servletHelp separate presentation from contentHelp web application programmers create dynamic content By reusing predefined components By interacting with components using server-side scripting2126.4.2 JavaServer PagesJavaBeans and custom tag libraries encapsulate complex, dynamic functionalityCustom tag libraries Allow Java developers to hide code for database access and other complex operations in custom tagsEnable web-page designers who are not familiar with Java to enhance web pages with powerful dynamic content and processing capabilitiesThe JSP classes and interfaces are located in packages javax.servlet.jsp and javax.servlet.jsp.tagext.2226.4.2 JavaServer PagesFour key components DirectivesActionsScripting elements Tag librariesDirectives Messages to the JSP container Specify page settingsInclude content from other resources Specify custom tag libraries for use in JSPsActions Encapsulate functionality in predefined tags Often are performed based on the information sent to the server as part of a particular client requestCan create Java objects for use in JSPs2326.4.2 JavaServer PagesScripting elements Insert Java code that interacts with components in a JSP to perform request processingTag libraries Enable programmers to create custom tags Enable web-page designers to manipulate JSP content without prior Java knowledgeJavaServer Pages Standard Tag Library (JSTL) Provides many common web application tasksStatic content XHTML or XML markupKnown as fixed-template data or fixed-template textLiteral text is translated to a String literal in the servlet representation of the JSP2426.4.2 JavaServer PagesFirst request for a JSPContainer translates the JSP into a servletServlet handles the current and future requests to the JSPJSPs rely on the same request/response mechanism as servlets to process requests from and send responses to clients25Performance Tip 26.1Some JSP containers translate JSPs into servlets at the JSP’s deployment time (i.e., when the application is placed on a web server). This eliminates the translation overhead for the first client that requests each JSP, as the JSP will be translated before it is ever requested by a client.2626.4.3 JavaServer FacesWeb application framework Simplifies the design of an application’s user interface Further separates a web application’s presentation from its business logicFramework Simplifies application development by providing libraries and sometimes software tools to help you organize and build your applications2726.4.3 JavaServer FacesJSF custom tag libraries Contain user interface components that simplify web-page designIncludes a set of APIs for handling component eventsYou design the look-and-feel of a page with JSF by adding custom tags to a JSP file and manipulating their attributesYou define the page’s behavior in a separate Java source-code file.2826.4.4 Web Technologies in Java Studio Creator 2Java Studio Creator 2 web applications Consist of one or more JSPs built in the JavaServer Faces frameworkEach has the file-name extension .jsp and contains the web page’s GUI elementsJava Studio Creator 2 allows you to Design pages visually by dragging and dropping JSF components onto a page; Customize a web page by editing its .jsp file manuallyEvery JSP file created in Java Studio Creator 2 represents a web page and has a corresponding JavaBean class called the page bean2926.4.4 Web Technologies in Java Studio Creator 2JavaBean class must have Default (or no-argument) constructorget and set methods for all of its properties.page bean Defines properties for each of the page’s elementsEvent handlersPage life-cycle methods Other supporting code for the web application Every web application built with Java Studio Creator 2 has a page bean, a RequestBean, a SessionBean and an ApplicationBean3026.4.4 Web Technologies in Java Studio Creator 2RequestBean Request scopeExists only for the duration of an HTTP requestSessionBean Session scopeExists throughout a user’s browsing session or until the session times outUnique SessionBean object for each userApplicationBean Application scopeShared by all instances of an application Exists as long as the application remains deployed Application-wide data storage or processingOne instance exists, regardless of the number of open sessions3126.5 Creating and Running a Simple Application in Java Studio Creator 2Static Text components display text that cannot be edited by the user32OutlineTime.jsp (1 of 2 ) Tag libraries available for use in this web applicationConfigure head section of web page33OutlineTime.jsp (2 of 2 ) Set up a Static Text element3426.5.1 Examining a JSP FileJava Studio Creator 2 generates a JSP file in response to your interactions with the Visual EditorAll JSPs have a jsp:root element version attribute indicates the version of JSP being usedOne or more xmlns attributes. Each xmlns attribute specifies a prefix and a URL for a tag library, allowing the page to use tags specified in that library. All JSPs generated by Java Studio Creator 2 include the tag libraries for JSF core components libraryJSF HTML components libraryJSP standard components library JSP user interface components library3526.5.1 Examining a JSP FileThe jsp:directive.page elementcontentType attribute specifies the MIME type and the character set the page usespageEncoding attribute specifies the character encoding used by the page sourceThese attributes help the client determine how to render the contentAll pages containing JSF components are represented in a component tree with the root JSF element f:view (of type UIViewRoot)All JSF component elements are placed in this elementMany ui page elements have a binding attribute to bind their values to properties in the web application’s JavaBeansJSF Expression Language is used to perform these bindings.3626.5.1 Examining a JSP Fileui:head element title attribute that specifies the page’s titleui:link element can be used to specify the CSS stylesheet used by a pageui:body element defines the body of the pageui:form element defines a form in a page.ui:staticText component displays text that does not change3726.5.1 Examining a JSP FileJSP elements are mapped to XHTML elements for rendering in a browserCan map to different XHTML elements, depending on the client browser and the component’s property settingsui:staticText component Typically maps to an XHTML span elementA span element contains text that is displayed on a web page and is used to control the formatting of the textstyle attribute of ui:staticText represented as part of the corresponding span element’s style attribute38Fig. 26.5 | Sample JSF component tree. 3926.5.2 Examining a Page Bean FilePage bean classes Inherit from class AbstractPageBean (package com.sun.rave.web.ui.appbaseProvides page life-cycle methodsPackage com.sun.rave.web.ui.component includes classes for many basic JSF componentsA ui:staticText component is a StaticText object (package com.sun.rave.web.ui.component).40OutlineTime.java (1 of 8 ) 41OutlineTime.java (2 of 8 ) 42OutlineTime.java (3 of 8 ) 43OutlineTime.java (4 of 8 ) 44OutlineTime.java (5 of 8 ) Code that was inserted by the designer to create a StaticText object45OutlineTime.java (6 of 8 ) 46OutlineTime.java (7 of 8 ) 47OutlineTime.java (8 of 8 ) Programmatically change the text in the StaticText object4826.5.3 Event-Processing Life CycleJava Studio Creator 2’s application model Places methods init, preprocess, prerender and destroy in the page bean that tie into the JSF event-processing life cycleThese represent four major stages—initialization, preprocessing, prerendering and destructioninit method Called by the JSP container the first time the page is requested and on postbacksPostback occurs when form data is submitted, and the page and its contents are sent to the server to be processedinvokes its superclass version, then tries to call the method _init, which handles component initialization tasks4926.5.3 Event-Processing Life Cyclepreprocess method Called after init, but only if the page is processing a postbackprerender method Called just before a page is rendered by the browserShould be used to set component propertiesdestroy method Called after the page has been rendered, but only if the init method was calledHandles tasks such as freeing resources used to render the page5026.5.4 Relationship Between the JSP and Page Bean FilesPage bean has a property for every element that appears in the JSP file5126.5.5 Examining the XHTML Generated by a Java Web ApplicationTo create a new web applicationFile > New Project Select Web in the Categories paneSelect JSF Web Application in the Projects paneClick NextSpecify the project name and locationClick Finish to create the web application projectSingle web page named Page1 created and opened by default in the Visual Editor in Design mode when the project first loadsDesign mode shows how your page renders in abrowser The JSP file for this page, named Page1.jsp, can be viewed by clicking the JSP button at the top of the Visual Editor, orright clicking anywhere in the Visual Editor and selecting Edit JSP Source. 5226.5.5 Examining the XHTML Generated by a Java Web ApplicationPreview in Browser button at the top of the Visual Editor window allows you to view your pages in a browser without having to build and run the applicationThe Refresh button redraws the page in the Visual EditorThe Target Browser Size drop-down list allows you to specify the optimal browser resolution for viewing the page and allows you to see what the page will look like in different screen resolutions5326.5.5 Examining the XHTML Generated by a Java Web ApplicationProjects window displays the hierarchy of all the project’s filesWeb Pages node contains the JSP files and includes the resources folder, which contains the project’s CSS stylesheet and any other files the pages may need to display properly (e.g., images)The Java source code, including the page bean file for each web page and the application, session and request scope beans, can be found under the Source Packages nodePage Navigation file Defines rules for navigating the project’s pages5426.5.5 Examining the XHTML Generated by a Java Web ApplicationMethods init, preprocess, prerender and destroy are overridden in each page beanServe as placeholders for you to customize the behavior of your web applicationRename the JSP and Java files in your project, so that their names are relevant to your applicationRight click the JSP file in the Projects Window Select Rename to display the Rename dialogEnter the new file nameIf Preview All Changes is checked, the Refactoring Window will appear at the bottom of the IDE when you click Next >No changes will be made until you click Do Refactoring in the Refactoring Window. If you do not preview the changes, refactoring occurs when you click Next > in the Rename dialog. 5526.5.5 Examining the XHTML Generated by a Java Web ApplicationRefactoring the process of modifying source code to improve its readability and reusability without changing its behaviorExamples: renaming methods or variables, breaking long methods into shorter onesJava Studio Creator 2 has built-in refactoring tools that automate some refactoring tasksTitle property specifies JSPs titleComponents are rendered using absolute positioningJava Studio Creator 2 is a WYSIWYG (What You See Is What You Get) editorOutline window displays the page bean and the request, session and application scope beansClicking an item in the page bean’s component tree selects the item in the Visual Editor5626.5.5 Examining the XHTML Generated by a Java Web ApplicationTo build and run applicationSelect Build > Build Main Project Select Run > Run Main ProjectIf changes are made to a project, the project must be rebuilt before the changes will be reflected when the application is viewed in a browser F5build an application, then run it in debug mode F5 Program executes without debugging enabled.57OutlineTime.html (1 of 2 ) 58OutlineTime.html (2 of 2 ) HTML code that was generated for a StaticText object59Fig. 26.8 | Visual Editor window in Design mode. 60Fig. 26.9 | Palette in Java Studio Creator 2. 61Fig. 26.10 | Projects window for the WebTime project. 62Fig. 26.11 | JSP file generated for Page1 by Java Studio Creator 2. 63Fig. 26.12 | Page bean file for Page1.jsp generated by Java Studio Creator 2. 64Fig. 26.13 | Time.jsp after inserting the first Static Text component. 65Fig. 26.14 | Time.jsp after adding the second Static Text component. 66Fig. 26.15 | Outline window in Java Studio Creator 2. 67Error-Prevention Tip 26.1If you have trouble building your project due to errors in the Java Studio Creator-generated XML files used for building, try cleaning the project and building again. You can do this by selecting Build > Clean and Build Main Project or by pressing B.6826.6 JSF Components69Fig. 26.16 | Commonly used JSF components. 7026.6.1 Text and Graphics ComponentsGrid Panel component Designer can specify number of columns the grid should containDrop components anywhere inside the panelThey’ll automatically be repositioned into evenly spaced columns in the order in which they are droppedWhen the number of components exceeds the number of columns, the panel moves the additional components to a new rowImage component Inserts an image into a web pageImages must be placed in the project’s resources folderUse url property to specify the image to display7126.6.1 Text and Graphics ComponentsText FieldUsed to obtain text input from the userComponent’s JSP tags are added to the JSP file in the order they are added to the page. Tabbing between components navigates the components in the order in which the JSP tags occur in the JSP fileTo specify navigation orderDrag components onto the page in appropriate order, or Set each input field’s Tab Index property; tab index 1 is the first in the tab sequence7226.6.1 Text and Graphics ComponentsDrop Down List displays a list from which the user can make a selectionTo configure, right click the drop-down list in Design mode and select Configure Default OptionsHyperlink Adds a link to a web pageurl property specifies the linked resourceRadio Button Group Provides a series of radio buttons Edit options by right clicking the component and selecting Configure Default OptionsButton Triggers an action when clickedTypically maps to an input XHTML element with attribute type set to submit.73OutlineWebComponents .jsp (1 of 5 ) 74OutlineWebComponents .jsp (2 of 5 ) Designer generated code for ImageDesigner generated code for Grid PanelDesigner generated code for Text Field75OutlineWebComponents .jsp (3 of 5 ) Designer generated code for Drop Down ListDesigner generated code for Hyperlink76OutlineWebComponents .jsp (4 of 5 ) Designer generated code for Radio Button GroupDesigner generated code for Button77OutlineWebComponents .jsp (5 of 5 ) 7826.6.2 Validation Using Validator Components and Custom ValidatorsValidation Helps prevent processing errors due to incomplete or improperly formatted user input.Length Validator Determines whether a field contains an acceptable number of charactersDouble Range Validators and Long Range ValidatorsDetermine whether numeric input falls within acceptable rangesPackage javax.faces.validators contains the validator classes7926.6.2 Validation Using Validator Components and Custom ValidatorsLabel componentDescribes another component Can be associated with a user input field by setting its for propertyMessage componentDisplays an error message when validation failsTo associate a Label or Message component with another component, hold the Ctrl and Shift keys, then drag the Label or Message to the appropriate component8026.6.2 Validation Using Validator Components and Custom ValidatorsSet the required property of a component to ensure that the user enters data for it. An input field’s required property must be set to true for validation to occurIn the Visual Editor the label for a required field is automatically marked by a red asterisk.If a user submits a form with a missing required field, the default error message for that field will be displayed in its associated ui:message component8126.6.2 Validation Using Validator Components and Custom ValidatorsTo edit a Double Range Validator’s or a Long Range Validator’s propertiesClick its node in the Outline window in Design modeSet the maximum and minimum properties in the Properties windowCan limit user input length using validation Set a Text Field’s maxLength property8226.6.2 Validation Using Validator Components and Custom ValidatorsTo ensure properly formatted inputCan match input against a regular expression No built in regular expression, but you can add your own custom validator methods to the page bean file Add a custom validator methodRight click the appropriate input componentSelect Edit Event Handler > validate to create a validation method in the page bean file83OutlineValidation.jsp (1 of 6 ) 84OutlineValidation.jsp (2 of 6 ) Specifies the validator for the name Text FieldSpecifies the validator for the email Text FieldSpecifies the validator for the phone number Text Field85OutlineValidation.jsp (3 of 6 ) 86OutlineValidation.jsp (4 of 6 ) 87OutlineValidation.jsp (5 of 6 ) 88OutlineValidation.jsp (6 of 6 ) 8926.7 Session TrackingPersonalization Makes it possible for e-businesses to communicate effectively with their customers Improves the user’s ability to locate desired products and servicesPrivacySome consumers embrace the idea of tailored contentOthers fear the possible adverse consequences if the information they provide to e-businesses is released or collected by tracking technologies9026.7 Session TrackingTo provide personalized services, must be able to recognize clientsHTTP is a stateless protocolIt does not support persistent connections that would enable web servers to maintain state information regarding particular clientsTo help the server distinguish among clients, each client must identify itself to the serverTracking individual clients CookiesSessionBean object9126.7 Session TrackingOther tracking methods"hidden" form elementsA web form can write session-tracking data into a form When the user submits the form, all the form data, including the "hidden" fields, is sent to the form handler on the web serverURL rewritingWeb server embeds session-tracking information directly in the URLs of hyperlinks that the user clicks to send subsequent requests9226.7.1 CookiesCookie A piece of data typically stored in a text file on the user’s computerMaintains information about the client during and between browser sessionsWhen a user visits the website, the user’s computer might receive a cookieThis cookie is then reactivated each time the user revisits that siteHTTP-based interactions between a client and a serverIncludes a header containing information either about the request (when the communication is from the client to the server) or about the response (when the communication is from the server to the client)9326.7.1 CookiesIn a request, the header includes Request type Any cookies that have been sent previously from the server to be stored on the client machineIn a response, the header includesAny cookies the server wants to store on the client computer Other information, such as the MIME type of the responseExpiration date determines how long the cookie remains on the client’s computerIf not set, the web browser maintains the cookie for the browsing session’s duration9426.7.1 CookiesSetting the action handler for a Hyperlink enables you to respond to a click without redirecting the user to another pageTo add an action handler to a Hyperlink that should also direct the user to another pageAdd a rule to the Page Navigation fileRight click in the Visual Designer and select Page Navigation, then drag the appropriate Hyperlink to the destination page9526.7.1 CookiesA cookie object is an instance of class Cookie in package javax.servlet.httpAn HttpServletResponse (from package javax.servlet.http) represents the responseThis object can be accessed by invoking the method getExternalContext on the page bean, then invoking getResponse on the resulting objectAn HttpServletRequest (from package javax.servlet.http) represents the requestThis object can be obtained by invoking method getExternalContext on the page bean, then invoking getRequest on the resulting object. HttpServletRequest method getCookies returns an array of the cookies previously written to the client.Web server cannot access cookies created by servers in other domains96OutlineValidation.java (1 of 5 ) 97OutlineValidation.java (2 of 5 ) 98OutlineValidation.java (3 of 5 ) 99OutlineValidation.java (4 of 5 ) Custom email validation via regular expression100OutlineValidation.java (5 of 5 ) Custom phone number validation via regular expression101Portability Tip 26.1Clients may disable cookies in their web browsers for more privacy. When such clients use web applications that depend on cookies to maintain state information, the applications will not execute correctly.102OutlineOptions.jsp (1 of 4 ) 103OutlineOptions.jsp (2 of 4 ) 104OutlineOptions.jsp (3 of 4 ) 105OutlineOptions.jsp (4 of 4 ) 106Fig. 26.21 | Editing the Page Navigation file. 107OutlineOptions.java (1 of 6 ) 108OutlineOptions.java (2 of 6 ) 109OutlineOptions.java (3 of 6 ) 110OutlineOptions.java (4 of 6 ) 111OutlineOptions.java (5 of 6 ) Creates the Cookie objectGets the response object and adds the Cookie to the response112OutlineOptions.java (6 of 6 ) 113Software Engineering Observation 26.1Java Studio Creator 2 can automatically import any missing packages your Java file needs. For example, after adding the Properties object to Options.java, you can right click in the Java editor window and select Fix Imports to automatically import java.util.Properties.114OutlineRecommendations .jsp (1 of 2 ) 115OutlineRecommendations .jsp (2 of 2 ) 116OutlineRecommendations .java (1 of 4 ) 117OutlineRecommendations .java (2 of 4 ) 118OutlineRecommendations .java (3 of 4 ) Obtains the Cookie object(s) from the request119OutlineRecommendations .java (4 of 4 ) 120Fig. 26.25 | javax.servlet.http.Cookie methods. 12126.7.2 Session Tracking with the SessionBean ObjectCan perform session tracking with class SessionBean that is provided in each web application created with Java Studio Creator 2When a new client requests a web page in the project, a SessionBean object is created. The SessionBean can be accessed throughout a session by invoking the method getSessionBean on the page beanCan then use the SessionBean object to access stored session propertiesTo store information in the SessionBeanAdd properties to the SessionBean classTo add a propertyRight click the SessionBean node in the Outline window Select Add > Property to display the New Property Pattern dialogConfigure the property and click OK to create it122OutlineOptions.jsp (1 of 5 ) 123OutlineOptions.jsp (2 of 5 ) 124OutlineOptions.jsp (3 of 5 ) 125OutlineOptions.jsp (4 of 5 ) 126OutlineOptions.jsp (5 of 5 ) 127Fig. 26.27 | New Property dialog for adding a property to the SessionBean. 128Fig. 26.28 | Bind to Data dialog.129OutlineSessionBean.java (1 of 3 ) 130OutlineSessionBean.java (2 of 3 ) 131OutlineSessionBean.java (3 of 3 ) Manually coded Properties object132OutlineOptions.java (1 of 6 ) 133OutlineOptions.java (2 of 6 ) 134OutlineOptions.java (3 of 6 ) 135OutlineOptions.java (4 of 6 ) 136OutlineOptions.java (5 of 6 ) Add a recommendation137OutlineOptions.java (6 of 6 ) 138Software Engineering Observation 26.2A benefit of using SessionBean properties (rather than cookies) is that they can store any type of object (not just Strings) as attribute values. This provides you with increased flexibility in maintaining client state information.139OutlineRecommendations .jsp (1 of 2 ) 140OutlineRecommendations .jsp (2 of 2 ) 141OutlineRecommendations .java (1 of 4 ) 142OutlineRecommendations .java (2 of 4 ) 143OutlineRecommendations .java (3 of 4 ) Obtains the objects needed to retrieve the users selections144OutlineRecommendations .java (4 of 4 ) Creates recommendations for the user145
Các file đính kèm theo tài liệu này:
- javahtp7e_26_8877_5325.ppt