Sunday, 25 March 2018

jsp to demonstrate import attribute

Write a JSP Program to demonstrate the import attributes..



//index.jsp
<%@ taglib uri="WEB-INF/tlds/mytags.tld" prefix="m" %> 
Cube of 4 is: <m:cube number="4"></m:cube> 

//CubeNumber.java
package reva; 
import javax.servlet.jsp.JspException; 
import javax.servlet.jsp.JspWriter; 
import javax.servlet.jsp.tagext.TagSupport; 
 
public class CubeNumber extends TagSupport{ 
private int number; 
     
public void setNumber(int number) { 
    this.number = number; 
} 
 
public int doStartTag() throws JspException { 
    JspWriter out=pageContext.getOut(); 
    try{ 
        out.print(number*number*number); 
    }catch(Exception e){e.printStackTrace();} 
      
    return SKIP_BODY;  } 
} 

//mytags.tld

<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
  <tlib-version>1.0</tlib-version>
  <short-name>mytags</short-name>
  <uri>/WEB-INF/tlds/mytags</uri>
   <description>A simple tab library for the examples</description> 
 
  <tag> 

    <name>cube</name> 
    <tag-class>reva.CubeNumber</tag-class> 
    <attribute> 
    <name>number</name> 
    <required>true</required> 
    </attribute> 
  </tag> 
</taglib>

output


No comments:

Post a Comment

PUBLISHER & SUBSCRIBER PATTERN

Using the UML Drawing Tool by implementing the code in Java demonstrate the Observer  Design Pattern. The Publisher-Subscriber desig...