📄 mate_jfreechartservlet.java
字号:
package imis_mate.servlet;
import imis_mate.common.MateByJFree;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.servlet.ServletUtilities;
public class Mate_JFreeChartServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public Mate_JFreeChartServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String pattern = request.getParameter("pattern");
if(pattern.equals("buyJfreePag")) {
this.buyJfreePag(request,response);
}else if(pattern.equals("outJfreePag")) {
this.outJfreePag(request,response);
}else if(pattern.equals("jfreePag")){
this.jfreePag(request,response);
}
}
private void jfreePag(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// TODO Auto-generated method stub
String displayType = request.getParameter("displayType");
String materialTypeNo = request.getParameter("materialTypeNo");
String startDate = request.getParameter("startDate");
String endDate = request.getParameter("endDate");
// String applyDep = request.getParameter("applyDep");
String type = request.getParameter("type");
String title = "";
String y = ""; // y轴标题
if(type.equals("1")) {
title = "数量构成";
y = "数量";
} else {
title = "价格构成";
y = "价格";
}
String filename = "";
HashMap table = MateByJFree.getTongjiTu(materialTypeNo, startDate, endDate,type);
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
if(displayType.equals("pie")) { //面积比例饼图 //500是图片长度,300是图片高度
filename = ServletUtilities.saveChartAsPNG(MateByJFree.getchart(table,1,title,y), 500, 300, info, request.getSession());
} else if(displayType.equals("bar")) { //柱状图
filename = ServletUtilities.saveChartAsPNG(MateByJFree.getchart(table,2,title,y), 500, 300, null, request.getSession());
} else if(displayType.equals("line")) {
filename = ServletUtilities.saveChartAsPNG(MateByJFree.getchart(table,3,title,y), 500, 300, null, request.getSession());
}
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
request.setAttribute("graphURL", graphURL);
request.getRequestDispatcher("../imis_mate/mate_JFree.jsp").forward(request, response);
}
private void outJfreePag(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.getRequestDispatcher("../imis_mate/mate_Out_JFree.jsp").forward(request, response);
}
private void buyJfreePag(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.getRequestDispatcher("../imis_mate/mate_JFree.jsp").forward(request, response);
}
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -