Why cant we overide create method in StatelessSessionBean?
From the EJB Spec : – A Session bean’s
home interface defines one or morecreate(…) methods.
Each create method must be named create and must match one of the ejbCreate methods defined in the enterprise Bean class. The
return type of a create method must be the enterprise Bean’s remote interface
type. The home interface of a stateless session bean must have one create
method that takes no arguments.
Is struts threadsafe?Give an example?
Struts
is not only thread-safe but
thread-dependent. 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.
Question: Can we Serialize static variable?
Serialization is the process of converting a
set of object instances that contain references to each other into a linear
stream of bytes, which can then be sent through a socket, stored to a file, or
simply manipulated as a stream of data. Serialization is the mechanism used by
RMI to pass objects between JVMs, either as arguments in a method invocation
from a client to a server or as return values from a method invocation. In the
first section of this book, There are three exceptions in which serialization
does not necessarily read and write to the stream. These are
1. Serialization ignores static fields, because they are not part of any
particular object’s state.
2. Base class fields are only handled if the base class itself is serializable.
3. Transient fields. There are four basic things you must do when you are
making a class serializable. They are:
1. Implement the Serializable
interface.
2. Make sure that instance-level, locally defined
state is serialized properly.
3. Make sure that super class state is serialized
properly.
4. Override equals( )and hashCode(
).
it is possible to have control over serialization process. The class should
implement Externalizable interface. This interface
contains two methods namely readExternal and writeExternal. You should implement these methods and write
the logic for customizing the serialization process …. (Source: http://www.oreilly.com/catalog/javarmi/chapter/ch10.html)
What are the uses of tiles-def.xml file,
resourcebundle.properties file, validation.xml file?
tiles-def.xml is is
an xml file used to configure tiles with the struts application. You can define
the layout / header / footer / body content for your View.
The resourcebundle.properties file is used to configure the message (error/ other messages) for
the struts applications.
The
file validation.xml is used to declare sets of validations that should be
applied to Form Beans.
What is the difference between perform() and execute() methods?
Perform method is the method
which was deprecated in the Struts Version 1.1. In Struts 1.x, Action.perform() is the method called by the ActionServlet. This is typically where your business logic
resides, or at least the flow control to your JavaBeans and EJBs that handle
your business logic. As we already mentioned, to support declarative exception
handling, the method signature changed in perform. Now execute just throws
Exception. Action.perform() is now deprecated; however,
the Struts v1.1 ActionServlet is smart enough to know
whether or not it should call perform or execute in the Action, depending on
which one is available.
What are the various Struts tag libraries?
Struts is very rich framework
and it provides very good and user friendly way to develop web application
forms. Struts provide many tag libraries to ease the development of web
applications. These tag libraries are:
* Bean tag library – Tags for accessing JavaBeans and their properties.
* HTML tag library – Tags to output standard HTML, including forms, text boxes,
checkboxes, radio buttons etc..
* Logic tag library – Tags for generating conditional output, iteration
capabilities and flow management
* Tiles or Template tag library – For the application using tiles
* Nested tag library – For using the nested beans in the application
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:
If
you wanted to use the property “o” instead, as in o=create, you would change
the mapping to
Again, very cool. But why use a JaveScript
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. (Source: http://husted.com/struts/tips/002.html).
No comments:
Post a Comment