在不同的窗口显示条形图

时间:2014-11-22 13:38:29

标签: struts2

我正在尝试在test.jsp页面上点击按钮时显示条形图。我能够显示图表,但它在我的test.jsp所在的同一浏览器中作为图像打开。我想在新窗口中显示它,我该怎么做。我正在使用Struts2和Jfreechart:

以下是我的行动:

public class TestAction  extends ActionSupport{

    public String execute() throws Exception {

        //code to populate DataSet

        chart = ChartFactory.createBarChart(
               "Bar Chart",     //Chart title
            "",     //Domain axis label
            "MARKETS",         //Range axis label
            dataSet,         //Chart Data 
            PlotOrientation.VERTICAL, // orientation
            true,             // include legend?
            true,             // include tooltips?
            false             // include URLs?
        );
     chart.setBorderVisible(true);
     return SUCCESS;
    }
}

以下是我的struts.xml

<action name="testAction" 
        class="testAction" 
        method="execute">
             <result name="success" type="chart">
                <param name="value">chart</param>
                <param name="type">jpeg</param>
                <param name="width">600</param>
                <param name="height">400</param>
            </result> 
</action>

<action name="displayDataAction" 
        class="testAction" 
        method="getData">
            <result name="success">test.jsp</result>
</action>

Jsp是:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
   pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Data</title>
<s:head theme="ajax" debug="true"/>
</head>
<body bgcolor="white">

<s:form validate="true" target="_blank">
<table>

//Mapping of data from database

</table>

<s:submit id="submit" value="Display Chart" align="left" action="testAction"/>
<s:submit value="Display Data" align="left" action="displayDataAction"/>`
  </s:form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

不使用s:form标签和s:submit,而是使用表单标签,如:

<form action="blah blah" target="_blank">

这应该可以解决问题。