In today's web development, there are more and more java-based applications. Among them, servlet plays a very important role. This series of articles will introduce some tools to assist in servlet development, so that you can choose from a variety of technologies during development.
Servlet technology is undoubtedly an excellent technology. Most java server technologies are based on servlet technology. However, this technology also has its own shortcomings. For example, the presentation layer (html code) is mixed with the code, and the reusability is not high. SUN proposed jsp (the first choice for SUN Enterprise Applications) technology, and jsp (the first choice for SUN Enterprise Applications) is also a servlet-based technology, you can embed java code in html. Jsp (the preferred choice for SUN Enterprise Applications) has taken a big step on the basis of servlet, but the pure jsp (the preferred choice for SUN Enterprise Applications) also has the shortcomings of servlet mentioned above. However, using jsp (the preferred choice for SUN Enterprise Applications) + javabean + taglib can solve the shortcomings mentioned above. However, jsp (The preferred choice for SUN Enterprise Applications) also has some other shortcomings. For details, see The Problems with jsp (The preferred choice for SUN Enterprise applications. So people developed other servlet-based technologies. Let's first introduce Tapestry.
Introduction
Tapestry is an open-source servlet-based application framework that uses component object models to create dynamic and interactive web applications. A component is any html tag with the CID attribute. Jwc indicates Java Web Component. Tapestry completely isolates java code from html, making it easy to use this framework to develop large-scale applications. In addition, the developed applications are easy to maintain and upgrade. Tapestry supports localization and detailed error reports. Tapestry mainly uses javabean and xml (standardization is getting closer and closer) technologies for development.
First Application
Before introducing the first application, we will first introduce the installation of Tapestry. Download the latest version from sourceforge. decompress the package and put the jar file in the lib directory to CLASSPATH. Put the war file in tomcat (a very useful JSP running platform) under the webapp directory. Then, you can access its tutorial application through http: // localhost: 8080/tutorial.
An application in Tapestry consists of the following parts. We will introduce it with its own HelloWorld program as an example:
Servlet:
This is the main part of an application: servlet class, which must be a subclass of ApplicationServlet and must implement the getApplicationSpecificationPath () method. Example:
Import com. primix. tapestry .*;
Public class HelloWorldServlet extends ApplicationServlet
{
Protected String getApplicationSpecificationPath ()
{
Return "/tutorial/hello/HelloWorld. application ";
}
}
/Tutorial/hello/HelloWorld. application is an application description file.
Application Specification:
It is actually an xml (standardization is getting closer and closer) file describing this application. There are many parameters to be set in this application. The engine-class will be introduced below, the name attribute in page specifies the html file name, and specification-path specifies the description file for this page. There can be many pages in an application, but the name of a page must be "Home", because this page is first displayed when you access your application.
<? Xml (standardization is getting closer and closer) version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE application PUBLIC "-// Howard Ship // Tapestry Specification 1.1 //" http://tapestry.sf.net/dtd/Tapestry_1_1.dtd ">
<Application name = "Hello World Tutorial" engine-class = "com. primix. tapestry. engine. SimpleEngine">
<Page name = "Home" specification-path = "/tutorial/hello/Home. jwc"/>
</Application>
Application Engine:
When a customer connects to a Tapestry application, Tapestry creates an Engine object (similar to session ). Generally, the application engine in our program is an instance of the SimpleEngine class. Of course, this class can also be a subclass.
Page Specification:
Similar to the application description, the page description is also an xml (standardization is getting closer and closer) description file: