JAKARTA programming: Using Tiles, the first part
Author: Chuck Cavaness Chen Zhengyong (zhengyongchen@21cn.com) translation
This article is the first part of the series of articles extracted from "Programming Jakarta Struts", which tells how to use Tiles and make a certain understanding of the template.
So far, we have not talked about how to organize the contents and layout of the JSP page in the Struts application. In many ways, this free Struts theme. Many excellent books provide a good strategy for how to organize web content and page layout.
In the StoreFront application, we use two ways to organize the web page. The first way, that is, JSP-based ways that are usually employed. This may be the most familiar way of web designers. The JSP page contains logic and HTML layout tags, there is no separation between the two, which is usually applied to small, unsurcoming web applications.
The second method uses JSP's INCLUDE instructions. Large web application developers, or when developers realize how repeatable work will be used in the first way, usually. If you spend a lot of time to maintain a web application, you will know how painful update the site's feelings. Use JSP's include instructions to allow more multiplexing, which reduces overall development and maintenance costs.
The third way introduced in this chapter provides you with a better way to reduce redundant code in the web application. At the same time, you can better separate the content and layout than the first two methods.
Understanding templates
Traditional GUI kits, such as Visual Works SmallTalk and Java Swing, provide several layout managers, which indicate how content is displayed in the frame or window. Traditional web sites may have a lot of or large or small during its life cycle. Using the Layout Manager helps the physical area of the page in the application, so when they change, the other parts of the application are small. Unfortunately, JSP technology itself does not provide a layout or layout manager. This is why the modular way is invented by a template. Templates are not a new concept - it has been in other forms for many years.
In order to understand how the template can simplify the layout of the Web site in the actual application. Let's make a comparison with the way using JSP Include. The index.jsp page of the StoreFront application is shown in Example 14-1.
Example 14-1: Storefront application's index.jsp page
<% @ Taglib URI = "/ Web-INF / STRUTS-HTML.TLD" prefix = "html"%>
<% @ Taglib URI = "/ Web-INF / STRUTS-LOGIC.TLD" prefix = "logic"%>
<% @ Taglib Uri = "/ Web-INF / STRUTS-Bean.tld" prefix = "bean"%>