📄 ilabprovinceplusprojectaction.java
字号:
package cn.edu.hlju.oa.kygl.action;
import javax.servlet.http.*;
import java.sql.*;
import cn.edu.hlju.oa.kygl.db.DBConnection;
import java.io.*;
import net.sf.jasperreports.engine.*;
import java.util.*;
import net.sf.jasperreports.engine.util.JRLoader;
import javax.servlet.ServletContext;
import cn.edu.hlju.oa.kygl.print.SRDataSourceFactory;
import cn.edu.hlju.oa.kygl.util.GlobalUtil;
/**
* 承担省部级以上项目情况报表
*/
public class ILabProvincePlusProjectAction extends GeneralAction {
int exportType = -1;
/**
* 一些预处理操作
*
* @param request HttpServletRequest
* @param response HttpServletResponse
* @throws Exception
* @todo Implement this cn.edu.hlju.oa.kygl.action.GeneralAction method
*/
void preProcess(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("UTF-8");
String action=request.getParameter("action");
//如果没有参数则设置默认值
if( action == null)
action = "reportQuery";
if( action.equals("reportQuery")){
actionType=REPORT_QUERY;
actionPage="ILabOnlyQuery.jsp";
}else if(action.equals("reportPreview")){
actionType=REPORT_PREVIEW;
//进入到打印预览页面
actionPage="GeneralHTMLReportViewer.jsp";
}else if( action.equals("reportExport") ){
//这里不会被访问到
/*actionType=REPORT_EXPORT;
String exportTypeStr = request.getParameter("exportType");
if( exportTypeStr.equals("pdf") )
exportType = REPORT_EXPORT_PDF;
else if( exportTypeStr.equals("rtf") )
exportType = REPORT_EXPORT_RTF;
else if( exportTypeStr.equals("xls") )
exportType = REPORT_EXPORT_XLS;*/
}
}
/**
* 验证操作
*
* @param request HttpServletRequest
* @param response HttpServletResponse
* @throws Exception
* @todo Implement this cn.edu.hlju.oa.kygl.action.GeneralAction method
*/
void validate(HttpServletRequest request, HttpServletResponse response) throws Exception {
}
/**
* 执行业务逻辑的操作
*
* @param request HttpServletRequest
* @param response HttpServletResponse
* @throws Exception
* @todo Implement this cn.edu.hlju.oa.kygl.action.GeneralAction method
*/
void executeBusiniess(HttpServletRequest request, HttpServletResponse response) throws Exception {
switch (actionType) {
case REPORT_QUERY:{
TreeMap map = GlobalUtil.getILabInfo("001");
request.setAttribute("QueryTitle","省部级以上项目信息");
request.setAttribute("ActionName","ILabProvincePlusProjectAction");
request.setAttribute("ILabInfo",map);
}
break;
case REPORT_PREVIEW:
{
Connection conn;
conn=DBConnection.getConnection();
ServletContext context = this.getServletConfig().getServletContext();
String filePath = context.getRealPath("/Reports/承担省部级以上项目/承担省部级以上项目.jasper");
//获得重点实验室的编码
String iLabBm = request.getParameter("ILabSelection");
File reportFile = new File(filePath);
if (!reportFile.exists())
throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first.");
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());
Map parameters = new HashMap();
JasperPrint jasperPrint =
JasperFillManager.fillReport(
jasperReport,
parameters,
SRDataSourceFactory.createILabProvincPlusProjectDS(iLabBm)
);
//JasperViewer.viewReport(jasperPrint, false);
request.getSession().setAttribute("JasperPrint",jasperPrint);
request.getSession().setAttribute("pageTitle","承担省部级以上项目情况");
}
break;
case REPORT_PRINT:
{
JasperPrint print = (JasperPrint)request.getSession().getAttribute("JasperPrint");
if( print == null ){
Connection conn;
conn=DBConnection.getConnection();
ServletContext context = this.getServletConfig().getServletContext();
String filePath = context.getRealPath("/Reports/承担省部级以上项目/承担省部级以上项目.jasper"); File reportFile = new File(filePath);
if (!reportFile.exists())
throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first.");
JasperPrint jasperPrint= (JasperPrint)JRLoader.loadObject(reportFile.getPath());
}
//JasperPrintManager.printReport(print, true);
}
break;
case REPORT_EXPORT://这里面的东西用不上了
{
/*ServletContext context = this.getServletConfig().getServletContext();
JasperPrint jasperPrint = (JasperPrint)context.getAttribute("JasperPrint");
if( exportType == REPORT_EXPORT_PDF){
JRPdfExporter pdfExporter = new JRPdfExporter();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
pdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
pdfExporter.exportReport();
}else if( exportType == REPORT_EXPORT_RTF){
JRRtfExporter rtfExporter = new JRRtfExporter();
rtfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
rtfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
rtfExporter.exportReport();
}else if( exportType == REPORT_EXPORT_XLS){
JExcelApiExporter xlsExporter = new JExcelApiExporter();
xlsExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
xlsExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());
xlsExporter.exportReport();
}*/
}
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -