WEB application using SNAP
Create a login page with Webwork, JSP, and Velocity
Overview
Webwork is an open source web application framework. The aim is to simplify web application development. This column introduces WebWork and explains the creation process of logging in to the web page using Webwork and two different view technology, JavaServerPages (JSP), and Velocity.
Web applications and development are complex and time consuming. However, you can use a framework to process a normal web application development task to simplify the process. Several Open Source The web application framework can do this and do more. The best one is Webwork, a web application framework for the OpenSymphony group from an open source project.
The biggest advantage of Webwork is its simple and flexible. Webwork has a small API. The API allows developers to start and run immediately. WebWork offers many properties and flexible integrated performance, including: using different view technologies such as JavaServerPages (JSP), Velocity, Scalable Single Language Conversion Description (XSLT), and JasperReports,
Note: This article is based on an alternative book 2 released by WebWork 1.3.0. In order to run the example, you need to create a folder in a webApps directory of your application server, copy the example into the new folder, and copy the required JAR file from the webwork distribution to the web-inf / lib directory. . Download Webwork and the source code required for this article from Resources.
Action
One of the most important features in Webwork is the Action interface. WebWork Action provides a map between page (or view) and corporate logic to control a web application. In WebWork, the form is submitted to an Action URI (the same resource tag); the URI is mapped to a corresponding action; performing the action; so that the user advances to the right view.
The next class, LoginAction is an example of the webwork action that handles the login form in a web-based application. LoginAction comes from extension ActionSupport, a base class that provides error handling, view mapping, and many other 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.");}} LoginAction Contains two JavaBeaN properties, Password, and username. WebWork will remove data from these properties, put the data you need into your view; and you can automatically explain any parameters to set the attribute value in the action.
LoginAction uses two functions from ActionSupport: DOVALIDATION () and DoExecute (). Dovalidation () function verifies the legality of the parameters and drives the user forward to the appropriate view by the doexecute () function. The doexecute () function returns a string. If the string is a constant success, the string is a constant input, which is sent back to the INPUT view, and the Dovalidation () function call in the loginaction Adderror indicates an illegal parameter problem and returns the user to the INPUT view.
View mapping
WebWork ACION maps to the view with two methods: via an action.xml file or a views.properties file. Each ACION should have an INPUT view and a Success view. The next Action.xml file defines two Actions: LoginJSP and Loginvelocity. Both actions use the LoginAction class. If loginaction returns Success, take the user to Success.html. If loginaction returns INPUT, the action is moving to the corresponding INPUT view, which is either login.jsp, or login.vm:
WebWork provides support for many different view technologies, the most common to make JSP and Velocity. The following page is two login page examples - one created with JSP and creates it with Velocity. Each page contains a form with a username and password field submitted to a WebWork action.
Login.JSP Pages use the WebWork tag library, create and iterate two fields and repeat iterations by collecting errors. Webwork: TextField and Webwork: Password tag creates text and cryptographic fields, and Webwork: Iterator tag repeats any errors returned from loginAction. Webwork: Property tag set UserName, Password, and Erroors properties:
<% @ Taglib Uri = "Webwork" prefix = "Webwork"%>