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;
视图
尽管WebWork对于许多不同的视图技术提供了支持,但是最为常见的是JSP和Velociy。以下页面是两个注册页面的例子--一个使用了JSP另一个使用了Velocity。每个页面都包括了一个用户部分和一个密码部分,这两部分提交给WebWork action。
Login.jsp页面通过使用WebWork标记库来建立和处理以上两个部分,并且通过错误收集器来处理错误。webwork:textfield 和 webwork:password标记建立了text和password部分,webwork:iterator标记处理从LoginAction返回的错误。 webwork:property标记设置username,password和errors属性。
login.vm页面使用了Velocity模板语言来建立域并且处理错误。在Velocity中,$符号表明了一个参考。!符号告诉Velocity如果参考为空,那么什么都不显示。#符号表示了一个指令。在下述例子中,$!userName和$!password表明参考引用了LoginAction中的username和password;#foreach在错误处理属性中指示了循环。
#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)

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,idealforconsistentlengthdatalikecountrycodes;2)VARCHARforvariable-lengthstrings,suitableforfieldslikenames;3)TEXTtypesforlargertext,goodforblogpostsbutcanimpactperformance;4)BINARYandVARB

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools
