Webwork/JSP/velocity login page

Source: Internet
Author: User
Webwork/JSP/velocity login page
Author: Erik Swenson, Chen Xiaoyu (Translated by: 20:32:48)
Overview

Webwork is an openSource codeWeb application framework. The purpose is to simplify web application development. This topic introduces webwork and explains the process of creating a login webpage using webwork and two different view technologies: assumerverpages (JSP) and velocity.

Web ApplicationsProgramAnd Development is complex and time-consuming. However, you can use a framework to process common web application development tasks to simplify the process. Several open sourcesCodeWeb application frameworks can do this and do more. The best one is webwork, a Web application framework from the opensymphony group of open source projects.

The biggest advantage of webwork is its simplicity and flexibility. Webwork has a small API. This API allows developers to start and run immediately. Webwork provides many attributes and flexible comprehensive performance, including: using different view technologies, such as javaserverpages (JSP), velocity, Scalable Single-language conversion instructions (XSLT), and jasperreports,.

Note: This article is based on the alternative version 2 released by webwork 1.3.0. To run the provided example, you need to create a folder in the webapps directory of your application server and copy the example to the new folder, and copy the required JAR file from the webwork distribution to the WEB-INF/lib directory. Download the source code for webwork and this article from resources.

Action

One of the most important features of webwork is the action interface. Webwork action provides ing between pages (or views) and enterprise logic to control the process of a Web application. In webwork, the form is submitted to an action uri (the same resource identifier); The URI is mapped to a corresponding action; the action is executed; then the user moves to the appropriate view.

The next class, loginaction, is an example of webwork action for processing login forms in Web-based applications. Loginaction comes from the extended actionsupport. It is a base class that provides error handling, view ing, and many other useful functions:

     
      
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 attributes: password and username. webwork extracts data from these attributes and puts the data you need into your view. It can automatically interpret any parameters and send them to action to set attribute values.

Loginaction uses two functions from actionsupport: dovalidation () and doexecute (). The dovalidation () function verifies the validity of the parameter, and the doexecute () function drives the user forward to the appropriate view. The doexecute () function returns a string. If the processing is successful, the string is the constant success. If there is a problem, the string is the constant input, and the user is returned to the input view, the dovalidation () function in loginaction calls adderror, which indicates that an invalid parameter problem occurs and the user is returned to the input view.

View ing

Webwork acion is mapped to a view in two ways: through an action. xml file or an views. properties file. Each acion should have an input view and a success view. The following action. xml file defines two actions: loginjsp and loginvelocity. Both regions use the loginactionclass. If loginactionreturns to success, the user is directed to success.html. If loginaction returns input, the action takes the user forward to the corresponding Input view. This action is either login. jsp or login. VM:


     
      
<Actions> <action name = "loginaction" alias = "loginjsp"> <view name = "input"> login. JSP </View> <view name = "success"> success.html </View> </Action> <action name = "loginaction" alias = "loginvelocity"> <view name =" input "> login. VM </View> <view name = "success"> success.html </View> </Action> </actions>

     

View

Webwork provides support for many different view technologies, the most common use of JSP and velocity. The following are two logon page examples: one created using JSP and the other created using velocity. Each page contains a form with the username and password fields submitted to a webwork action.

The login. jsp page uses webwork to mark the library, creates and iterates two fields, and repeats iteration through collection errors. Webwork: textfield and webwork: Password mark create text and password fields, and webwork: iterator mark duplicate iterations of any errors returned from loginaction. Webwork: The property tag sets the username, password, and errors attributes:


     
      
<% @ Taglib uri = "webwork" prefix = "webwork" %> <HTML> 

The login. VM page uses the velocity temporary language to add domains and iterate over all errors. In velocity, $ represents a reference ;! The symbol tells velocity that if the reference is null, nothing is displayed; # The symbol indicates an instruction. In the following example, $! Username and $! Password is used to access the username and password attributes of loginaction. # The foreach command loops through the errors attribute:


     
      
<HTML> 

Webwork is a simple, flexible, and powerful open-source Web application framework. This section describes the basic webwork functions. Visit the opensympony website to learn more instructions and download the updated webwork version. After the download is complete, go to the Jakarta site and have a look at velocity, a simple and fast open source temporary engine, which is a backup option for JSP on your web page.

[About the author]

Erik Swenson is a consultant and founder of open source software solutions. He is proficient in Java development using open source software and components, and has developed jasperedit and openreports open source projects.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.