Home Database Mysql Tutorial 用WebWork、JSP、Velocity建立注册页面_MySQL

用WebWork、JSP、Velocity建立注册页面_MySQL

Jun 01, 2016 pm 02:11 PM
Establish register page

  
WebWork是一个源代码开放的Web应用框架,用于简化基于Web的应用开发。本专栏介绍了WebWork并且描述了如何使用WebWork和JavaServer Pages(JSP)、Velocity两种技术来建立注册界面的过程。

Web 应用程序的设计开发是复杂并且费时的。然而,你能够通过运用一种框架处理常见的Web应用程序来简化开发流程。许多开源Web应用框架能够做到这一点甚至更好一些。这些开发框架中最好的一个就是WebWork,是开源项目中OpenSymphony组的一个Web应用开发框架。

 WebWork的最大优点是它的简单性和灵活性。WebWork有一个很小的API,它使开发者可以迅速进行开发工作。WebWork是许多特性和适用性的组合,包括使用variour view技术,例如JavaServer Pages(JSP),Velocity,Extensible Stylesheet Language Transformations 
Specification(XSLT)和JasperReporters。WebWork拥有一个活跃的社区,有许多文章、开发者和用户。

注意:本文基于WebWork1.3.0 release candidate 2(RC2)。为了使用本文提供的例子,你需要在你的应用服务器的webapps目录下建立文件夹,将例子拷贝至新的文件夹下,同时将所需的jar文件从WebWork distribution拷贝至WEB-INF/lib目录。在此处下载WebWork和本文相关的源代码。

------
Actions

 WebWork的一个最重要的特色就是Action接口。WebWork actions通过在页面(视图)和商业逻辑间提供mapping来控制Web应用程序流程。在WebWork中,提交窗体到一个action URI(Uniform Resource Identifier);这个URI指向一个相应的action;action执行;用户可以前进到相应的视图。

下述class,LoginAction,是WebWork处理基于Web应用的注册窗体的例子。LoginAction扩展了ActionSupport。它是一个基类,提供了处理错误、视图映射、和许多有用的功能。





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()     if (password == null 
 password.length()   }
}

LoginAction包括了两个JavaBean属性,password和username。WebWork把数据从属性中放置到你的视图中并且自动解析送到action的参数来设置属性值。

 LoginAction重载了ActionSupport的两个方法:doValidation()和doExecute()。doValidation()方法验证参数,doExecute()方法让用户前进到相应的视图。doExecute()方法返回一个字符串,如果所有的处理是成功的,返回常量success。如果有任何问题发生,在用户输入视图上返回常量input。在LoginAction的doValidation()方法中调用addError指出了一个认证问题并且让用户返回INPUT视图。

---------

View mapping
 
WebWork有两种方法从map到视图:通过一个Action.xml文件或者一个views.properties文件。每一种动作应该具有一个INPUT视图和一个SUCCESS视图。下述Action.xml文件定义了两个actions,loginJSP和loginVelocity。这两个action都使用了LoginAction类。如果LoginAction返回SUCCESS,这两个action使用LoginAction类并且使用户转向success.html。如果LoginAction返回INPUT,action转向相应的INPUT视图,或者login.jsp、或者login.vm;








  
    login.jsp
    success.html
  


  
    login.vm
    success.html
  


  --------
视图

尽管WebWork对于许多不同的视图技术提供了支持,但是最为常见的是JSP和Velociy。以下页面是两个注册页面的例子--一个使用了JSP另一个使用了Velocity。每个页面都包括了一个用户部分和一个密码部分,这两部分提交给WebWork action。

Login.jsp页面通过使用WebWork标记库来建立和处理以上两个部分,并且通过错误收集器来处理错误。webwork:textfield 和 webwork:password标记建立了text和password部分,webwork:iterator标记处理从LoginAction返回的错误。 webwork:property标记设置username,password和errors属性。










  


    WebWork JSP Example
  

  

  


    
      
      
    


    
  


  
    

  


  



    login.vm页面使用了Velocity模板语言来建立域并且处理错误。在Velocity中,$符号表明了一个参考。!符号告诉Velocity如果参考为空,那么什么都不显示。#符号表示了一个指令。在下述例子中,$!userName和$!password表明参考引用了LoginAction中的username和password;#foreach在错误处理属性中指示了循环。







  
    WebWork Velocity Example
  

  

  

    
    
    
  


  #foreach ($error in $errors)

