FusionChartsFree的JSP标签开发

简介:

  写一个JSP标签,一个Java文件,一个标签定义,避免重复写好多嵌入FusionChartsFree的代码。

 

  第一步:定义标签属性等信息,编写TLD文件;

  第二步:编写标签处理的代码;  

  第三步:测试标签;

  第四步:打包发布。


   关键:TLD文件

   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<? xml  version = "1.0"  encoding = "UTF-8" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
                         "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
< taglib >
     < tlib-version >1.0</ tlib-version >
     < jsp-version >1.2</ jsp-version >
     < short-name >jrtz</ short-name >
     < uri >http://www.sunrise.com/jrtz</ uri >
     < tag >
         < name >fcf</ name >
         < tag-class >com.sunrise.broncho.tag.FusionChart</ tag-class >
         < body-content >JSP</ body-content >
         < description > <![CDATA[FusionChartsFree 图表组件应用在JSP页面]]> </ description >
         < attribute >
             < name >chartSWF</ name >
             < required >true</ required >
             < rtexprvalue >true</ rtexprvalue >
             < description > <![CDATA[FusionChart的模版图例文件名]]> </ description >
         </ attribute >
         < attribute >
             < name >divId</ name >
             < required >true</ required >
             < rtexprvalue >true</ rtexprvalue >
             < description > <![CDATA[图表所显示在的Div的Id]]> </ description >
         </ attribute >
         < attribute >
             < name >chartId</ name >
             < required >true</ required >
             < rtexprvalue >true</ rtexprvalue >
             < description > <![CDATA[图表的名称Id]]> </ description >
         </ attribute >
         < attribute >
             < name >dataXml</ name >
             < required >false</ required >
             < rtexprvalue >true</ rtexprvalue >
             < description > <![CDATA[数据源信息,XML数据源.如果使用XML数据源时,URL和XML同时存在优先使用XML数据源]]> </ description >
         </ attribute >
         < attribute >
             < name >dataUrl</ name >
             < required >true</ required >
             < rtexprvalue >true</ rtexprvalue >
             < description > <![CDATA[数据源信息,URL数据源.如果使用XML数据源时该参数设为:""即可]]> </ description >
         </ attribute >
         < attribute >
             < name >chartWidth</ name >
             < required >false</ required >
             < rtexprvalue >true</ rtexprvalue >
             < description > <![CDATA[图标显示的宽,默认值为300]]> </ description >
         </ attribute >
         < attribute >
             < name >chartHeight</ name >
             < required >false</ required >
             < rtexprvalue >true</ rtexprvalue >
             < description > <![CDATA[图标显示的高,默认值为180]]> </ description >
         </ attribute >
         < attribute >
             < name >deCode</ name >
             < required >false</ required >
             < rtexprvalue >true</ rtexprvalue >
             < description > <![CDATA[注意:仅在使用URL数据源下使用,对URL进行编码或解码,ture为解码,false为编码,默认值为false]]> </ description >
         </ attribute >
         < attribute >
             < name >charName</ name >
             < required >false</ required >
             < rtexprvalue >true</ rtexprvalue >
             < description > <![CDATA[注意:仅在使用URL数据源下使用,对URL进行编码解码的处理的字符名称,默认为:UTF-8]]> </ description >
         </ attribute >
     </ tag >
</ taglib >


FusionChartsFree的相关:http://aiilive.blog.51cto.com/1925756/1267021

    关键:Java业务处理

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import  java.io.IOException;
import  java.io.UnsupportedEncodingException;
import  java.net.URLDecoder;
import  java.net.URLEncoder;
import  javax.servlet.jsp.JspException;
import  javax.servlet.jsp.tagext.TagSupport;
/**
  * 使用FusionChartsFree图标组件的标签支持类
  *
  * @author ZhangXiao
  * @time 2013-8-12
  */
