With WebWork, JSP, Velocity establish registration page Source: PConline Editor: chenyong [04-2-14 9:20] Author: dodo / Matix
Summary
WebWork is an open web application framework for simplifying web-based applications. This column describes the webwork and describes how to use WebWork and JavaServer Pages (JSP), Velocity to create a process of establishing registration interfaces.
The design and development of the web application is complex and take time. However, you can simplify the development process by using a framework to handle common web applications. Many open source web application frameworks can do this or even better. The best one in these development frames is WebWork, which is a web application development framework for the OpenSymphony group in the open source project.
The greatest advantage of Webwork is its simplicity and flexibility. Webwork has a small API that enables developers to develop work quickly. WebWork is a combination of many features and applicability, including using Variour View technology, such as JavaServer Pages (JSP), Velocity, Extensible Stylesheet Language Transformations Specification (XSLT), and JasperReporters. Webwork has an active community with many articles, developers and users.
Note: This article is based on WebWork1.3.0 Release Candidate 2 (RC2). In order to use the examples provided herein, you need to create a folder in your application server's webapps directory, copy the sample to your new folder, and copy the required JAR file to the web-inf / lib directory. . Download WebWork and source code related to this article here.
------ Actions
One of the most important features of Webwork is the action interface. WebWork Actions Controls the web application process by providing mapping between the page (view) and the business logic. In WebWork, submit the form to an action URI (Uniform Resource Identifier); this URI points to a corresponding action; action; the user can enter the corresponding view.
The following Class, LoginAction is an example of a web application-based registered form based on Web application. LoginAction extends ActionSupport. It is a base class that provides processing errors, view mapping, and many useful features.
Import Webwork.Action. *;
Public class loginaction extends actionsupport {private string username; private string password;
Public string getpassword () {return password;}
Public string getUsername () {return username;}
Public void setpassword (string password) {this.password = password;}
Public void setusername (string username) {this.username = usrname;}
Public string doexecute () {returnis Success;}
Public void Dovalidation () {if (username == null || username.length () <1) Adderror ("UserName", "please enter username."); if (password == null || Password.length () < 1) Adderror ("Password", "Please enter password.");}} LoginAction includes two JavaBeaN properties, Password and Username. WebWork places the data from the property into your view and automatically parses the parameters sent to the Action to set the attribute value.
LoginAction is overloaded two methods for ActionSupport: Dovalidation () and DoExecute (). Dovalidation () method verifies the parameters, and the doexecute () method allows the user to advance to the corresponding view. The doexecute () method returns a string, if all processing is successful, return constant access. If there is any problem, return constant input on the user input view. Calling Adderror in the loginaction pointing to an authentication issue and allows the user to return to the INPUT view.
---------
VIEW MAPPING Webwork has two ways from map to the view: via an action.xml file or a views.properties file. Each action should have an INPUT view and a Success view. The following Action.xml file defines two Actions, LoginJSP, and Loginvelocity. Both Actions use the LoginAction class. If LoginAction returns Success, the two Actions use the LoginAction class and turn the user to Success.html. If loginaction returns input, Action turns to the corresponding INPUT view, or login.jsp, or login.vm;
actions>
-------- View Although webwork provides support for many different view technologies, the most common is JSP and Velociy. The following page is an example of two registration pages - one using the JSP another Velocity. Each page includes a user section and a password part, which is submitted to the WebWork Action. The Login.jsp page creates and processs the above two parts by using the WebWork tag library, and handles errors via the error collector. Webwork: TextField and Webwork: Password tag establishes a text and password section, and the Webwork: Iterator tag handles errors returned from loginaction. WebWork: Property tag Set the username, password, and errors properties.
<% @ Taglib Uri = "Webwork" prefix = "Webwork"%>