Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JFreeChart未显示在JSP页面上_Java_Jsp_Servlets_Jfreechart - Fatal编程技术网

Java JFreeChart未显示在JSP页面上

Java JFreeChart未显示在JSP页面上,java,jsp,servlets,jfreechart,Java,Jsp,Servlets,Jfreechart,我不熟悉JFreeChart并尝试在JSP中实现它。我通过JSP页面上的表单接受用户输入,并将其发送到Servlet页面,从数据库中获取数据后,在该页面中形成图表。之后,我想在我的JSP页面上显示图表,但不幸的是,图表显示在我的Servlet页面上,并且页面没有重定向回我的JSP页面。我不明白为什么 这是我的JSP页面up.JSP <form action="FormChart" class="values" method="post"> <

我不熟悉
JFreeChart
并尝试在
JSP
中实现它。我通过
JSP
页面上的表单接受用户输入,并将其发送到
Servlet
页面,从数据库中获取数据后,在该页面中形成图表。之后,我想在我的
JSP
页面上显示图表,但不幸的是,图表显示在我的
Servlet
页面上,并且页面没有重定向回我的
JSP
页面。我不明白为什么

这是我的JSP页面up.JSP

      <form action="FormChart"  class="values" method="post">
            <table cellspacing="4" cellpadding="4">
                <tr>
                    <td>Select Industry</td>
                    <td><select name="sta" class="dropdown">
                            <option>Industry</option>
                            <option>Cotton</option>
                            <option>Sugar</option>
                            </select></td>
                </tr>
                <tr>
                    <td>Select Category </td>
                    <td><select name="ind" class="dropdown">
                            <option>Category</option>
                            <option>Area</option>
                            <option>Production</option>
                            <option>Yield</option>
                        </select></td>
                </tr>
                <tr>
                    <td>Input Year Range</td>
                </tr>
                <tr>
                    <td>Year 1</td>
                    <td><input type="text" name="yr1" class="yearbox"/></td>
                    <td style="padding-left: 20px;">Year 2</td>
                    <td><input type="text" name="yr2" class="yearbox"/>
                </tr>
                <tr>
                    <td><input type="submit" value="Submit" style="margin-top: 10px;" name="bt" class="btn btn-primary btn1"/></td>
                </tr>
            </table>
            </form>
            <div style="border:1px solid; float:left;width:55%;margin-top:10px;margin-left:20px;border-radius:5px;height:400px;">
                <img src="/FormChart" WIDTH="600" HEIGHT="400" BORDER="0" usemap="#chart"/>
                <%--<jsp:include page="/FormChart" />--%>
    </div>

您的图像的URL正确吗
FormChart是我的Servlet页面的名称,Jfreechart是在该页面上形成的。您没有添加Jfreechart png来响应。对不起,我不明白您在说什么。您能详细说明一下吗?@Rembo您能借助代码告诉我我代码中实际需要更改的内容吗?很紧急。我必须在我的项目中使用它
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        response.setContentType("image/png");
        OutputStream ot = response.getOutputStream(); 
        String qry;
        String y1, y2;
        String indus;
        float a;
        int b;
        DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();
        String st;
        String img;
        categoryDataset = new DefaultCategoryDataset();
        try 
        {
            y1 = request.getParameter("yr1");
            y2 = request.getParameter("yr2");
            st = request.getParameter("sta").toLowerCase();
            indus = request.getParameter("ind").toLowerCase();
            qry = "select year," + indus + " from " + st + " where year between '" + y1 + "' and '" + y2 + "'  and state='Uttar Pradesh'";
            utility ut = new utility();
            ResultSet rs = ut.DQL(qry);
            while (rs.next()) {
                a = Float.parseFloat(rs.getString("" + indus));
                b = Math.round(a);
                categoryDataset.setValue(b, "" + st, "" + rs.getString("year"));
            }
            JFreeChart chart = ChartFactory.createBarChart3D("" + st, // Title
                    "Year", // X-Axis label
                    "" + indus,// Y-Axis label
                    categoryDataset, // Dataset
                    PlotOrientation.VERTICAL,
                    true, // Show legend
                    true,
                    false
            );
            final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
            final File file1 = new File("F:/JavaAptech/Netbeans 74 applications/MinorProj/web/" + "up" + st + indus + y1 + y2 + ".png");
            img = "up" + st + indus + y1 + y2 + ".png";
           ChartUtilities.writeChartAsPNG(ot, chart, 600, 400);
           ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
           chart.setBorderVisible(true);
           request.getRequestDispatcher("/up.jsp").forward(request,response);
        } 
        catch (Exception e) 
        {
           // out.println(e);
        }
}