javapandit.net
  • Home
  • Quick Java
    • Exception Handling
    • Collections Framework
  • Java Best Practices
  • Web Services
    • Web Service Basics
    • Ten Basic webservice concepts
    • XML
    • Apache Axis
    • Restful Web Services
  • JMS Concepts
    • JMS- MySQL
  • Hadoop
    • NoSQL DATABASEs
    • Apache Sqoop
    • Hadoop Interview Questions
  • Java 5
  • Java 8
    • Java 8 : Lambda Expressions
  • JDBC
  • Java Architect
    • Enterprise application re-platforming strategies
    • Java Memory Management
  • Java Programs
  • Technical Tips
    • How to set JAVA_HOME environment variable
    • How to create an auto increment field in Oracle?
    • Linux Commands
  • Best Java Interview Questions
    • Java Interview Questions- YouTube
  • Interview Questions
    • Java Tech interview Questions
    • Core Java Interview Questions >
      • core tech questions1
      • Java Collection interview questions
      • Java Concurrency
    • Servlets Interview Questions
    • JSP Interview Questions
    • Java Web Services Interview Questions
    • EJB Interview Questions
    • XML Interview Questions
    • JMS Interview Questions
  • Struts Interview Questions
    • Struts 2 Interview Questions
  • Java EE Architects Interview Questions
    • Java Architect Interview Questions
    • Top 10 reasons for Java Enterprise Application Performance Problems
    • Web Application Scalability Questions for IT Architect
  • JavaPandit's Blog
  • Web Services Interview Questions
  • Servlets And JSP
  • Oracle SOA Interview Questions
    • Open ESB /JBI
    • BPEL Language
  • Log4J
  • Ant
  • Maven
  • JMeter
  • JUnit
  • Apache POI Framework
  • ORCALE SERVICE BUS (OSB) Interview Questions
  • J2EE Patterns
    • Model-View-Controller (MVC)
    • Front Controller
    • DAO
    • Business Delegate
    • Session Facade
    • Service Locator
    • Transfer Object
    • Design Patterns >
      • Creational Patterns >
        • Singleton
      • Behavioural Patterns
      • Structural Patterns
    • Intercepting Filter
  • SQL Interview Questions/Lab
  • Best Wall Papers
    • Devotional Songs
  • Java Community
  • HIBERNATE
  • ORACLE CC&B
    • Oracle CC&B Interview Questions
  • Docker
  • Little Princess
    • Sai Tanvi Naming Ceremony Celebrations
    • Rice Feeding Ceremony
    • Sai Tanvi Gallery
  • APPSC Career Guidance
    • AP History
    • Indian Polity
    • Indian Economy
    • Science & Technology
    • Mental Ability and Reasoning
    • Disaster Management
    • Current Affairs and Events
    • General Sciences >
      • Biology
      • Physics
      • Chemistry
    • Previous Question Papers
  • About Us
  • Contact US
Tags & Tag Libraries

  •JSP technology has a set of pre- defined tags
–<jsp: useBean …/>

•These are HTML like but…
•… have limited functionality
•Can define new tags
–Look like HTML
–Can be used by page authors
–“Java code” is executed when tag is encountered
–Allow us to keep Java code off the page

•Better separation of content and logic
May Have Tags To…
•Process an SQL command
•Parse XML and output HTML
•Automatically call into an “EJB component” (EJB ™ technology- based component)
•Get called on every request to initialize script variables
•Iterate over a ResultSet and display the output in an HTML table

To define a tag, you need to:
  • Develop a tag handler and helper classes for the tag
  • Declare the tag in a tag library descriptor

Tag Handlers:
A tag handler is an object invoked by a Web container to evaluate a custom tag during the execution of the JSP page that references the tag. Tag handlers must implement either the Tag or BodyTag interface.

For newly created handlers, you can use the TagSupport and BodyTagSupport classes as base classes. These classes and interfaces are contained in the javax.servlet.jsp.tagext package.

Tag handler methods defined by the Tag and BodyTag interfaces are called by the JSP page's servlet at various points during the evaluation of the tag. When the start tag of a custom tag is encountered, the JSP page's servlet calls methods to initialize the appropriate handler and then invokes the handler's doStartTag method. When the end tag of a custom tag is encountered, the handler's doEndTag method is invoked. Additional methods are invoked in between when a tag handler needs to interact with the body of the tag.

Simple Tag Example :

<%@ taglib uri=“/WEB-INF/mylib.tld” prefix=“test” %>
<html>
<body bgcolor=“white”>
          <test:hello name=“Java Pandit” />
</body>
</html>
public class HelloTag extends TagSupport {

            private String name = “World”;

            public void setName(String name) { this.name = name; }

            public int doEndTag() { pageContext.getOut().println(“Hello “ + name); }

}
mylib.tld

<taglib>        ……    
          <tag><name>hello</name>

                   <tagclass>com.pramati.HelloTag</tagclass>

          <bodycontent>empty</bodycontent>

          <attribute><name>name</name></attribute>

          </tag>
</taglib>

How Tag Handler methods are invoked :
<prefix:tagName
          attr1=“value1”         ------------     setAttr1(“value1”)
          attr2=“value2”         ------------     setAttr2(“value2”)
          >                           ------------     doStartTag()
          This tags's body
          </ prefix:tagName>------------      doEndTag()

•Implementation of JSP page will use the tag handler for each ‘action’ on page.

Summary
•The JSP specification is a powerful system for creating structured web content
•JSP technology allows non- programmers to develop dynamic web pages
•JSP technology allows collaboration between programmers and page designers when building  web applications
•JSP technology uses the Java programming language as the script language
•The generated servlet can be managed by directives
•JSP components can be used as the view in the MVC architecture
•Authors using JSP technology are not necessarily programmers using Java technology
•Want to keep “Java code” off a “JSP Page”
•Custom actions (tag libraries) allow the use of elements as a replacement for Java code

Prev 1 2 3 Next
Powered by Create your own unique website with customizable templates.