我需要在我的应用程序中显示图像。我正在使用jfreechart和Spring Framework。已经好几天但我无法解决问题。当我执行代码时,我得到一个包含these等文本的页面,但不是我期待的图表页面!
Tha图像确实存在。如您所见here我可以访问同一文件夹中的另一个图像。更奇怪的是,当我右键单击图像应该在的空间并在另一个标签中打开它实际上出现了!!!正如您所见here
这是我的控制器:
@RequestMapping(value = {"/recursosHumanos/dashboardRrhh"}, method = RequestMethod.GET)
public String dashboardRrhh(Model mapa, HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String adminLineChart = createLineCharts(req, res);
mapa.addAttribute("adminLineChart", adminLineChart);
return "recursosHumanos/dashboardRrhh";
}
private String createLineCharts( HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
String file = "";
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
List<Usuario> listadoDeUsuarios = us.encontrarTodos();
dataset.addValue(5, "Resignation", "2010");
dataset.addValue(10, "Resignation", "2011");
dataset.addValue(8, "Resignation", "2012");
dataset.addValue(10, "Resignation", "2013");
dataset.addValue(7, "Resignation", "2014");
dataset.addValue(8, "Resignation", "2015");
JFreeChart grafico = ChartFactory.createLineChart(
"Ingresos de Personal",
"Años",
"Cantidad de Empleados",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false);
grafico.setBackgroundPaint(Color.white);
final TextTitle subtitulo = new TextTitle("El grafico muestra la distribucion de la tasa de Despidos");
subtitulo.setFont(new Font("Calibri", Font.PLAIN, 12));
grafico.addSubtitle(subtitulo);
ChartRenderingInfo info = null;
System.setProperty("java.io.tmpdir", "C:\\Users\\Pisner-Lichtenstein\\Documents\\NetBeansProjects\\com.gambbate.faqu\\src\\main\\webapp\\static\\css\\charts");
info = new ChartRenderingInfo(new StandardEntityCollection());
HttpSession session = req.getSession();
PrintWriter out = res.getWriter();
try {
file = ServletUtilities.saveChartAsPNG(grafico, 700, 300, info, session);
ChartUtilities.writeImageMap(out, "imgMap", info, false);
out.flush();
} catch (IOException iOException) {
iOException.printStackTrace();
}
String fileName = req.getContextPath() + "/recursosHumanos/grafico?filename=" + file;
return fileName;
}
这是我的JSP
<%--
Document : recursosHumanos
Created on : 26-jun-2016, 20:01:34
Author : Marcelo
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="windows-1252"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-
1252">
<title>Gambbate - faqu Soft</title>
<link href="<c:url value='/static/css/principal.css' /> "
rel='stylesheet' />
<link href="<c:url value='/static/css/bootstrap.min.css' /> "
rel='stylesheet' />
<link href="<c:url value='/static/css/font-awesome.min.css' /> "
rel='stylesheet' />
</head>
<body>
<%@include file="../barraSuperior.jsp" %>
<img id="logoG" src="<c:url value='/static/css/images/GambbateIcon.jpg'
/> " />
<img src="<c:url value='/static/css/charts/${adminLineChart}' /> "
width="200" height="200" >
<img src="${adminLineChart}" border=0 usemap="#imgMap" >
<script src="<c:url value='/static/js/jquery.min.js' /> "></script>
<script src="<c:url value='/static/js/bootstrap.min.js' /> "></script>
</body>
</html>