$error
  #end

  





---------------
开始工作!
   
WebWork是一个易用的、灵活的、功能强大的开源Web应用框架,本文介绍了它的基本功能。访问OpenSympony的网站去学习并且下载最新版本的WebWork。你下载完WebWork后,到Jakarta的网站的上部去寻找Velocity,一种简单、快速的开源引擎,它是你在网页中使用JSP的另一个选择。
-----------------
作者介绍

Erik Swenson 是Open Source Software Solutions的顾问和建立者。他主要研究使用开源软件和组件来进行java开发。此外,他参与开发了开源项目JasperEdit和OpenReports。
------------------
资源

下载本文相关的源代码
http://www.javaworld.com/javaworld/jw-03-2003/opensource/jw-0307-opensourceprofile.zip

从OpenSymphony网站下载WebWork: 
http://www.opensymphony.com/webwork/

Velocity 是Apache Jakarta项目的一部分,从以下地址下载: 
http://jakarta.apache.org/velocity/index.html

“使用Velocity模板引擎” Geir Magnusson Jr. (JavaWorld,  2001年12月): 
http://www.javaworld.com/javaworld/jw-12-2001/jw-1228-velocity.html

其他开源Web应用框架包括: 

Maverick:
http://mav.sourceforge.net/ 
Struts:
http://jakarta.apache.org/struts/index.html
JasperReports homepage: 
http://jasperreports.sourceforge.net/

Matrix经javaworld授权翻译.加入matrix,与java共舞: www.matrix.org.cn(出处:PConline)
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
How to register multiple accounts on Xiaohongshu? Will I be discovered if I register multiple accounts? How to register multiple accounts on Xiaohongshu? Will I be discovered if I register multiple accounts? Mar 25, 2024 am 09:41 AM

As a platform integrating social networking and e-commerce, Xiaohongshu has attracted more and more users to join. Some users hope to register multiple accounts to better experience interacting with Xiaohongshu. So, how to register multiple accounts on Xiaohongshu? 1. How to register multiple accounts on Xiaohongshu? 1. Use different mobile phone numbers to register. Currently, Xiaohongshu mainly uses mobile phone numbers to register accounts. Users sometimes try to purchase multiple mobile phone number cards and use them to register multiple Xiaohongshu accounts. However, this approach has some limitations, because purchasing multiple mobile phone number cards is cumbersome and costly. 2. Use email to register. In addition to your mobile phone number, your email can also be used to register a Xiaohongshu account. Users can prepare multiple email addresses and then use these email addresses to register accounts. but

How to register a Manwa Comics account How to register a Manwa Comics account Feb 28, 2024 am 08:00 AM

On the Manwa Comics platform, there are rich comic resources waiting for everyone to explore. As long as you easily enter the official platform of Manwa Comics, you can enjoy all kinds of wonderful comic works. Everyone can easily find their favorite comics to read according to their own preferences. So how to register the official account of Manwa Comics? The editor of this website will bring you this detailed tutorial guide, hoping to help everyone in need. Manwa Comics-Official entrance: https://fuw11.cc/mw666 Manwa Comics app download address: https://www.siemens-home.cn/soft/74440.html Manwa Comics non-mainland area entrance: https: /

How to copy a page in Word How to copy a page in Word Feb 20, 2024 am 10:09 AM

Want to copy a page in Microsoft Word and keep the formatting intact? This is a smart idea because duplicating pages in Word can be a useful time-saving technique when you want to create multiple copies of a specific document layout or format. This guide will walk you through the step-by-step process of copying pages in Word, whether you are creating a template or copying a specific page in a document. These simple instructions are designed to help you easily recreate your page without having to start from scratch. Why copy pages in Microsoft Word? There are several reasons why copying pages in Word is very beneficial: When you have a document with a specific layout or format that you want to copy. Unlike recreating the entire page from scratch

