Replace JSP new technology - Tapestry !!!
(This article has been read 3466 times) Time: 2003/10/07 04:55 PM Source: SMLTIGER
In today's Web development, Java-based applications are increasing. In this, servlet played a very important role. This series of articles is to introduce some of the tools for servlet development, and there are a variety of technologies to choose from when developing. Servlet technology is undoubtedly an excellent technology, and the Java server-side technology is mostly based on servlet technology. However, this technique also has its own insufficient, for example, indicating that the layer (HTML code) is mixed with the code, and the reusability is not high. SUN then proposed JSP technology, JSP is also a technology-based technology, using it you can embed Java code in HTML. JSP moves a big step on the basis of servlet, but simple JSP has the shortcomings of the servlet mentioned above. However, using JSP JavaBean Taglib This development mode can solve the shortcomings mentioned above. But JSP itself has some other shortcomings, and details will be referred to the article of Problems with JSP. So people have developed some other servlet-based technologies. Let's first introduce TapeStry.
Introduction
Tapestry is an open source-based Servlet-based application framework that uses component object models to create dynamic, interactive web applications. One component is any HTML tag with JWCID attribute. Where JWC means Java Web Component. Tapestry makes Java code to completely separated from HTML, using this framework to develop large applications becomes lighter. And the application developed is easy to maintain and upgrade. TapeStry supports localization, and its error report is also very detailed. Tapestry is mainly developed by JavaBean and XML technology.
First application
Let's introduce TapeStry installation before introducing the first application. After downloading its latest version from SourceForge, place the JAR file in the lib directory in the classpath, put the WAR file in the Tomcat's WebApp directory. The TUTORIAL application can then be accessed by http: // localhost: 8080 / tutorial. One of the following components in TapeStry, we use their own HelloWorld program as an example:
Servlet: This is a part of an application: servlet class, this class must be the subclass of ApplicationServlet, and must implement the getApplicationsPecificationPath () method. Examples are as follows:
Import com.primix.tapestry. *; public class helloworldServlet Extends ApplicationServlet {protected string getApplicationspecificationPath () {return "/TUTORAL/HELLO/HelloWorld.Application";}
/Tutorial/hello/helloWorld.Application is an application's instruction file. Application Specification: It is actually describing an XML file for this app. There are many parameters in this app to set, Engine-Class will introduce, the name attribute in the page specifies the HTML file name, specification-pats specifies the description of this page. file. There are many Page in an app, but you must have a page of Name as "HOME", because when you access your app, the first display is this Page. XML Version = "1.0" encoding = "UTF-8"?>
Application Engine:
When the customer is connected to the Tapestry app, TapeStry will create an Engine object (similar to session). Usually Application Engine in our program is generally an instance of the SimpleEngine class, of course, the subclass of this class can also be.
Page Spectation: Similar to the application, page description is also an XML description file:
XML Version = "1.0" encoding = "UTF-8"?>
Because this application is static, use com.primix.tapestry.baSepage, if it is a dynamic application, you need to define some Component in this file, of course, the use of BasePage is a class class class. HTML page: The HTML page of this app is very simple:
Note that the various files mentioned above must be placed in a WAR's web-inf / class content.
A complex application
In this application, we will introduce Tapestry's common functions with a simple student management system. We have to achieve students' increase and display, so we need two HTML pages. As for the StudentServlet class and student.application, we will not describe, defined in Student.Application, two Page: Home and EditStudent, see attachments. Student Data is stored in the database, we use the Student class to indicate a record in the data, use the StudentFactory class to search for student data, these two classes use a JDBC wrapper, about this JDBC wrapper can see my other article < Student list p> Unlike the previous simple applications, we define seven components in this page. Let's take a few home.jwc files, we will tell how to describe these components. Package test; import com.primix.tapestry. *; import sun.jdbc.odbc.jdbcodbcdriver; / *** Return to each student's data ** / Public class liststudent eachstudage {private;} () () () () () () () () () () ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, public Student getEachstudent () {return eachstudent;} public void setEachstudent (Student value) {eachstudent = value;} public Student [] getStudent () {try {Class.forName ( "sun.jdbc.odbc.JdbcOdbcDriver"); student = StudentFactory.FindallStudAntents ();} catch (exception e) {E.PrintStackTrace ();} returnit; } This class has four functions, where the DETACH function is the action that is performed when the page is placed in the buffer pool, and the getStudent function returns all student records, which is assigned to the source parameter of the ListStudent component in the JWC file, getEachstudent gives this component Value parameter Assignment, because Source is an array, each loop needs to be taken from the record assignment to Eachstudent, so there is a function to setEachstudent, you will notice this function is very simple, actually TapeStry helps you do most of the work. At this point, it shows that the part of the student has been completed, let's take a look at EditStudent.html student management system p>
study number td> Name TD> Gender TD> Class TD> 20012400 Span> td> Zongfeng span> td> male span> td> computer research one span> td> tr> 20011389 td> Sang Yishan td> Male TD> Computer Research 1 TD> TR> Table> Add Student html >