b. Download presentation Presentation is loading. Please wait.
1
Pre-assessment Questions
2
Pre-assessment Questions (Contd.)
3
Pre-assessment Questions (Contd.)
4
Solution to Pre-assessment Questions
5
Objectives In this lesson, you will learn about: Types of Custom Tags
6
Advance Custom Tag Features
7
Advance Custom Tag Features (Contd.)
8
Advance Custom Tag Features (Contd.)
9
Advance Custom Tag Features (Contd.)
10
Advance Custom Tag Features (Contd.)
11
Advance Custom Tag Features (Contd.)
12
Advance Custom Tag Features (Contd.)
13
Advance Custom Tag Features (Contd.)
14
Advance Custom Tag Features (Contd.)
15
Advance Custom Tag Features (Contd.)
16
Advance Custom Tag Features (Contd.)
17
Advance Custom Tag Features (Contd.)
18
Advance Custom Tag Features (Contd.)
19
Advance Custom Tag Features (Contd.)
20
Advance Custom Tag Features (Contd.)
21
Advance Custom Tag Features (Contd.)
22
Advance Custom Tag Features (Contd.)
23
Advance Custom Tag Features (Contd.)
24
Advance Custom Tag Features (Contd.)
25
Demonstration-Developing a Custom Tag Application
26
Demonstration-Developing a Custom Tag Application (Contd.)
27
Web Application Design Patterns
28
Web Application Design Patterns (Contd.)
29
Web Application Design Patterns (Contd.)
30
Web Application Design Patterns (Contd.)
31
Web Application Design Patterns (Contd.)
32
Summary In this lesson, you learned:
33
Summary (Contd.) JSP provides the following event handling methods:
34
Summary (Contd.) J2EE design patterns are described as:
Similar presentations © 2025 SlidePlayer.com. Inc. Log in
Similar presentations
Presentation on theme: "Pre-assessment Questions"— Presentation transcript:
1. The syntax to instantiate a JavaBean, OptionBean contained in the package test is: a. <jsp:useBean id="option_bean" scope ="page“ class="test.OptionBean"/> b. <% jsp:useBean id="option_bean" scope ="page“ class="test.OptionBean" %> c. <jsp:useBean id="option_bean" scope ="page“ class="test.OptionBean"> d. <%jsp:useBean id="option_bean" scope ="page“ class="test.OptionBean"/> 2. Which JSP action tag can be used to get a property of a JavaBean? a. <jsp:useBean> b. <jsp:getProperty> c. <jsp:getAttribute> d. <jsp:setProperty> J2EE Web Components
3. Identify the empty custom tag where the prefix string is tagPrefix and name of the tag is tagName. a. <tagPrefix:tagName/> b. tagPrefix:tagName/> c. tagPrefix:tagName> d. <tagName:tagPrefix/> 4. The syntax to initialize a JavaBean property using JSP actions is: a. <jsp:setProperty " name = beanName property = propertyName "> b. <jsp:setProperty name="beanName" property=" propertyName"/> c. <jsp:setProperty "name=beanName" "property= propertyName"> d. <jsp:setProperty name="beanName" property=" propertyName"> J2EE Web Components
Identify the correct scope for which a JavaBean object is available to all other components of the Web application. a. page b. request c. application d. session J2EE Web Components
1. a. <jsp:useBean id="option_bean" scope ="page“ class="test.OptionBean"/> 2. b. <jsp:getProperty> 3. a. <tagPrefix:tagName/> 4. b. <jsp:setProperty name="beanName" property=" propertyName"/> 5. c. application J2EE Web Components
Classes and interfaces of Custom Tag API Web Application Design Patterns J2EE Web Components
Custom tags are user-defined reusable components that helps in minimizing the complex and recurring business logic in JSP. Custom Tag API: The javax.servlet.jsp.tagext package is used to develop custom tag. The interfaces defined in the javax.servlet.jsp.tagext package are: Tag interface: Defines the methods that are called during the life cycle of the tag. IterationTag interface: Extends the Tag interface and defines the methods that enable the tag handler to re-evaluate the body content of the custom tags. BodyTag interface: Extends the IterationTag interface and defines the methods that enable the tag handler to manipulate the body content of the custom tag. J2EE Web Components
The following table describes the various classes defined in the javax.servlet.jsp.tagext package: Class Description BodyContent Is a subclass of the JSPWriter class and represents the body content of a tag. TagSupport Acts as a base class for tag handlers and implements empty tags. BodyTagSupport Implements the BodyTag interface. This class is used to develop custom tags with body. TagData Represents the attributes and their values. J2EE Web Components
Various classes defined in the javax.servlet.jsp.tagext package are (Contd.): Class Description TagInfo Represents the information specified in the <tag></tag> element of the TLD file. This class is used by the JSP engine while translating a JSP page to a servlet. TagLibraryInfo Represents the information of the TLD file, such as tags and versioning information. TagVariableInfo Represents information about the variables of a custom tag. J2EE Web Components
The following table describes the various methods that you can implement in a tag handler: Method Description public int doStartTag() Defined by the Tag interface. This method is invoked when the start tag of the custom tag is encountered. The doStartTag() method returns the SKIP_BODY value to specify that the processing of the body content should be skipped. This method can also return EVAL_BODY_INCLUDE value to specify that the body content of the tag should be processed. public void release() Defined by the Tag interface. This method is invoked to allow the tag handler to release some of its resources. J2EE Web Components
Various methods that you can implement in a tag handler are (Contd.): Method Description doAfterBody() Implemented by the BodyTagSupport class. This method is invoked after the body tag is evaluated. The doAfterBody() method returns the EVAL_BODY_AGAIN value to specify that the body content should be re-evaluated. This method can also return SKIP_BODY value to specify that the evaluation of the body content should be skipped. public int doEndTag() Defined by the Tag interface. This method is invoked when the end tag of a custom tag is encountered. The doEndTag() method returns the EVAL_PAGE value to process the remaining JSP page or the SKIP_PAGE value to skip the processing of the remaining page. J2EE Web Components
The following table describes the various methods of the PageContext class: Method Description public abstract JspWriter getOut() Returns the JSP implicit object, out. public abstract ServletRequest getRequest() Returns the JSP implicit object, request. public abstract ServletResponse getResponse() Returns the JSP implicit object, response. public abstract HttpSession getSession() Returns the JSP implicit object, session. J2EE Web Components
Various methods of the PageContext class are (Contd.): Method Description public abstract Exception getException() Returns the JSP implicit object, exception. public abstract ServletContext getServletContext() Returns the JSP implicit object, application. public abstract ServletConfig getServletConfig() Returns the JSP implicit object, config. public abstract Object getPage() Returns the JSP implicit object, page. J2EE Web Components
Various types of custom tags are: Custom tag with attributes Custom tag with body Nested custom tags J2EE Web Components
Custom tag with attributes Contains various attributes. You need to define a property for each attribute. You use the getXXX() and setXXX() methods to access and set the properties in the tag handler class. For example, the following code snippet shows a custom tag with an attribute, copyright and the value as books: <cpyrt:CopyrightTag copyright=”books”> J2EE Web Components
Custom tag with attributes (Contd.) The following code snippet shows how to declare an attribute in the tag handler class: public class FirstCustomTag extends TagSupport { String copyright; ... /* Defines a method that retrieves the copyright information */ public String getCopyright() return(this.copyright); } J2EE Web Components
Custom tag with attributes (Contd.) /* Defines a method that sets the copyright information */ public setCopyright(String copyright) { this.copyright=copyright; } … J2EE Web Components
Custom tag with attributes (Contd.) You need to define the name of the attribute in the TLD file under the attribute element that appears within the tag element. <taglib> <tag> <name>FirstCustomTag</name> <tag-class>copyright.FirstCustomTag</tag-class> <body-content>empty</body-content> <attribute> <name>copyright</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib J2EE Web Components
Custom Tag with Body Encloses other JSP components. The following code shows how to evaluate the body text “Hello! Welcome to the site.”: <hello:HelloTag> Hello! Welcome to the site. </hello:HelloTag> The following code snippet shows a tag element within the TLD file that defines a tag with body: <tag> <name>HelloTag</name> <tag-class>hello.HelloTagHandler</tag-class> <body-content>JSP</body-content> </tag J2EE Web Components
Custom Tag with Body (Contd.) The following code snippet shows how to define the doAfterBody() method in a tag handler for a custom tag with body: public int doAfterBody() throws JspException { try /* Obtain an instance of the BodyContent class */ BodyContent bc = getBodyContent(); Get the bodycontent as string String body = bc.getString(); JspWriter out = bc.getEnclosingWriter(); out.println(body.toUpperCase()); } J2EE Web Components
Nested Custom Tags Are defined within the opening and closing tag of other custom tags. The following code snippet shows a nested tag: <pdtd:ParentTag condition= “true” > <chtd:ChildTag> The expression evaluates to true </chtd:ChildTag> </pdtd:ParentTag> J2EE Web Components
Nested Custom Tags (Contd.) The following code shows how to define the tag handler for the parent tag, <pdtd:ParentTag>, in the tag handler file: import javax.servlet.jsp.tagext.*; import class ParentTag extends TagSupport { private boolean condition; public int doStartTag(){ return EVAL_BODY_INCLUDE; } public void setCondition (Boolean condition) this.condition = condition;} J2EE Web Components
Nested Custom Tags (Contd.) public boolean getCondition() { return condition; } J2EE Web Components
Nested Custom Tags (Contd.) The following code shows how to define a tag handler for the child tag in the tag handler file: import javax.servlet.jsp.tagext.*; import class ChildTag extends TagSupport { public int doStartTag(){ ParentTag parent = (ParentTag) getParent(); /* Access the parent tag using the getParent() method */ boolean condition = parent.getCondition(); /* Access the parent eval_condition attribute using the getCondition() method */ if(condition){ return EVAL_BODY_INCLUDE; } J2EE Web Components
Nested Custom Tags (Contd.) else{ return SKIP_BODY; } }/* End doStartTag() */ J2EE Web Components
Problem Statement Larry Williams, the CEO of ABC Inc. wants the company to have an interactive Web site, which greets end users who visit the Web site and displays the current time. He also wants the end user to be able to specify the background color of the home page. Larry asks John, the company’s Web master to modify the home page of the Web site so that a customized greeting message is displayed to the end user along with the current system time. J2EE Web Components
Solution To solve the preceding problem, perform the following steps: Create an HTML Page. Create a Tag Handler. Create a TLD File of the Tag Handler. Create a JSP page. Specify the Location of the TLD File. Access the Custom Tag Application. J2EE Web Components
The design patterns used in the J2EE applications are: Value Object Model-View-Controller (MVC) Architecture Data Access Object (DAO) Business Delegate J2EE Web Components
Value Object Design Pattern: Is a business tier Pattern that provides solutions to the problems that occur when a client accesses a business object. J2EE Web Components
Model View Controller (MVC): Is a presentation tier pattern and is also known as the client tier pattern. MVC pattern is used to develop interactive J2EE applications that support different types of application clients. J2EE Web Components
Data Access Objects Design Pattern: Provides solution to the various problems that might occur while accessing external resources from the J2EE application. J2EE Web Components
Business Delegate Design Pattern: Hides the complexity for calling the remote business methods of EJB components by Web clients. J2EE Web Components
Custom tag API consists of classes and interfaces, of the javax.servlet.jsp.tagext package. The interfaces defined in the javax.servlet.jsp.tagext package are, Tag, IterationTag and BodyTag. There are 3 types of Custom tags in JSP: Custom Tags with attributes Custom Tags with body Nested custom tags J2EE Web Components
doStartTag(): Invoked when the start tag of a custom tag is encountered. doEndTag(): Invoked when the end tag of a custom tag is encountered. doInitBody(): Invoked before the evaluation of the tag’s body. doAfterBody(): Invoked after the evaluation the tag’s body. release(): Releases the resources. Design pattern is a document that describes the general solutions to the design level problems in a software project. The design patterns suggest general problems at a macro level, which can be modified by the software developer to suit their specific needs. Summary (Contd.) J2EE Web Components
Presentation tier pattern Integration tier pattern Business tier pattern Model View Controller (MVC) Design Pattern represents the presentation tier and is known as the client tier. Data Access Objects Design (DAO) Pattern represents the integration of an application with various external resources, such as databases and other utility software used by an application. Business Delegate Design Pattern represents the business logic part. It abstracts the client information from the business logic. J2EE Web Components
Similar presentations
All rights reserved.