How to check what is registered with a mobile phone number 'Detailed explanation: APP query method for mobile phone number registration' How to check what is registered with a mobile phone number 'Detailed explanation: APP query method for mobile phone number registration' Feb 07, 2024 am 08:24 AM

I don’t know if you have such an experience. Your mobile phone often receives some inexplicable text messages, or registration information for some websites or other verification information. In fact, our mobile phone number may be bound to many unfamiliar websites, and we ourselves Even if you don’t know, what I will share with you today is to teach you how to unbind all unfamiliar websites with one click. Step 1: Open the number service platform. This technique is very practical. The steps are as follows: Open WeChat, click the plus icon in the search box, select Add Friend, and then enter the code number service platform to search. We can see that there is a number service platform. Of course, it belongs to a public institution and was launched by the National Institute of Information and Communications Technology. It can help everyone unbind mobile phone number information with one click. Step 2: Check whether the phone has been marked for me

How to register 163 email How to register 163 email Feb 14, 2024 am 09:20 AM

Some users find that they do not have an account when they want to use 163 mailbox. So what should they do if they need to register an account at this time? Now let’s take a look at the 163 email registration method brought by the editor. 1. First, search the 163 Email official website in the browser and click [Register a new account] on the page; 2. Then select [Free Email] or [VIP Email]; 3. Finally, after selecting, fill in the information and click [Now Just register];

How to register a Xiaohongshu account? What is required to register a Xiaohongshu account? How to register a Xiaohongshu account? What is required to register a Xiaohongshu account? Mar 22, 2024 am 10:16 AM

Xiaohongshu, a social platform integrating life, entertainment, shopping and sharing, has become an indispensable part of the daily life of many young people. So, how to register a Xiaohongshu account? 1. How to register a Xiaohongshu account? 1. Open the Xiaohongshu official website or download the Xiaohongshu APP. Click the "Register" button below and you can choose different registration methods. Currently, Xiaohongshu supports registration with mobile phone numbers, email addresses, and third-party accounts (such as WeChat, QQ, Weibo, etc.). 3. Fill in the relevant information. According to the selected registration method, fill in the corresponding mobile phone number, email address or third-party account information. 4. Set a password. Set a strong password to keep your account secure. 5. Complete the verification. Follow the prompts to complete mobile phone verification or email verification. 6. Perfect the individual

How to register a Xiaohongshu account? How to recover if its account is abnormal? How to register a Xiaohongshu account? How to recover if its account is abnormal? Mar 21, 2024 pm 04:57 PM

As one of the most popular lifestyle sharing platforms in the world, Xiaohongshu has attracted a large number of users. So, how to register a Xiaohongshu account? This article will introduce you to the Xiaohongshu account registration process in detail, and answer the question of how to recover Xiaohongshu account abnormalities. 1. How to register a Xiaohongshu account? 1. Download the Xiaohongshu APP: Search and download the Xiaohongshu APP in the mobile app store, and open it after the installation is complete. 2. Register an account: After opening the Xiaohongshu APP, click the "Me" button in the lower right corner of the homepage, and then select "Register". 3. Fill in the registration information: Fill in the mobile phone number, set password, verification code and other registration information according to the prompts. 4. Complete personal information: After successful registration, follow the prompts to complete personal information, such as name, gender, birthday, etc. 5. Settings

How to register a qooapp account How to register a qooapp account Mar 19, 2024 pm 08:58 PM

qooapp is a software that can download many games, so how to register an account? Users need to click the "Register" button if they don't have a pass yet, and then choose a registration method. This account registration method introduction is enough to tell you how to operate it. The following is a detailed introduction, so take a look. How to register a qooapp account? Answer: Click to register, and then choose a registration method. Specific methods: 1. After entering the login interface, click below. Don’t have a pass yet? Apply now. 2. Then choose the login method you need. 3. You can use it directly after that. Official website registration: 1. Open the website https://apps.ppaooq.com/ and click on the upper right corner to register. 2. Select registration

See all articles