简体   繁体   中英

Transfer data between JSPs. Data is received in one of the JSP's from the controller (SPring MVC)

I want to transfer data from JSP1 to JSP2. Data is being sent to JSP1 from Controller class (Spring MVC).

ModelAndView model = new ModelAndView("JSP1.jsp");

Data sent from Spring MVC Controller to JSP1

model.addObject("documetIdentity", document.getDocumentIdentity());

I want to call JSP2 in JSP1 and the data in "documetIdentity" is to be accessible in JSP2 . I am using foreach on documetIdentity in JSP1.

use ModelMap in your Controller

@RequestMapping("/welcome")
    public String helloWorld(ModelMap model) {

        String message = "Simplemente hola";
        model.addAttribute("msg", message);
        return "/welcome";
}

then in your JSP get the value

....
<div id="messageDiv" class="message primary"> ${msg} </div>
....

Maybe you want to make a validation

<c:if test="${fn:length(msg) > 0}">
    <div id="messageDiv" class="message primary"> ${msg} </div>
</c:if>

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM