How to pass model attribute from ModelAndView to jsp page

时间:2019-01-09 22:18:32

标签: java jquery spring

I am trying to create a listener to check when a user submits a form to download an excel document to disable/enable buttons.

It works using session attribute but this is not a good solution as I have to check the server if the attribute has been set, causing unnecessary page refreshes. It works using cookies too but as I understand I should be able to add an attribute in the model object for reference.

Controller

@RequestMapping(value = "/report", method = RequestMethod.POST)
public ModelAndView getReport(HttpServletResponse response, HttpSession session) {
    Map<String, Object> modelObject = new HashMap<>();
    modelObject.put("lock", "false");
    return new ModelAndView("report", modelObject);
}

Report Model/View

@Override
protected final void renderMergedOutputModel(Map<String, Object> model,
        HttpServletRequest request, HttpServletResponse response)  throws Exception {
    exposeModelAsRequestAttributes(model, request); //did not have this before but did not fix the issue
    //generate excel document and write to output stream
}

jsp

<input type="text" id="downloadLockId" value="<c:out value="${lock}"/>">

The idea is to know then the download has started, which happens when the server writes to the outputstream but I get null for the variable.

0 个答案:

没有答案