Answer the question
In order to leave comments, you need to log in
Why does SpringBoot lose its file folder when building?
Good afternoon, please tell me why is this happening?
There is a controller which should give files on request.
the folder with files is located along the path: ~\src\main\resources\webapp\WEB-INF
@Controller
@RequestMapping("/jr")
public class JReportFileController {
@RequestMapping("/reportFile/{fileName}")
public void downloadReportFile(HttpServletRequest request, HttpServletResponse response,
@PathVariable("fileName") String fileName) {
String dataDirectory = request.getServletContext().getRealPath("/WEB-INF/reports/");
Path file = Paths.get(dataDirectory, fileName);
if (Files.exists(file)) {
response.setContentType("application/jasper");
response.addHeader("Content-Dispositions", "attachment;filename=" + fileName);
try {
Files.copy(file, response.getOutputStream());
response.getOutputStream().flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question