一、后端代码
@Slf4j
@Controller
@RequestMapping("/reprot")
public class FineReportController {
//帆软地址:finereport.url=http://localhost:8075/WebReport/ReportServer?reportlet=
@Value("${finereport.url}")
private String finereportUrl;
@RequestMapping(value = "/page")
public String page(Model model,String cptName, HttpServletRequest request) {
try {
model.addAttribute("reportName",cptName);
model.addAttribute("_reprotUrl",finereportUrl+cptName;
} catch (Exception e) {
log.error("报表页面打开出错:{}",e.getMessage());
}
return "report/reprot_page";
}
}
二、reprot_page.html 前端 iframe 集成 代码片断
<iframe class="report_url" height="930" width="99%" th:attr="name=${reportName},id=${reportName}" frameborder="0" ></iframe>
<script th:inline="javascript">
/*<![CDATA[*/
$(function(){
var winH = $(window).height();
$(".report_url").css('height',winH - 80);
post([[${_reprotUrl}]],{[[${reportName}]]);
});
//post 请求方法
function post(URL, PARAMS,target) {
var temp_form = document.createElement("form");
temp_form .action = URL;
temp_form .target = target;
temp_form .method = "post";
temp_form .style.display = "none";
if (PARAMS){
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp_form .appendChild(opt);
}
}
document.body.appendChild(temp_form);
temp_form.submit();
}
/*]]>*/
</script>
三、显示效果
四、部署到 nginx服务器问题
用 iframe 嵌套 帆软(FineReport)报表页面,结果部署到正式服务器,报表地址显示错误,无法正常访问,经过排查,发现是 nginx 配置导致 的,具体原因如下:
参考:nginx 不允许 iframe嵌套报表问题解决