Ai
1 Star 3 Fork 2

龙哥/gridReportServerJava

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
myreportServer.txt 5.59 KB
一键复制 编辑 原始数据 按行查看 历史
龙哥 提交于 2021-03-08 16:18 +08:00 . add doc file
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.xml.util.PropertiesHelper" %>
<%@ page import="com.xml.util.HttpUtils" %>
<%@ page import="com.xml.util.TimestampUtil" %>
<%@ page import="com.xml.gridreport.ServerUtility" %>
<%@ page import="gridreport.ExportType" %>
<%
//http://as.hda.gov.cn/reportServerService/?
// grf=http://as.hda.gov.cn:80//grf/hlwypxxfw/hlwypxxfw_xkz_new.grf
// &data_url=http://as.hda.gov.cn:80//gridreport/hlwxxfw/dy_printJsonData.action
//网络类型:internet互联网 server_local服务器内网,默认是服务器内网
String net_type = "server_local";
net_type = request.getParameter("net_type") == null ? "" : request.getParameter("net_type").toString();
//项目中使用,如果为空,就切换为本机服务器模式
if (!"".equals(net_type))
net_type = "server_local";
//PDF文件的显示方式
// inline内联模式,直接通过浏览器打开PDF;
// attachment附件模式,浏览器提示保存对话框
String pdf_mode = "inline";
pdf_mode = request.getParameter("pdf_mode") == null ? "" : request.getParameter("pdf_mode").toString();
if (!"".equals(pdf_mode))
pdf_mode = "inline";
//POST参数中获取GRF模板JSON数据的基本网址
String base_url = "";
//POST参数中获取GRF模板JSON数据的参数
String param_str = "";
//获取调用页面中给GRF模板路径的URL
String grf_url = "";
//获取grf模板 参数值
grf_url = request.getParameter("grf") == null ? "" : request.getParameter("grf").toString();
if (grf_url == null || grf_url.length() == 0) {
throw new Exception("没有在URL参数中指定\"grf\"参数!");
}
//获取grf模板数据ACTION参数值
//&data_url=http://as.hda.gov.cn:80//ylqxsc/ylqxsc_slspGrf.action?sqSqbh=%25E8%25B1%25AB%25E7%2594%25B32020122301351%25E5%258F%25B7&sfsl=Y&tabName=bs_ylqxsc_bg&time=810
//string data_url = context.Request.QueryString["data_url"];用这种方法取类似上面的信息时会出错,
//只取到http://as.hda.gov.cn:80//ylqxsc/ylqxsc_slspGrf.action?sqSqbh=%E8%B1%AB%E7%94%B32020122301351%E5%8F%B7
//获取当前访问页面完整url
String full_url = request.getQueryString().toString();
System.out.println("full_url:" + full_url);
if(full_url.indexOf("pdf_mode")>0){
pdf_mode=full_url.substring(full_url.indexOf("pdf_mode=") + 9);
}
//取data_url=后面所有的字符串
String data_url = full_url.substring(full_url.indexOf("data_url=") + 9);
//http://as.hda.gov.cn//gridreport/hlwxxfw/dy_printJsonData.action?sqSqbh=1
System.out.println("data_url:" + data_url);
if (data_url == null || data_url.length() == 0) {
throw new Exception("没有在URL参数中指定\"data_url\"参数!");
}
/* else {
if (data_url.indexOf('?') > 0) {
String[] sArray = data_url.split("\\?");
base_url = sArray[0];
param_str = sArray[1];//data_url.Substring(data_url.IndexOf('?')+1 , data_url.Length-data_url.IndexOf('?'));
System.out.println("base_url:"+base_url);
System.out.println("param_str:"+param_str);
}
}*/
//1 创建报表对象,此处需要引入gridreport.jar到项目中
gridreport.Report report = new gridreport.Report();
//2 从文件载入报表grf模板
//因为服务器只能访问内网,所以需要把基本网址中的http://as.hda.gov.cn转成本机获取IP项目
//改为从config.properties配置文件获取服务器本机内网IP
String local_ip = PropertiesHelper.getString("config.properties", "serverLocalIP");
//如果是服务器内网,需要转换域名为本机IP项目
if (net_type == "server_local") {
String serverDomain = PropertiesHelper.getString("config.properties", "serverDomain");
grf_url = grf_url.replace(serverDomain, local_ip);
//因为服务器只能访问内网,所以需要把模板网址http://as.hda.gov.cn中的as.hda.gov.cn转成本机获取IP项目
}
//载入报表本地grf模板文件
//String FileName = request.getRealPath("grf")+ "/1a.grf";
//Boolean local_grf_load_flag = report.LoadFromFile(FileName);
//载入报表网络grf模板文件 如http://as.hda.gov.cn:80/grf/hlwypxxfw/hlwypxxfw_xkz_new.grf
System.out.println("模板grf_url:" + grf_url);
Boolean server_grf_load_flag = report.LoadFromURL(grf_url);
if (!server_grf_load_flag) {
throw new Exception("载入报表模板失败,文件:" + grf_url);
}
System.out.println("11111111" );
//3 获取模板对应的JSON数据:模板发送POST请求获取GRF模板的JSON数据
String reportDataText = HttpUtils.get(data_url);
System.out.println("模板JSON数据是:" + reportDataText);
boolean load_grf_data_flag = report.LoadDataFromXML(reportDataText);
if (!load_grf_data_flag) {
throw new Exception("载入报表数据失败,数据文本:" + reportDataText);
}
//4 生成PDF文档数据到二进制数据对象
gridreport.BinaryObject bo = report.ExportDirectToBinaryObject(ExportType.PDF);
//获取当前的时间戳作为下载PDF的名字
String down_pdf_name = TimestampUtil.getCurrentTimestamp() + ".pdf";
//5 将生成的数据响应给客户端
System.out.println("pdf_mode:" + pdf_mode);
if ("inline".equals(pdf_mode)){
ServerUtility.ResponseBinary(request, response, bo, down_pdf_name, "application/pdf", "inline");//inline
} else {
ServerUtility.ResponseBinary(request, response, bo, down_pdf_name, "application/pdf", "attachment"); //attachment
}
%>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/ixml/grid-report-server-java.git
git@gitee.com:ixml/grid-report-server-java.git
ixml
grid-report-server-java
gridReportServerJava
master

搜索帮助