0
I have a method of a report controller (posted below), to which I return a PDF.
The problem is that it returns the pdf in the same application tab and this is killing it. How can I 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 calling 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
You will not solve this in the backend, you will have to change the link where calls the report
– Denis Rudnei de Souza
Any suggestions how best to do it?
– Marcelo
Generic
<a href="url" target="_blank">Meu link</a>
– Denis Rudnei de Souza
My problem is that I don’t call for a link but for a post in a form that returns a pdf to me through a responseEntity Responseentity.ok(). header(Httpheaders.CONTENT_TYPE, Mediatype.APPLICATION_PDF_VALUE). body(report).
– Marcelo
Put the part where you call
– Denis Rudnei de Souza
It is the method posted above. Or are you referring to HTML?
– Marcelo
Anyway I also put HTML
– Marcelo
The problem is that you send via
form
, could use ajax for this, send information asynchronously and after you receive open a new window– Denis Rudnei de Souza
I’m currently at work, when I get home at night I formulate an answer
– Denis Rudnei de Souza
Thank you. I’ll be waiting.
– Marcelo