Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring AbstractPdfView - change the response so it has a file name rather than the request path
    primarykey
    data
    text
    <p>I have a controller that returns a view that overrides <code>AbstractPdfView</code>. Works great except for the fact when the user goes to save the PDF form the browser it tries to save a the request path (seems reasonable but not what I want).</p> <p>The controller code is:</p> <pre><code>public class MealPlanPDFController { private MealPlannerDao mealPlannerDao; private UserDao userDao; //protected SessionFactory sessionFactory; @Autowired public void setMealPlanDao(MealPlannerDao mealPlannerDao) { this.mealPlannerDao = mealPlannerDao; } @Autowired public void setUserDao(UserDao userDao) { this.userDao = userDao; } @RequestMapping(value = "{id}", method = RequestMethod.GET) @Transactional protected ModelAndView handleRequest(@PathVariable Long id, HttpServletRequest request) throws Exception { System.out.println(request.getContextPath()); ModelAndView modelView = new ModelAndView(new MealPlanPDFView()); MealPlan mealPlan = mealPlannerDao.getMealPlan(id, true); ServletContext servletContext = request.getSession().getServletContext(); Resource res = new ServletContextResource(servletContext,"/images/logo.png"); URL url = res.getURL(); modelView.addObject("mealPlan",mealPlan); modelView.addObject("imageURL",url); System.out.println(url.getPath()); return modelView; } } </code></pre> <p>So the request path is:</p> <p><code>api/mealplanpdf/1</code> where 1 is the id for the MealPlan.</p> <p>On the response I woulf like it to be <code>mealplan_1.pdf</code>. </p> <p>Makes sense? Any idea how I would do that?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload