/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. <%@ taglib 

2.    uri="WEB-INF/taglib.tld" 

3.    prefix = "preafigs" 

4. %> 

5.   

6. <HTML

7. <HEAD

8. <TITLE

9. JSP Custom tags  1 

10. </TITLE

11. </HEAD

12.  

13. <BODY

14.  

15. <H1>Behold our footer, but now as a Custom Tag</H1

16.  

17. <preafigs:SEMMsFooter> 

18.  

19. <BR

20. (In tag's body :)  P.O.Box 1234 

21.  

22. </preafigs:SEMMsFooter> 

23.  

24. </BODY

25. </HTML

26. =======  /WEB-INF/taglib.tld  ======================= 

27. ===( semmstags.jar : /META-INF/taglib.tld )============= 

28.  

29. <?xml version="1.0" encoding="ISO-8859-1" ?> 

30.   <!DOCTYPE taglib 

31.     PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" 

32.   "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"

33.  

34. <taglib> 

35.  

36.   <tlibversion>1.2</tlibversion> 

37.   <jspversion>1.2</jspversion> 

38.   <shortname>SEMMsTags</shortname> 

39.   <uri>com.javalessons.tags</uri> 

40.   <info> 

41.     Some example tags. 

42.   </info> 

43.  

44.   <tag> 

45.     <name>SEMMsFooter</name> 

46.     <tagclass> 

47.     nl.semm.tags.SEMMsFooterTag 

48.     </tagclass> 

49.     <info> Footer </info> 

50.   </tag> 

51.  

52.  

53.   <tag> 

54.     <name>SEMMsFTAttr</name> 

55.     <tagclass> 

56.     nl.semm.tags.SEMMsFTAttr 

57.     </tagclass> 

58.     <info> Footer with attribute</info> 

59.  

60.     <attribute> 

61.       <name>pobox</name> 

62.       <required>false</required> 

63.     </attribute> 

64.     <attribute> 

65.       <name>color</name> 

66.       <required>false</required> 

67.     </attribute> 

68.   </tag> 

69. </taglib> 

70. ====== SEMMsFooterTag.java  ======================== 

71.  

72. package nl.semm.tags; 

73. import javax.servlet.jsp.*; 

74. import javax.servlet.jsp.tagext.*; 

75. import java.util.Calendar

76. public class SEMMsFooterTag 

77.   extends TagSupport 

78.

79.   public int doStartTag() 

80.           throws JspException 

81.     { 

82.     try

83.       JspWriter jspout = pageContext.getOut() ; 

84.       Calendar now = Calendar.getInstance() ; 

85.       jspout.print ( "<HR>" ) ; 

86.       jspout.print ( "Generated " ) ; 

87.       jspout.print (  now.getTime() ) ; 

88.       jspout.print ( " and sent to "  ) ; 

89.       jspout.print ( 

90.         pageContext.getRequest().getRemoteAddr()  ) ; 

91.       jspout.print ( " by " ) ; 

92.       jspout.print ( 

93.         pageContext.getRequest().getServerName()  ) ; 

94.       jspout.print ( "."  ) ; 

95.       jspout.print ( "<HR>"  ) ; 

96.       jspout.print ( "<CENTER>"  ) ; 

97.       jspout.print ( "Copyright © " ) ; 

98.       jspout.print (  now.get(Calendar.YEAR)  ) ; 

99.       jspout.print ( " SEMM (NL) " ) ; 

100.     } 

101.     catch ( Exception ex ) 

102.     { 

103.       throw new JspException("Problem : " + ex ); 

104.     } 

105.     return EVAL_BODY_INCLUDE

106.   } 

107.   public int doEndTag() 

108.   throws JspException 

109.     { 

110.     try

111.       JspWriter jspout = pageContext.getOut() ; 

112.       jspout.print ( "</CENTER>"  ) ; 

113.       jspout.print ( "<HR>"  ) ; 

114.     } 

115.     catch ( Exception ex ) 

116.     { 

117.       throw new JspException("Problem : " + ex ); 

118.     } 

119.     return EVAL_PAGE

120.   } 

121.

122.