l Groovy is a agile development language on the Java platform, which simplifies code, improves coding efficiency.
l Groovy = 50% Java code 50% Simplified task development time
l In WebWork2, you can use Groovy to simplify code, improve coding efficiency.
l example:
Package web
Import java.util.date
Import org.apache.commons.logging.log
Import org.apache.commons.logging.logfactory
Import com.opensymphony.xwork.Actionsupport
Class GroovyAction Extends ActionSupport {
Protected final log logger = logfactory.getlog (getclass ())
Private string now
String execute () {
Now = "$ {new date ()}"
Logger.info ("Returning View with $ {now}")
"Success"
}
Void setNow {
THIS.NOW = now
}
String getnow () {
NOW
}
}
l The above Action class is a Groovy class, which extends the ActionSupport, here you should pay attention:
Ø Execute () method does not have the throws Exception statement, because the current Groovy has no this Java feature, which requires an increase in future versions; if added, compile will report an error
Ø Execute () method Returns, do not use constants similar to Success, but use the corresponding value (such as "success)); if you use Success, Groovy will parse it into a class of properties, throwing it
L Of course, in the / web-inf / lib directory, you need to include Running JAR files: Groovy and ASM, I use Groovy-1.0-Beta-7.jar and ASM-1.4.3.jar (in Groovy) Lib Directory)