Danh mục

XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application- P7

Số trang: 50      Loại file: pdf      Dung lượng: 1.62 MB      Lượt xem: 10      Lượt tải: 0    
Thu Hiền

Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application- P7: Là một nhà phát triển Web, bạn biết những thách thức trong việc xây dựng các ứng dụng mạnh mẽ trên nhiều nền tảng. Tạo các ứng dụng di động trở nên thật sự có thể bằng cách sử dụng Java cho code và XML để tổ chức và quản lý dữ liệu. "XML, XSLT, Java, và JSP: Một trường hợp học" sẽ giúp bạn tối đa hóa khả năng của XML, XSLT, Java, và JSP trong các ứng dụng web của bạn....
Nội dung trích xuất từ tài liệu:
XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application- P7282 Chapter 8 Java Servlet and Java Bean: BonForumEngine and BonForumStore method, as appropriate.That returns actorKeys, which is an array list of nodeKeys, either for all host nodes or for all guest nodes in bonForumXML. The chatGuest and chatHost session attribute values (chatActor strings) have the following format, which depends upon the XSL document used in the XSLT process that displays the lists of hosts and guests: actorNickname age:actorAge rating:actorRating Here is an example: John Doe age:47 rating:11 The actorNickname is recovered from that string and is used as follows: NodeKey actorNodeKey = getActorByNickname(actorKeys, actorNickname); The getActorByNickname() method selects the correct actor nodeKey from the list for the correct one. It is then used as follows: NodeKey actorRatingNodeKey = getActorRatingForActor(actorNodeKey); The getActorRatingForActor() method gets the nodeKey of the actorRating node. That node is a child of the actor node for the actorNodeKey. The content of the actorRating node is the current rating for the actor being rated. The final statement in the changeChatActorRating() method is the following: return changeActorRating(actorRatingNodeKey, amount); The changeActorRating() method gets the actorRating node from its key, the first argument. It then parses the actorRating node content and the amount argument as integer values.The rating value is offset by the amount value (1 or –1, in our case) to get a new rating, which is converted to a string. Finally, the actorRatingNodeKey and the new rating value for the actorRating node content are both passed to the editBonNode() method of the database object.That method takes care of updating the actor rating in the XML data (we will spare you the details). Accessing Bean Properties and Methods from JSP You just saw a bean method, changeChatActorRating(), being called from a JSP.We will now show several ways to access bean properties and to call bean methods from JSP.The property examples will use two BonForumStore properties, hitTimeMillis and initDate, which are mostly useful for examples like this. For convenience, the method examples will use the get and set property access methods of these same two proper- ties, although the techniques that we show apply to other public bean methods as well. First, let’s introduce the properties that we will use.Whenever a thread goes through the processRequest() BonForumStore method, it calls the initialize() method of the class. In that method, it leaves a timestamp in the hitTimeMillis prop- erty with the following statement: setHitTimeMillis(null); 8.2 The BonForumStore Class 283With a null argument, the set method uses the system clock to set the current timein the property. Both set and get methods for hitTimeMillis have been declaredpublic so that we can both read and write the property from JSP in bonForum. The thread next calls the initializeXML() method. If the bonForumXML data objectis empty (normally true only after application startup), it will be filled with necessarydata.When that happens, the setInitDate() method of BonForumStore is called with anull argument, which puts a datestamp in the initDate property, which shows thedate and time that the database was initialized.The getInitDate() method is public,but the setInitDate() method is protected. From JSP, therefore, initDate is a read-only property. One easy way to use a JavaBean from JSP is to use a jsp:useBean tag, as follows: It is important to realize that jsp:useBean will create a new instance of the bean onlyif it does not find an already existing one with the name given by the id attribute, inthe scope given by the scope attribute. Because BonForumEngine has created a servletcontext attribute called bonForumStore and has set it to its static bonForumStore dataobject, this tag will find the “real” data storage object, not create a new one. You can then use a jsp:getProperty tag to display a property value, if you arelooking for a property that is readable and that provides a value (we are, in thisexample): initDate: Alternatively, you can use a JSP expression to display the same property value by usingthe id from the jsp:useBean tag to access the bean and its method, as follows: initDate: The setInitDate() method is protected, so attem ...

Tài liệu được xem nhiều:

Tài liệu cùng danh mục:

Tài liệu mới: