Thursday, 12 July 2012

Commonly Used Struts Tags in Java


Commonly Used Struts Tags
Struts Studio comes with support for the three most common Struts JSP tag libraries:
For the tags in these libraries, the tables below show the names (without the required prefixes), whether the tag is for an empty element (<emptyElementTag /> versus <elementTag>...</elementTag>), required attributes, and optional attributes.
Each of these tag names must be prefixed with bean: when using.
tag name
empty
required attributes
optional attributes
cookie
yes
id, name
multiple, value
define
yes
id
name, property, scope, toScope, type, value
header
yes
id, name
multiple, value
include
yes
id
anchor, forward, href, name, page, transaction
message
yes

arg0, arg1, arg2, arg3, arg4, bundle, key, locale, name, property, scope
page
yes
id, property

parameter
yes
id, name
multiple, value
resource
yes
id, name
input
size
yes
id
collection, name, property, scope
struts
yes
id
formBean, forward, mapping
write
yes

bundle, filter, format, formatKey, ignore, locale, property, scope

Each of these tag names must be prefixed with html: when using.
tag name
empty
required attributes
optional attributes
base
yes

server, target
button
yes
property
accesskey, alt, altKey, disabled, indexed, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, style, styleClass, styleId, tabindex, title, titleKey, value
cancel
yes
property
accesskey, alt, altKey, disabled, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, property, style, styleClass, styleId, tabindex, title, titleKey, value
checkbox
yes
property
accesskey, alt, altKey, disabled, indexed, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, style, styleClass, styleId, tabindex, title, titleKey, value
errors
yes

bundle, locale, name, property
file
yes
property
accept, accesskey, alt, altKey, disabled, indexed, maxlength, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, size, style, styleClass, styleId, tabindex, title, titleKey, value
form
no
action
enctype, focus, focusIndex (1.1+), method, name (depricated), onreset, onsibmit, scope (depricated), style, styleClass, styleId, target, type (depricated)
frame
no

action, anchor, forward, frameborder, frameName, href, longdesc, marginheight, marginwidth, name, noresize, page, paramId, paramName, paramProperty, paramScope, property, scope, scrolling, style, styleClass, styleId, title, titleKey, transaction
hidden
yes
property
accesskey, alt, altKey, indexed, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, style, styleClass, styleId, title, titleKey, value, write
html
no

locale, xhtml
image
yes

accesskey, align, alt, altKey, border, bundle, disabled, indexed, locale, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, page, pageKey, property, src, srcKey, style, styleClass, styleId, tabindex, title, titleKey, value
img
yes

align, alt, altKey, border, bundle, height, hspace, imageName, ismap, locale, lowsrc (deprecated), name, onclick, ondblclick, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, page, pageKey, paramId, paramName, paramProperty, paramScope, property, scope, src, srcKey, style, styleClass, styleId, title, titleKey, usemap, vspace, width
javascript
no

cdata (1.1+), dynamicJavascript, formName, htmlComment, method, page, src, staticJavascript
link
no

accesskey, action, anchor, forward, href, indexed, indexId, linkName, name, onblur, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, page, paramId, paramName, paramProperty, paramScope, property, scope, style, styleClass, styleId, tabindex, target, title, titleKey, transaction
messages
no
id
bundle, footer, header, locale, message, name, property
multibox
yes
property
accesskey, alt, altKey, disabled, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, style, styleClass, styleId, tabindex, title, titleKey, value
option
no

bundle, disabled, key, locale, style, styleClass, styleId
options
no

collection, filter, labelName, labelProperty, name, property, style, styleClass
optionsCollection
no
property
filter, label, name, style, styleClass, value
password
yes
property
accesskey, alt, altKey, disabled, indexed, maxlength, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, readonly, redisplay, size, style, styleClass, styleId, tabindex, title, titleKey, value
radio
yes
property, value
accesskey, alt, altKey, disabled, idName (1.1+), indexed, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, pointer, property, style, styleClass, styleId, tabindex, title, titleKey
reset
yes

accesskey, alt, altKey, disabled, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, pointer, property, style, styleClass, styleId, tabindex, title, titleKey, value
rewrite
yes

anchor, forward, href, name, page, paramId, paramName, paramProperty, paramScope, property, scope, transaction
select
no
property
alt, altKey, disabled, indexed, multiple, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, size, style, styleClass, styleId, tabindex, title, titleKey, value
submit
yes

accesskey, alt, altKey, disabled, indexed, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, property, style, styleClass, styleId, tabindex, title, titleKey, value
text
yes
property
accesskey, alt, altKey, disabled, indexed, maxlength, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, readonly, size, style, styleClass, styleId, tabindex, title, titleKey, value
textarea
no
property
accesskey, alt, altKey, cols, disabled, indexed, name, onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, readonly, rows, style, styleClass, styleId, tabindex, title, titleKey, value
xhtml
yes