public  class  FusionChart  extends  TagSupport {
     /**
      *
      */
     private  static  final  long  serialVersionUID = -455570295257618661L;
     private  String chartSWF =  "" ;
     private  String divId =  "" ;
     private  String dataUrl =  null ;
     private  String dataXml =  null ;
     private  String chartId = divId +  "chart" ;
     private  int  chartWidth =  300 ;
     private  int  chartHeight =  180 ;
     private  boolean  deCode =  false ;
     private  String charName =  "UTF-8" ;
     @Override
     public  int  doStartTag()  throws  JspException {
         try  {
             byte [] script = createScript().getBytes();
             pageContext.getOut().write( new  String(script,  "UTF-8" ));
         catch  (UnsupportedEncodingException e) {
             e.printStackTrace();
         catch  (IOException e) {
             e.printStackTrace();
         }
         return  super .doStartTag();
     }
     /**
      * 通过标签参数创建JavaScript脚本信息
      *
      * @return 返回图表渲染脚本
      */
     private  String createScript() {
         StringBuffer sb =  new  StringBuffer();
         sb.append( "<script type='text/javascript'>" );
         sb.append( "var fcf=new FusionCharts(" );
         sb.append( "'" );
         sb.append(chartSWF);
         sb.append( "', " );
         sb.append( "'" );
         sb.append(chartId);
         sb.append( "', " );
         sb.append( "'" );
         sb.append(chartWidth);
         sb.append( "', " );
         sb.append( "'" );
         sb.append(chartHeight);
         sb.append( "' ); " );
         if  (( this .dataUrl ==  null  &&  this .dataXml ==  null )
                 || ( this .dataUrl ==  ""  &&  this .dataXml ==  "" )) {
             sb =  new  StringBuffer();
             sb.append( "无有效数据支持!" );
         else  {
             // 数据源的选取,XML和URL都存在时:优先选择XML
             if  ( this .dataXml !=  null ) {
                 sb.append( "fcf.setDataXML(\"" );
                 sb.append( this .dataXml);
                 sb.append( "\"); " );
             else  {
                 sb.append( "fcf.setDataURL('" );
                 if  (! this .deCode) {
                     sb.append( this .encode( this .dataUrl));
                 else  {
                     sb.append( this .decode( this .dataUrl));
                 }
                 sb.append( "'); " );
             }
             sb.append( "fcf.render('" );
             sb.append( this .divId);
             sb.append( "'); " );
             sb.append( "</script>" );
         }
         return  sb.toString();
     }
     /**
      * 对URL进行解码
      *
      * @param url
      * @return 返回解码字符串
      */
     private  String decode(String url) {
         try  {
             return  URLDecoder.decode(url,  this .charName);
         catch  (UnsupportedEncodingException e) {
             e.printStackTrace();
         }
         return  url;
     }
     /**
      * 对URL进行编码
      *
      * @param url
      * @return 返回编码字符串
      */
     private  String encode(String url) {
         try  {
             return  URLEncoder.encode(url,  this .charName);
         catch  (UnsupportedEncodingException e) {
             e.printStackTrace();
         }
         return  url;
     }
}

 

 关于测试参见附件例子FusionChartsFree JSP Tag web工程,例子文件要去掉.txt后缀。



本文转自 secondriver 51CTO博客,原文链接:http://blog.51cto.com/aiilive/1285886,如需转载请自行联系原作者

相关文章
|
2月前
|
前端开发 Oracle 关系型数据库
关于使用SSM+JSP开发时setter、getter隐式调用问题的小结
关于使用SSM+JSP开发时setter、getter隐式调用问题的小结
38 3
|
6月前
|
存储 Java 关系型数据库
JSP考试质量分析系统myeclipse开发mysql数据库bs框架java编程web网页结构
JSP 考试质量分析系统是一套完善的web设计系统,对理解JSP java编程开发语言有帮助,系统具有完整的源代码和数据库,开发环境为TOMCAT7.0,Myeclipse8.5开发,数据库为Mysql5.0,使用java语言开发,系统主要采用B/S模式开发。
185 1
|
2天前
|
设计模式 存储 前端开发
Java从入门到精通:2.2.1学习Java Web开发,了解Servlet和JSP技术,掌握MVC设计模式
Java从入门到精通:2.2.1学习Java Web开发,了解Servlet和JSP技术,掌握MVC设计模式
|
1月前
|
存储 安全 前端开发
ssm226基于jsp的快递管理系统的开发
ssm226基于jsp的快递管理系统的开发
|
6月前
|
存储 Java 关系型数据库
JSP考试质量分析系统myeclipse开发mysql数据库bs框架java编程web网页结构
JSP 考试质量分析系统是一套完善的web设计系统,对理解JSP java编程开发语言有帮助,系统具有完整的源代码和数据库,开发环境为TOMCAT7.0,Myeclipse8.5开发,数据库为Mysql5.0,使用java语言开发,系统主要采用B/S模式开发。
126 0
|
2月前
|
Java
jsp页面中使用jstl标签报错:javax.servlet.jsp.JspTagException
jsp页面中使用jstl标签报错:javax.servlet.jsp.JspTagException
13 0
|
3月前
|
SQL 前端开发 Java
JSP技术详解及其在Web开发中的应用
【1月更文挑战第2天】本文将对JSP(Java Server Pages)技术进行详细的介绍和分析。JSP是一种基于Java的服务器端编程技术,它允许开发者在HTML或XML等文档中直接嵌入Java代码片段,从而动态地生成Web页面内容。本文将首先阐述JSP的基本原理和工作机制,然后讨论其在Web开发中的各种应用场景,包括表单处理、数据库访问、会话管理等,并通过实例代码展示JSP的实际应用。最后,本文将对JSP的优缺点进行评述,并对未来的发展趋势进行展望。
133 10
|
3月前
|
XML 前端开发 Java
Web开发: 什么是Servlet和JSP?
Web开发: 什么是Servlet和JSP?
79 0
|
4月前
|
Java
jsp标签下
jsp标签下
27 0
|
4月前
|
XML Java 数据格式
jsp标签上
jsp标签上
26 0

相关课程

更多