js|web| page WebWork is a source-code-open Web application framework for simplifying web-based application development. This column describes WebWork and describes how to use the WebWork and JavaServer Pages (JSP), velocity two techniques to establish a registration interface.
The design and development of WEB applications is complex and time-consuming. 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 even better. One of the best of these development frameworks is WebWork, a Web application development framework for Opensymphony groups in open source projects.
The greatest advantage of webwork is its simplicity and flexibility. WebWork has a very small API that allows developers to work quickly on development. WebWork is a combination of many features and applicability, including the use of Variour view techniques, 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). To use the examples provided in this article, you need to create a folder in your application server's WebApps directory, copy the example to a new folder, and copy the required jar files from the webwork distribution to the Web-inf/lib directory. Download WebWork and the source code related to this article here.
------
Actions
One of the most important features of WebWork is the action interface. WebWork actions control Web application processes by providing mapping between the page (view) and business logic. In WebWork, the form is submitted to an action URI (uniform Resource Identifier), which points to a corresponding action;action execution, and the user can advance to the appropriate view.
The following class,loginaction are examples of the webwork process of registering forms based on Web applications. Loginaction extended the Actionsupport. It is a base class that provides handling errors, view mappings, 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 = UserName;
}
Public String Doexecute ()
{
return 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.");
}
}
The loginaction includes two JavaBean attributes, password and username. WebWork sets the property value by placing the data in your view from the attribute and automatically parsing the arguments sent to the action.
The loginaction overloaded two methods of Actionsupport: Dovalidation () and Doexecute (). The Dovalidation () method validates the parameter, and the Doexecute () method allows the user to advance to the appropriate view. The Doexecute () method returns a string that returns a constant success if all the processing is successful. If any problems occur, return constant input on the user input view. Calling Adderror in the Dovalidation () method of loginaction indicates an authentication problem and lets the user return to the input view.
---------
View Mapping
There are two ways to webwork from map to view: Through a action.xml file or a views.properties file. Each action should have an input view and a success view. The following Action.xml documents define two actions,loginjsp and loginvelocity. All two action uses the Loginaction class. If Loginaction returns success, the two action uses the Loginaction class and turns the user to success.html. If Loginaction returns input,action to the corresponding input view, or login.jsp, or LOGIN.VM;
Although WebWork provides support for many different view technologies, the most common are JSP and velociy. The following pages are examples of two registered pages-one using JSP and the other using velocity. Each page includes a user section and a password section that is submitted to the WebWork action.
The login.jsp page establishes and processes the above two sections by using the WebWork tag library and handles errors through the error collector. The Webwork:textfield and Webwork:password tags create the text and password sections, and the webwork:iterator tag handles errors returned from the loginaction. The webwork:property tag sets the Username,password and Errors properties.
The LOGIN.VM page uses the Velocity template language to establish domains and handle errors. In velocity, the $ symbol indicates a reference.! symbols tell velocity. If the reference is empty, then nothing is displayed. #符号表示了一个指令. In the following example, $!username and $!password indicate references to username and password in loginaction; #foreach在错误处理属性中指示了循环.
WebWork is an easy-to-use, flexible, powerful open source Web application framework, this article describes its basic functions. Visit Opensympony's website to learn and download the latest version of WebWork. After you download webwork, go to the top of Jakarta's website to find velocity, a simple, fast open Source engine, which is another option for you to use JSP in your Web pages.
----
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.