Each of these tag names must be prefixed with logic: when using.
tag name
empty
required attributes
optional attributes
empty
no

name, property, scope
equal
no
value
cookie, header, name, parameter, property, scope
forward
yes
name

greaterEqual
no
value
cookie, header, name, parameter, property, scope
greaterThan
no
value
cookie, header, name, parameter, property, scope
iterate
no
id
collection, indexId, length, name, offset, property, scope, type
lessEqual
no
value
cookie, header, name, parameter, property, scope
match
no
value
cookie, header, location, name, parameter, property, scope
messagesNotPresent
no

message, name, property
messagesPresent
no

message, name, property
notEmpty
no

message, name, property
notEqual
no
value
cookie, header, name, parameter, property, scope
notMatch
no
value
cookie, header, name, parameter, property, scope
notPresent
no

cookie, header, name, parameter, property, role, scope, user
present
no

cookie, header, name, parameter, property, role, scope, user
redirect
yes

cookie, header, name, parameter, property, role, scope, user









Struts from Scratch
By Kevin Bedell

Go to page: 1  2  Next  
This article lays out the steps for installing Struts and a basic "Hello World!" sample application 'from scratch.' It assumes that you are brand new to Struts and that you're also fairly new to Java ServerPages (JSP) and programming in general.
The goal of this article is to go through the basics of installing and building a Struts application; the details of the application itself are not covered. The application is taken from my recent book, Struts Kick Start, and is covered in detail there. The application and build files described in this article can be downloaded from the book's companion Web site (http://www.strutskickstart.com).
Although some of the material in this article may seem very basic to an experienced Java developer, I've had a number of people express frustration to me that they were unable to locate a set of very basic instructions for installing Struts and getting a beginning application running. This is the problem addressed by this article.
Before we begin, it's worth stating that Struts does require some knowledge of Java and JSP to be used effectively. If you are brand new to Java Programming or JSP, it's recommended that you get some base knowledge of those technologies before diving too deeply into Struts. Spending a little extra time preparing yourself will make learning Struts a lot less frustrating for you.

Preparing your Computer to Install Struts

Before you install Struts, there are some configuration steps that need to be completed on your machine. This section leads you through those steps and gets you ready to install and begin working with Struts.
While this article assumes you have a computer running one of the Microsoft Windows operating systems, modifying the steps to work under Linux (or some other Unix variant) would require only minor changes.

Installing Java

Struts is based on Java, so running it requires you have Java installed. This article uses Sun's Java 2 Platform Standard Edition v1.4.1 (also known as JDK 1.4.1). The JDK 1.4.1 can be downloaded free from Sun's Web site at http://java.sun.com/j2se/1.4.1/index.html. Earlier versions of Sun's JDK can be used, but 1.4.1 is the most current version.
If you've done any programming in Java, it's likely that you already have this (or some other) version of Java installed. To see if you have Java installed already (or to see what version you have), from a command line, simply type "java -version". The output from this command run on my computer is as follows:
// Testing your Java Installation.
 
  c:\dev>java -version
  java version "1.4.1_01"
  Java(TM) 2 Runtime Environment, Standard Edition
           (build 1.4.1_01-b01)
  Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
If running this command doesn't show that you have a version of Java installed, you need to install a JDK on your computer before you can install Struts. Installing the JDK is like installing any other application on your machine. I'd recommend just following the defaults unless you have specific reasons not to. You can download the JDK from the link above.
Once Java is installed, you need to ensure that you have two environment settings configured. They are:
  • Set JAVA_HOME to point to the top level directory where your JDK is installed. On my machine, I installed the JDK 1.4.1 in the directory C:\j2sdk1.4.1_01 so that's the value I would use as my JAVA_HOME.
  • Add JAVA_HOME\bin to your path so that you can execute the java program itself. In my case this means adding the directory c:\j2sdk1.4.1_01\bin to my PATH variable.
Because each version of Windows (or Unix shell) provides a slightly different way of setting environment variables, you'll have to refer to other documentation to determine how to do this for your environment. After you've completed these steps, you should be able to open a new window, type the java -version command and see output similar to the example above.

Installing Ant So You Can Build Web Archive (WAR) Files

