Jsp pass object to include

I currently have a page with a little content that needs to be updated frequently.

For example: jsp content

Chapter 1 : section abc: section def: section ghi: 

Assuming I have a Chapter class and its sections are parameters in it

  class Chapter{ Section abc; Section def; Section ghi; } 

I am using spring mvc, adding the following models

 model.addAttribute("chapter", chapter); model.addAttribute("abc", chapter.getAbc()); model.addAttribute("def", chapter.getDef()); model.addAttribute("ghi", chapter.getGhi()); 

When the main page is called up, I can load individual sections using jsp: includes, and when I update them, I add this particular model to this particular jsp page myself and update it with ajax. It works great.

But

The question is, How can I change the design so that I can control the whole only with

 model.addAttribute("chapter", chapter); 

so that I can use the chapter object to get the values ​​abc, def, ghi, and not explicitly pass them.

The problem is that I cannot pass individual objects to jsps included from the chapter object, for example ..

 <jsp:include page="abc.jsp" > <jsp:param name="abc" value="${ chapter.abc}"/> </jsp:include> 

it's impossible. as i can only pass strings

minor problem, long description .. wishing I made my point.

+4
source share
1 answer

You can pass strings only as query parameters, but you can set any type of objects as query attributes. The request area (not the page area) beans should also work.

+3
source

Source: https://habr.com/ru/post/1384850/


All Articles