|
How you
will display validation fail errors on jsp page? |
Following tag displays all the errors:
|
|
How you
will enable front-end validation based on the xml in
validation.xml? |
The
tag to allow front-end validation based on the
xml in validation.xml. For example the code:
generates the client side java script for the form "logonForm"
as defined in the validation.xml file. The
when added in the jsp file generates the client
site validation script.
|
|
Can I
setup Apache Struts to use multiple configuration files? |
Yes Struts can use multiple configuration
files. Here is the configuration example:
<servlet>
<servlet-name>banking</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml,
/WEB-INF/struts-authentication.xml,
/WEB-INF/struts-help.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
|
|
How you
will make available any Message Resources Definitions file to
the Struts Framework Environment? |
Message Resources Definitions file are
simple .properties files and these files contains the messages
that can be used in the struts project. Message Resources
Definitions files can be added to the struts-config.xml file
through
tag.
Example:
|
|
What is
Struts Flow? |
Struts Flow is a port of Cocoon's Control
Flow to Struts to allow complex workflow, like multi-form
wizards, to be easily implemented using continuations-capable
JavaScript. It provides the ability to describe the order of Web
pages that have to be sent to the client, at any given point in
time in an application. The code is based on a proof-of-concept
Dave Johnson put together to show how the Control Flow could be
extracted from Cocoon. (Ref: http://struts.sourceforge.net/struts-flow/index.html
)
|
|
What are
the difference between
and
? |
: This tag is used to output locale-specific text
(from the properties files) from a MessageResources bundle.
: This tag is used to output property values from a
bean.
is a commonly used tag which enables the programmers
to easily present the data.
|
|
What is
LookupDispatchAction? |
An abstract Action that dispatches to the
subclass mapped execute method. This is useful in cases where an
HTML form has multiple submit buttons with the same name. The
button name is specified by the parameter property of the
corresponding ActionMapping.
|
|
What do
you understand by DispatchAction? |
DispatchAction is an action that comes
with Struts 1.1 or later, that lets you combine Struts actions
into one class, each with their own method. The
org.apache.struts.action.DispatchAction class allows multiple
operation to mapped to the different functions in the same
Action class.
For example:
A package might include separate RegCreate, RegSave, and
RegDelete Actions, which just perform different operations on
the same RegBean object. Since all of these operations are
usually handled by the same JSP page, it would be handy to also
have them handled by the same Struts Action.
A very simple way to do this is to have the submit button modify
a field in the form which indicates which operation to perform.
SAVE
SAVE AS NEW
DELETE
Then, in the Action you can setup different methods to handle
the different operations, and branch to one or the other
depending on which value is passed in the dispatch field.
String dispatch = myForm.getDispatch();
if ("create".equals(dispatch)) { ...
if ("save".equals(dispatch)) { ...
The Struts Dispatch Action [org.apache.struts.actions] is
designed to do exactly the same thing, but without messy
branching logic. The base perform method will check a dispatch
field for you, and invoke the indicated method. The only catch
is that the dispatch methods must use the same signature as
perform. This is a very modest requirement, since in practice
you usually end up doing that anyway.
To convert an Action that was switching on a dispatch field to a
DispatchAction, you simply need to create methods like this
public ActionForward create(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException { ...
public ActionForward save(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException { ...
Cool. But do you have to use a property named dispatch? No, you
don't. The only other step is to specify the name of of the
dispatch property as the "parameter" property of the
action-mapping. So a mapping for our example might look like
this:
path="/reg/dispatch"
type="app.reg.RegDispatch"
name="regForm"
scope="request"
validate="true"
parameter="dispatch"/>
If you wanted to use the property "o" instead, as in o=create,
you would change the mapping to
path="/reg/dispatch"
type="app.reg.RegDispatch"
name="regForm"
scope="request"
validate="true"
parameter="o"/>
Again, very cool. But why use a JavaScript button in the first
place? Why not use several buttons named "dispatch" and use a
different value for each?
You can, but the value of the button is also its label. This
means if the page designers want to label the button something
different, they have to coordinate the Action programmer.
Localization becomes virtually impossible.
|
|
Is struts
threadsafe?Give an example? |
Struts is not only thread-safe but
thread-dependant. The response to a request is handled by a
light-weight Action object, rather than an individual servlet.
Struts instantiates each Action class once, and allows other
requests to be threaded through the original object. This core
strategy conserves resources and provides the best possible
throughput. A properly-designed application will exploit this
further by routing related operations through a single Action
PREVIOUS
NEXT |