📄 distrbypostsnameservlet.java
字号:
package com.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.general.DefaultPieDataset;
import com.service.DistributionByPostsNameService;
import com.service.impl.DistributionByPostsNameServiceImpl;
public class DistrByPostsNameServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public DistrByPostsNameServlet() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
@SuppressWarnings("deprecation")
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
String postsName = request.getParameter("postsName");
DistributionByPostsNameService distributionByPostsNameServiceImpl = new DistributionByPostsNameServiceImpl();
distributionByPostsNameServiceImpl.CountAppBENByPostsName(postsName);
int benCount = distributionByPostsNameServiceImpl.CountAppBENByPostsName(postsName);
int zhuanCount = distributionByPostsNameServiceImpl.CountAppZHUANByPostsName(postsName);
int shuoCount = distributionByPostsNameServiceImpl.CountAppSHUOByPostsName(postsName);
int boCount = distributionByPostsNameServiceImpl.CountAppBOByPostsName(postsName);
int menCount = distributionByPostsNameServiceImpl.CountAppMenByPostsName(postsName);
int womenCount = distributionByPostsNameServiceImpl.CountAppWomenByPostsName(postsName);
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("专科",zhuanCount);
data.setValue("学士",benCount);
data.setValue("硕士",shuoCount);
data.setValue("博士",boCount);
HttpSession session = request.getSession();
PiePlot3D plot = new PiePlot3D(data);//生成一个3D饼图
JFreeChart chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(java.awt.Color.white);//可选,设置图片背景色
chart.setTitle("学历比例情况");//可选,设置图片标题
StandardEntityCollection sec = new StandardEntityCollection();
ChartRenderingInfo info = new ChartRenderingInfo(sec);
String filename = ServletUtilities.saveChartAsJPEG(chart,500,300,info,session);
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
request.setAttribute("graphURL", graphURL);
DefaultPieDataset dataDep = new DefaultPieDataset();
dataDep.setValue("男性",menCount);
dataDep.setValue("女性",womenCount);
HttpSession sessionDep = request.getSession();
PiePlot3D plotDep = new PiePlot3D(dataDep);//生成一个3D饼图
// plotDep.setSectionPaint(0,new Color(80,33,0));
// plotDep.setSectionPaint(1,new Color(22,0,80));
JFreeChart chartDep = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plotDep, true);
chartDep.setBackgroundPaint(java.awt.Color.white);//可选,设置图片背景色
chartDep.setTitle("性别比例情况");//可选,设置图片标题
StandardEntityCollection secDep = new StandardEntityCollection();
ChartRenderingInfo infoDep = new ChartRenderingInfo(secDep);
String filenameDep = ServletUtilities.saveChartAsJPEG(chartDep,500,300,infoDep,sessionDep);
String graphURLDep = request.getContextPath() + "/servlet/DisplayChart?filename=" + filenameDep;
request.setAttribute("graphURLDep", graphURLDep);
request.getRequestDispatcher("/form/distr_byPostsName.jsp").forward(request, response);
}
public void init() throws ServletException {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -