Yichz
Yichz

Reputation: 9671

jsp include once?

I'm coding a site using struts 2 and Dojo. my pages are almost all .jsp pages with dojo tags (not the strut dojo tags, because it had been deprecated)

the problem is I can't include twice the same jsp in different pages:

for example I have container.jsp, b.jsp, c.jsp and tool.jsp

b.jsp included tool.jsp

c.jsp included tool.jsp

but if container.jsp includes b.jsp and c.jsp it will cause error with dojo. because dojo will try to register twice elements of tool.jsp

is there a php style include_once which will only include tool.jsp if it has not been included before?? or there is a better approach? thanks

Upvotes: 2

Views: 1794

Answers (1)

Quaternion
Quaternion

Reputation: 10458

I'd recommend tiles. It is a template system which is more powerful than using includes. It wouldn't be much work to implement seeing as you already have your pages broken into fragments. When working inside a jsp things get messy, but if you had a tool that could see all the jsp's and define how they fit together and then assemble them life becomes much easier. This idea for handling the view is a 'composition' strategy and it's what tiles excels at.

Look up the struts2-tiles-plugin. Also see: http://tiles.apache.org/2.2/framework/index.html

For a different view strategy you could contrast 'composition' with 'decoration'. For that site mesh is quite popular.

Upvotes: 2

Related Questions