我将要选择一种方式来组织我的观点(使用 spring-mvc,但这应该没有多大关系)
在我看来,有6种选择(尽管它们并不相互排斥) :
<jsp:include>
<%@ include file="..">
Tiles 和 Sitemesh可以分组,Freemarker和 速度也可以分组。在每个小组中使用哪一个不是这个讨论的问题,关于它有足够的问题和讨论。
这是一个有趣的阅读 ,但不能完全说服我使用平铺。
我的问题是-这些框架提供了什么无法正确处理的东西 <@ include file="..">
和 JSTL:
包括页面的某些部分,比如页眉和页脚 ——这两者之间没有区别:
<%@ include file="header.jsp" %>
还有
<tiles:insert page="header.jsp" />
Defining parameters in the header - like title, meta tags, etc. This is very important, especially from SEO point of view. With the templating options you can simply define a placeholder which each page should define. But so you can in jsp with JSTL, using <c:set>
(in the including page) and <c:out>
(in the included page)
Layout reorganization - if you want to move the breadcrumb above the menu, or the login box above another side-panel. If page inclusions (with jsp) is not well organized, you might need to change every single page in such cases. But if your layout is not overly complex, and you put the common things in header/footer, there is nothing to worry about.
Coupling between the common components and the specific content - I don't find an issue with this. If you want to reuse some fragment, move it to a page that doesn't include any header/footer, and include it wherever needed.
Efficiency - <%@ include file="file.jsp" %>
is more efficient than anything else, because it is compiled once. All other options are parsed/executed many times.
Complexity - all non-jsp solutions require additional xml files, additional includes, pre-processor configurations, etc. This is both a learning curve and introducing more potential points of failure. Also, it makes support and changing more tedious - you have to check a number of files/configurations in order to understand what's happening.
Placeholders - do velocity/freemarker give anything more than JSTL? In JSTL you put placeholder, and use the model (placed in request or session scope, by controllers) to fill these placeholders.
So, convince me that I should use any of the above frameworks instead of/in addition to plain JSP.