jsp包含一次?
我正在使用 struts 2 和 Dojo 编写一个网站。我的页面几乎都是带有 dojo 标签的 .jsp 页面(不是 strut dojo 标签,因为它已被弃用),
问题是我不能在不同页面中包含两次相同的 jsp:
例如我有 container.jsp 、 b.jsp、c.jsp 和 tool.jsp
b.jsp 包括 tool.jsp
c.jsp 包含 tool.jsp
但如果 container.jsp 包含 b.jsp 和 c.jsp 则会导致错误道场。因为dojo会尝试注册tool.jsp的两次元素,
是否有一个php样式include_once,如果它之前没有被包含过,它只会包含tool.jsp?或者有更好的方法吗?谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我推荐瓷砖。它是一个比使用包含更强大的模板系统。由于您已经将页面分成了多个片段,因此实现 seeing 并不需要太多工作。在 jsp 内部工作时,事情会变得混乱,但如果您有一个工具可以查看所有 jsp 并定义它们如何组合在一起,然后组装它们,生活就会变得容易得多。这种处理视图的想法是一种“组合”策略,这也是tiles所擅长的。
查找 struts2-tiles-plugin。另请参阅:http://tiles.apache.org/2.2/framework/index.html< /a>
对于不同的视图策略,您可以将“组合”与“装饰”进行对比。对于该网站来说,网格非常受欢迎。
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.