Once you've verified that you have Java installed correctly, the next thing you need do is install Ant. Ant is a program used to compile, build, and deploy Java programs. It, like Struts, is an open source program from the Apache Software Foundation. Ant is widely used by Java developers for all kinds of tasks related to building, testing, and deploying Java applications. Ant is available for free from the the Apache Ant Project's Web site at http://ant.apache.org/.
You need to have Ant installed because there is more to running Struts programs than simply compiling your java files. Struts applications are stored in what are called Web ARchive files (also called "WAR" files). Ant coordinates the process of taking your Java files, your JSP files, and all the other files that make up a Struts application and using them to build the WAR files that are needed to run the application.
WAR files are defined as part of the Java 2 Enterprise Edition (J2EE) standard. This is the same standard that defines the operation of Tomcat (and other servlet engines). Among the other Java technologies defined by the J2EE standard are Enterprise Java Beans (EJBs), the Java Message Service (JMS), and Java Mail. Using JSP and WAR files is a great way to get introduced to the J2EE standard.
Installing Ant is required to take advantage of the automated build scripts provided for the sample application. If you are currently a Java developer, you likely have Ant already installed. If you don't have it installed, this section provides the steps you need to follow to install it.
Similar to verifying your Java installation, you can verify your Ant install by typing the command ant -version. The results of running this command on my computer are shown below:
// Testing your Ant Installation.
 
  c:\dev>ant -version
  Apache Ant version 1.5.1 compiled on October 2 2002
    
To install Ant, simply download its binary files from http://ant.apache.org and unzip the downloaded file into a convenient directory. For myself, I installed Ant into a directory named C:\jakarta-ant-1.5, but then renamed the directory to C:\ant to keep things simple.
Similar to installing Java, you now need to change two environment settings for everything to work. They are:
  • Set ANT_HOME to point to the top level directory where Ant is installed. On my machine, this value is C:\ant.
  • Add ANT_HOME\bin to your path so that you can execute the Ant program itself. In my case, this means adding the directory C:\ant\bin to my PATH variable.
To verify your installation, you can type ant -version to verify that Ant will run. The output should be similar to what you see in the section above. Now Ant should be installed and configured correctly and we're ready to install the Apache Tomcat server.

Installing Tomcat

Apache Tomcat is referred to as a "Servlet Engine" or "Servlet Container." This means that it conforms to the standards defined for running applications based on Java Servlets and Java ServerPages. (In fact, Tomcat is the 'Reference Implementation' of these standards.) Because Struts is based on Java Servlet and Java ServerPages technologies, you need a servlet container for your Struts applications to run.
There are a great number of other servlet containers available including Weblogic, Websphere, Resin, and many more. We're using Tomcat because it is widely available and easy to find and install. If you need Tomcat, you can download a copy of it from the Apache Jakarta Project at http://jakarta.apache.org/tomcat.
There are a number of ways to install Tomcat. We will install using the Win32 installation file jakarta-tomcat-4.1.12.exe. This install uses an installshield-like installer from nullsoft. The only change to the default installation I'd recommend is overriding the installation location to some path that does not contain spaces (I used \dev\tomcat). I've seen situations where having embedded spaces in the path to the Tomcat files can cause problems during the Ant build process.
After you've completed the Tomcat installation, you should be able to start Tomcat and then open a browser on your machine and point it to the location http://localhost:8080/ to see the default Tomcat info page.

Installing Struts

Now that we have all the preliminary work completed, it's finally time to install Struts!
There are two sets of files that make up Struts: The Struts binaries (as they are referred to on the Struts site) and the Struts source files. This section only discusses the binaries because these are what you use to develop Struts applications. If you don't already have a copy of Struts, you can download it via the Jakarta Struts home page at http://jakarta.apache.org/struts. Get the binaries of the latest release of the 1.1 version of Struts.
From the perspective of someone developing applications, the Struts binaries are really just a collection of files. These files (.jar's, .tld's, .properties, and si forth) contain the Struts application files along with configuration information, error messages, and so on.
Installing Struts is really just copying all these files on to your computer in a way that makes it convenient for your application to access them. This is why there's no setup.exe installation file for Struts—all you do is unzip Struts into a directory and start working!
On my computer, I unzipped Struts into the C:\dev\jakarta-struts-1.1-rc1 directory and then renamed it to C:\dev\struts to make it easier to work with. This is all that's required to install Struts.

2 comments:

  1. hi!,I like your writing very a lot! proportion we keep in touch extra approximately your post on AOL?
    I require a specialist on this house to solve my problem.
    Maybe that is you! Having a look ahead to see you.

    my weblog; Düfte

    ReplyDelete
  2. It’s actually a great and useful piece of information.

    I’m glad that you shared this useful information with
    us. Please stay us informed like this. Thanks for sharing.



    my weblog ... Alain delon

    ReplyDelete

Write your openion about my blog spot..To get automatic facebook updates like my Pagehttps://www.facebook.com/shivashankar4u ..It takes only 1 min to write the comment and to like the page.. Thanks.