0

In Spring controller Mapping I have coded for generating PDF file,After generating pdf ,it should redirect to another mapping.But Its Not working.Mapping code added given below.

@RequestMapping(value = "/closeJob")
    public  ModelAndView view(Model model, HttpServletRequest request,HttpServletResponse httpServletResponse) throws Exception {
        VehicleDetails vehicleDetails = new VehicleDetails();
        String i = request.getParameter("jCardNo");
        vehicleDetails = serviceMasterDAO.getVehicle(Long.parseLong(i));
        serviceMasterDAO.updateStatus(vehicleDetails);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("vehicleDetails",vehicleDetails);
        PDFBuilder builder = new PDFBuilder();
        builder.render(map, request, httpServletResponse);
        return new ModelAndView("redirect:/viewJobCard.htm");
    }

Please give me solution on this...

flavio.donze
  • 7,432
  • 9
  • 58
  • 91
Dhinesh
  • 1
  • 5
  • Ofcourse it won't... You first send a PDF (assuming `builde.render` sends that to the client) and expect to redirect after that. You can only either send te pdf of redirect, not both. – M. Deinum Apr 29 '16 at 09:33

1 Answers1

0

A good possible solution is posted here. When sending the first request to the server which creates the PDF, additionally send a download-token, which the server then can add to the response object after he has generated the PDF:

response.addCookie(new Cookie("downloadToken", downloadToken));

In the meantime, the client is polling and waiting to see when the downloadToken is set by the server (which is at the same time the server is done generating the PDF). Then the client can redirect to the new mapping.

Alternatively, one can also just make the client wait a few seconds after submitting the first request, and then make the redirect on client side. That however could lead to the client invoking the redirect before the PDF actually was generated.

Community
  • 1
  • 1
SebastianRiemer
  • 1,495
  • 2
  • 20
  • 33