I have a method of a report controller (posted below), to which I get a PDF.
The problem is that it returns the pdf on the same application tab and this is killing it. How can I do to return in a new tab?
Post method that is submitted in html.
@PostMapping("/vendasEmitidas")
public ResponseEntity<byte[]>
gerarRelatorioVendasEmitidas(PeriodoRelatorio periodoRelatorio)
throws SQLException, JRException {
byte[] relarotio =
relatorioService.gerarRelatorioVendasEmitidas(periodoRelatorio);
return ResponseEntity
.ok()
.header(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_PDF_VALUE)
.body(relarotio);
}
HTML that calls the report
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/LayoutPadrao}">
<head>
<title>Relatório - Vendas Emitidas</title>
</head>
<section layout:fragment="conteudo">
<div class="page-header">
<div class="container-fluid">
<h1>
Relatório de vendas emitidas
</h1>
</div>
</div>
<div class="container-fluid">
<form method="POST" th:object="${periodoRelatorio}" th:action="@{/relatorios/vendasEmitidas}">
<th:block th:include="fragments/MensagensErroValidacao"></th:block>
<div class="row">
<div class="form-group col-sm-12">
<label for="dataInicio">Data de criação</label>
<div class="form-inline">
<input type="text" class="form-control aw-form-control-inline-sm js-date"
id="dataInicio" th:field="*{dataInicio}" autocomplete="off"/>
<label for="a" class="aw-form-label-between">a</label>
<input type="text" class="form-control aw-form-control-inline-sm js-date"
id="dataFim" th:field="*{dataFim}" autocomplete="off"/>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Emitir</button>
</form>
</div>
</section>
</html>
I'm using:
- Spring MVC 5.0.2
- SpringBoot 2
- Jasper
- Thymeleaf