我把代码贴出来麻烦各位高手帮忙看下
1、最终显示页面test.jsp,这个页面是经过精简的,其实有更多代码,但与本问题无关<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'test.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
    <table width="350px" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#bdd5e0"  class="ntable">
          <tr height="45px">
            <td width="38%" align="center" bgcolor="#e6effb"><strong>柱状图</strong></td>
          </tr> 
           <tr height="200px">
 <td bgcolor="#FFFFFF" class="tdl">
<jsp:include page="includes/chart.jsp" flush="true"> 
<jsp:param name="phone_id" value="127011" /> 
  </jsp:include>
</td>                 
          </tr>
            </table>  
  </body>
</html>
2、test.jsp中include的chart.jsp<%@ page language="java"%>
<%@ page import="java.sql.*"%> 
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<HTML>
<HEAD>
<TITLE>FusionCharts Free - Database And Connection Class Example</TITLE>
<SCRIPT LANGUAGE="Javascript" SRC="../FusionCharts/FusionCharts.js"></SCRIPT>
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.text{
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>
</HEAD>
<BODY>
<CENTER>
<%
    int pid = Integer.parseInt(request.getParameter("phone_id"));
    //int pid=127011;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/rv_mining","root","123123");
Statement st1=null;
ResultSet rs1=null;
String strXML="";
String strXML1="";
strXML = "<graph xAxisname='参数列表' yAxisname='用户倾向值' hovercapbg='DEDEBE' hovercapborder='889E6D'"+
" rotateNames='0' yAxisMaxValue='40' numdivlines='5' divLineColor='CCCCCC' divLineAlpha='80'"+
" decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC'>";
strXML += "<categories font='Arial' fontSize='11' fontColor='000000'>"+
                           "<category name='屏幕'/>  <category name='系统性能' />"+ 
                           "<category name='外观及附件' />  <category name='通话及音效' /> "+
                           "<category name='待机' /> <category name='娱乐' />"+
                           "<category name='总体评价' /> </categories>";
                strXML += "<dataset seriesname='正面评价' color='56B9F9'>";
                strXML1 = "<dataset seriesname='负面评价' color='FDC12E'>";
try {
int P = 0;
int N = 0;
st1=con.createStatement();
rs1 = st1.executeQuery("select * from rvm_chart where phone_id="+pid+"");
while(rs1.next()){
P = rs1.getInt("P_value");
N = rs1.getInt("N_value");
strXML += " <set value='"+P+"' /> ";
strXML1 += "<set value='"+N+"' /> ";
}
rs1.close();
st1.close();
con.close();
}catch(SQLException e) {
    e.printStackTrace();
}
strXML1 += "</dataset>";
strXML += "</dataset>"+strXML1+"</graph>";
%> 
<jsp:include page="FusionChartsRenderer.jsp" flush="true"> 
<jsp:param name="chartSWF" value="../FusionCharts/FCF_MSColumn2D.swf" /> 
<jsp:param name="strURL" value="" /> 
<jsp:param name="strXML" value="<%=strXML %>" /> 
<jsp:param name="chartId" value="UsersTrend" /> 
<jsp:param name="chartWidth" value="300" /> 
<jsp:param name="chartHeight" value="210" /> 
<jsp:param name="debugMode" value="false" /> 
<jsp:param name="registerWithJS" value="false" /> 
</jsp:include>
</CENTER>
</BODY>
</HTML>
3、chart.jsp中include的FusionChartsRenderer.jsp,这是FCF教程里自带的一个页面<%
String chartSWF = request.getParameter("chartSWF");
String strURL = request.getParameter("strURL");
String strXML = request.getParameter("strXML");
String chartId = request.getParameter("chartId");
String chartWidthStr = request.getParameter("chartWidth");
String chartHeightStr = request.getParameter("chartHeight");
String debugModeStr= request.getParameter("debugMode"); 
String registerWithJSStr= request.getParameter("registerWithJS");  int chartWidth = 0;
int chartHeight = 0;
boolean debugMode=false;
boolean registerWithJS=false;
int debugModeInt = 0;
int regWithJSInt = 0;
if (null != chartWidthStr && !chartWidthStr.equals("")) {
chartWidth = Integer.parseInt(chartWidthStr);
}
if (null != chartHeightStr && !chartHeightStr.equals("")) {
chartHeight = Integer.parseInt(chartHeightStr);
}
if(null!=debugModeStr && !debugModeStr.equals("")){
debugMode = new Boolean(debugModeStr);
debugModeInt=boolToNum(debugMode);
}
if(null!=registerWithJSStr && !registerWithJSStr.equals("")){
registerWithJS = new Boolean(registerWithJSStr);
regWithJSInt=boolToNum(registerWithJS);
}


%>
<!-- START Script Block for Chart <%=chartId%> -->
<div id='<%=chartId %>Div'>Chart.</div>
<script type='text/javascript'>
var chart_<%=chartId%> = new FusionCharts("<%=chartSWF %>", "<%=chartId%>", "<%=chartWidth %>", "<%= chartHeight%>", "<%= debugModeInt%>", "<%= regWithJSInt%>");

<% // Check whether we've to provide data using dataXML method or dataURL
// method
      
if (strXML.equals("")) {
%>
    <!-- Set the dataURL of the chart-->
    chart_<%= chartId%>.setDataURL("<%= strURL%>");

<%} else {%>
    // Provide entire XML data using dataXML method
    chart_<%= chartId%>.setDataXML("<%= strXML%>");
<%}%>
<!-- Finally, render the chart.-->
chart_<%=chartId%>.render("<%=chartId%>Div");
</script>
<!--END Script Block for Chart <%=chartId%> -->
<%!
    /**
     * Converts a Boolean value to int value<br>
     * 
     * @param bool Boolean value which needs to be converted to int value 
     * @return int value correspoding to the boolean : 1 for true and 0 for false
     */
   public int boolToNum(Boolean bool) {
int num = 0;
if (bool.booleanValue()) {
    num = 1;
}
return num;
    }
%>
最终显示的时候总是出不来图,单独运行chart.jsp可以出来柱状图

解决方案 »

  1.   

    你可以 测试一下, 首先给你的这个TD加上边框 你先看你的这个TD画出来没。如果连TD都没画出来可能就加载不了这个jsp了 试着 加一个&nbsp;  再也可能是大小有问题。 既然你说jsp本身单独访问的时候是可以显示出柱状图的话 那第2个页面本身应该是没有问题。
      

  2.   


    你好,我尝试td加上边框了,能显示,也尝试改变大小,还是没有图片;能显示 <div id='<%=chartId %>Div'>Chart.</div>中的“Chart.”字样,但就是不出现图,还有别的办法吗?谢谢啊~
      

  3.   

    把FusionChartsRenderer.jsp里的代码整合到chart.jsp里去,然后include一个chart.jsp就行,要注意src外部文件的相对地址别弄错