You are on page 1of 15

1)why servlet is used as controller ?not JSP?

i want complete
Explation?
Most of the applications are created in MVC design pattern to seperate the functions of
differnet components and handle the complexity of applications. JSP and Servlets are the
server side components which can respond to the client request.
Servlets are the basic components for request handling in Web Server. They contains pure
Java code. Everything that needs to be done to generate the proper user response (which
is genarally HTML code) needs to be done through coding. As a single servlet
cannot respond each and every request by itself as client request varies in type (e.g.
enquiry, update request, add etc) the request and response object is passed onto different
servlets with little task completed by each servlet. This controlling part is easier to write
in java. So Servlet is used as controller.

JSP is again a servlet which has syntax more like to HTML with java support. Whatever user is going to see
as result of his request is HTML. Programmer can easily write html tags inside JSP to render html. This is
very economical to change also. So all this code is written JSP which is (generally) the final link in Servlet
chaining. In simple words, Controller (servlet) has pure Java code while View (JSP) has HTML code.

2) can i have more than one ActionServlet class file in my application?

Yes, you can have tow ActionServlet class per context but then you should must have two
different struts config files and their pattern

3) What is the difference betwwen struts 1.1 and struts 1.2?

struts 1.2 added new features. the usage of template tags and nested tags.

where to use template tags and struts tags

in servlet 1.1 there is actionPerformed() method whereas in struts 1.2 there is execute()
method

4) Should every html form property have a corresponding formbean get/set and
variable.?
Can form property be omitted in a form bean?
Yes every html field property have a corresponding formbean get/set methods. Otherwise you
will get this (No getter Method) error.

Get & Set are not compalsary for each form. when you specify type as DyanActionForm in the form bean in
struts-config.xml as below, with each field declared as form-property

<form-bean name="DynaAddressForm"
type="org.apache.struts.action.DynaActionForm">
<form-property name="name" type="java.lang.String"/>
<form-property name="address" type="java.lang.String"/>
<form-property name="email" type="java.lang.String" />
</form-bean>

5) Can input form property be omitted in a formbean ? is it mandatory for every form
property to have a corresponding formbean get/set and variable ?

Input form property cannot be ommitted it is mandatory property Yes , you can left. (Try it ) Other wise I will
show you.....
6) What are the Actions in Struts?

Struts framework provides us some inbuilt action classes like FORWARD ACTION, INCLUDE ACTION,
DISPATCH ACTION, LOOKUPDISPATCH ACTION AND SWITCH ACTION.

7) How can we write more than formbean in Action class?

we can use the dynaactionForm instade of only formbeans . the dynaactionform is framework class provided
by the apache struts. Using this perticular class we do not need to write formbeans this will generate the
beans automatically only need to mapp the fields to struts-config.xml and the datatypes of the fiels this will
generate the fields and their setter and getter methods too........

8) How to add multiple .property files in Sturts-config.xml file..?


hi friend ,in struts-config.xml file message-resources tag is therein that place you have to put
how many u want just include
9) how can we communicate from struts to ejb?

strut frame work have Action class. This Action class contain execute() method.this method interact with
model......your model code maybe in EJB/JDBC/Hibernate.......u can call that methods in execute().

with in the execute() u can call business delegate---> service loactor--->jndi--->to SessionFacade

10) 3.a) what is the difference between struts 1.0 and struts 1.1

Struts 1.0 - Each ActionForm bean is required for same type of field validation(Suppose in 10 screens if you
want to validate the phone number) and in action class perform() method.

Struts1.1 - DynaActionForm is introduced in 1.1 and you can use one DynaActionForm for multiple
screens/pages. Execute() method is introduced.

one more difference is struts1.0 throws only two exceptions IOException & ServletException.in
struts1.1 through all exceptions

srtuts 1.0 and 1.1 many difference s are availble

struts 1.0 here validation not availbe

struts 1.1 added actionclasses include action

dispatch action validator, tiles

11) What is the difference between ForwardAction and IncludeAction?

ForwardAction Provides a mechanism for forwarding to a specified URL.Whereas IncludeAction Provides a


mechanism for including the contents of a specified URL.

1.forward action is similar to <jsp:forward> and include action is similar to <jsp:include> in jsp

2. forward action is used to forward to control from one page to another page or action.

include action is used to include action in another action.

U can do forwards either in two ways.


using forward action or Global forwards.

12) Can I have more than one struts-config.xml file for a single Struts application?

No because of the struts-config.xml file is a deployment discriptor of the particulare struts


application.

Yes, It is possible in case of maintaing seperate module specific information.

Yes we can.. for example..

<init-param>

<param-name>config</param-name>

<param-value>/WEB-INF/struts-fndt-config.xml,/WEB-INF/struts-plugin-config.xml,/WEB-
INF/struts-app-config.xml</param-value>

</init-param>

Yes we can have more than one struts-config.xml files for a single struts
application in condition.1. If we have more than one module in our application.

<servlet>
<init-param>

<param-name> config </param-name>

<param-value> /WEB-INF/struts-config.xml </param-value>

</init-param>

<init-param>

<param-name> config/login </param-name>

<param-value> /WEB-INF/struts-config-login.xml</param-value>

</init-param>

<servlet>

where default and login our two module.2. If we want to use more than one
struts-config.xml files to make our application simple .

<init-param>

<param-name> config </param-name>


<param-value> /WEB-INF/struts-config.xml,/WEB-INF/struts-config-login.xml</param-value>

</init-param>

13) what is diff. between MVC1 and MVC2?

hi,from my reading knowledge,No MVC1 & MVC2. Its only model1 & model2.Model2 became
later to MVC pattern.so the diff between Model 1 & 2 is thatModel1 doesn't provide any
controller. so we are the only responsible to write entire flow of the control . Model 2 which
provide a controller for that to recieve a request and send a response in client/server model .

hi,from my reading knowledge,No MVC1 & MVC2. Its only model1 & model2.Model2 became
later to MVC pattern.so the diff between Model 1 & 2 is thatModel1 doesn't provide any
controller. so we are the only responsible to write entire flow of the control . Model 2 which
provide a controller for that to recieve a request and send a response in client/server model .

14) how can container will know this is a struts application?

in the web.xml you have to put the servlet entry(org.apache.struts.action.ActionServlet)


 which is nothing but action servlet. So each request will be handled by action servlet and
then it will be forwarded to assingned mapping. Mapping is all done in struts.xml. i think in
this very good site people should contribute by putting good question

i can explain it to the point when ever a request is invoked the container will invoke the excute
method of action servlet and checks for the web.xml for org.apache.struts.action.ActionServlet
and it mapped to sturts-config.xml file and there we r giving path which ends with( .do)and
with this it can recongise as an struts application.

15) what r the disadvantages of struts?

Few Disadvantage are mentioned in the below link. Struts have disadvantages mainly on performance of the
application. Especially when using advanced tag like nested-loop etc, Resulting in creating many Forms
object then required.

16)please anybody send the abbreviation of struts? this is the question i have faced
in the

A)interview?Struts means very tiny particles which we can't see virtually.

B)The particles which constitues bricks,walls,etc...all materials includes struts.This is all about struts name.
It doesn't have any special meaning.Actually "strut" means:To walk with a lofty proud gait, often in an
attempt to impress others."He struts around like a rooster in a hen house"

C)STRUTS is actually derived from the framework used in automobiles which is called as
struts.... i.e. it is the base of an automobile made with bars and rod on which all the other
thing resides.... like engine, etc.... Similarly for Struts is a framework for a web-application.I
hope this make it more clear.

D)Struts is an Apache project and if you can take a look at name of any of the apache projects
you would notice that they use Mechanical Engg related terms like Turbine, Velocity etc.Struts
is named in that same context and it doesnt have any abbreviation

16) What is struts flow? Explain in detail

What is struts flow? Explain in detail


Struts is based on MVC architecuture. Flow of struts is as follows if my understanding of question is correct

1. request comes.

2. corrosponding action class will be searched in the struts.xml

3. mapped form-bean will be populated with data.

4. execute method of mapped action servlet will be executed and result will be mapped in struts.xml with
<forward> tag.

5. mapped jsp/html page with forward will be displayed.

17) Hi How do i configure web.xml using with struts.

Sturts framework use 2 types of configuration files: web.xml & struts-cofig.xmlConfiguaring


web.xml for Struts is:2- steps are involved in this process1)Add .tld file in the web.xml. Eg: if
you are using html file add strtus-html.tld in /WEB-INF/struts-html.tld/WEB-INF/struts-
html.tld2) Configuring Action Servlet which wil recieve all incoming requests.Use Servet
element to configure the instance of servlet & later can be mapped in the servlet mapping
using some name the class name some name *.do

when ever start the web application the web container creates AcctionServlet object by using load-on-startup
method. then it gets the config init parameter. then read the config-xml file.

18) what is the difference between bean:write and bean:message

A)In Jakarta Struts - you may be knowing that - both are custom tags defined in HTML Tag library.

Both are used for accessing Java beans.

Bean:Message - is to access a java bean that will display a message such as " For more details on the
product displayed in this web site please contact a phone number 12345.."

Bean: write - is to display a data from the model; example "Number of People visited this site is: 1234"

Bean does not directly write. the Tag is used to take help of these Beans for the above mentioned purposes

B) hi in the jsp

<% @taglib uri="/tags/struts-bean" pefix="bean" %>

<ul> <bean:messages var="msg" property="propone">it will returns errors in the formbean tag

<li> <bean:wrtite id="var"/>it will returns data abt the formbean </li>

</bean:messages> </ul>

19) what is the difference between a normal servlet and action servlet?

Ordinary Servlets:
These are extends HttpServlet, and service the req, and send the response to the client. At the time,
servicing, the container will create the objects for this servlets, when ever, it needs

ActionServlet:

This also extends HttpServlet. But it wont create objects more than one, instead, it will service the request,
by using single object. This is called, SingletonPattern. So, ActionServlets are designed by singleton
pattern.

20) What are the drawbacks of Struts

In struts , their is no facility of backward flow.

Suppose we are in page 1 and when we submit it calls action mapping page2.Their may be lot of variable
stored in session , which is available to page2.Now we wish to go page1 from page 2, for this we have to
call the action mapping of page1. But struts flow is always in forward direction. So when we call page 1,
values stored in session never get reversed.So it reduces the performance.

To resolve this problem of struts, Their is a framework called Web Flow Nevigation Manager(WFNM) of
Sourgeforge.net.This framework can be integrated with struts.

21) How can we work struts on Eclipse? What is the best plugin for this?

Ecclipse work bench provides <add struts capabilities> option to any web project.building struts application
becomes very easy with the GUI provided and drag drop feature of struts-config file. The best plug-in
available is My-ecllipse .

the exadel studio is one of the plug-in for struts

22) What is the use of ActionForm class, Describe it's Life Cycle

ActionForm class is used to capture user-input data from an HTML form and transfer it to the
Action Class. ActionForm plays the role of Transport Vehicle between the presentation Tire &
Business Tier.

Life Cycle :
1. Request received by Controller
2. Create or recycle ActionForm
3. Call reset()
4. store ActionForm in proper scope
5. populate ActionForm from Request
6. Validate the ActionForm
7. If errors found then forward back to input attribute page(configured in Action mapping in
struts-config.xml) with ActionForm in scope. If no errors found then call execute() with the
ActionForm.

An ActionForm is a java bean that extends org.apache.struts.action.ActionForm, ActionForm maintain the


session state of web application.

All data submitted by the user are sent corresponding ActionForm

23) What is LookupDispatch Action ?


LookupDispatchAction is like DispatchAction but LookupDispatchAction uses the value of the
request parameter to perform a reverse lookup (using protected Map getKeyMethodMap() )
from the resource bundle using the parameter value and match it to a method in the class.
LookupDispatchAction is subclass of DispatchAction which actually lookup the action class method name
using the request parameter value in the reverse process by looking the value in the resource bundle.

24) In struts how can i validate the values filled into the text boxes or else using
DynaValidatorForm,without using javascript.
Actually with javascript it is working perfect but not without javascript, and i want without
javascript?

AnsHiStruts provide both client side and server side validation.for client side use for server
side the best approach is to use DynaValidatorForm, specify form name in validation.xml and
form property and its type and donot forget to make validate="true" in struts-config.xml at
appropriate action.Cheers!Pardeep Dureja

25) in struts why we use jsp as presentation layer? can we use servlet as
presentation layer?

no we can not use servlet as a presentation layer in struts even though jsp converted as
servlet at the back.bcos we can seperate presentation and business logic as part of jsp using
java beans.but in servlets we can not seperate presentation and business logics.

1. We can seperate the business logic from presentation logic

2.It facilitates to write the java code inside a html environment

if we use servlets then we need to write the html tags inside out.write() number of times. it is not possible in
all cases and it combines the businesslogic and presentation logic which reduces security

26) in struts what happens if made any changes in actionservlet?

The ActionServlet plays the role of controller wich is responsible for handling the request and selecting the
correct Application Module and storing ApplicationConfig and MessageResource bundle in the request
object.

If we modify the ActionServlet the Controller may or may not work what happens that depends on your
modification, You have not specify whether you want to create your own custom ActionServlet by extending
ActionServlet and overriding the methods in it or what exactly you want to modify

27) what is the request processor in struts? how it works?

IN addition to whatever said in comment one, in Jakarta Struts request processor has most of the following
responsibilities: 1. Determine path, 2. Handle Locale, 3. Process content and encoding type, 4.Process
cache headers 5. Pre Processing hook 6.Pre-processing hook, 7.Determine mapping, 8.Determine roles,
9.Process and validate actionForm, 10.Return a response

It is one instance per application module; it invokes proper Action instance

28) in struts why we use servlet as action controller?

Here u see, in servlets, we check (.do)url pattern in web.xml for each request(for each servlet) associated
with url whatever u mensioned in input jsp/html page. But in case of struts no need to worry about (.do) and
what type of request is coming,it can manage each request by seeing .do whatever it may be,

just observe in struts-config.xml, we can configure only for one servlet that is Action Servlet insted of
all, bcaz Action sevlet is singleton object that can be shared by all requests.
In Servlets,

each servlet - corresponding url pattern that recognize servet class

But in Struts,

one Action Servlet- here, no need to check url whatever it may be,it will check in the Struts-
config.Xml (<action path=Url that should be matched with url of the input JSP/html page)

29) what is the action mapping

An ActionMapping represents the information that the controller, RequestProcessor, knows


about the mapping of a particular request to an instance of a particular Action class. The
instance of ActionMapping is used to select a particular Action is passed on to that Action,
thereby providing access to any custom configuration information included with the
ActionMapping object

the action mapping object to give the proper action to that partcular request and takes care of validation
also.

30) What is the correct syntax for removing ActionMessages from the session context?
Choice 1
Action.removeErrors();
Choice 2
ActionMessages msg1 = new ActionMessages("clear");
Action.saveErrors(session, msg1);
Choice 3
Action.saveErrors(session, null);
Choice 4
Action.clearErrors(session, null);
Choice 5
request.getSession().saveErrors(session, null);
ans--Choice 3

31) Why is the action class is singleton in nature? Isn't this creates a bottleneck for
the requests?

We just have to make sure that we are not using any instance variable in execute method.

32) what is the diff between perform() and execute() method?

As per my understanding, both perform() and execute() is the same method with different
names. The prior version of struts supported "validate() and Perform()" for your action class
whereas the present versions supprots "validate() and Execute()" for validation and execution
of the code.

33) What is the diffrence between Apache struts and jakarta struts ?

Jakarta is a sub project of Apache. Struts used to be a Jakarta sub project. Struts is now a
Apache top level project. To answer the question Jakarta Struts and Apache Struts are the
same.

34) can we go one page to other page using java script or action Mapping ?
No, because we donot use both , because the struts does not support both togther otherwise
browser incomptable problem come arise

35) Is there any way to define a default method for every in the action mapping of
Struts-Config.XML file? If yes then how? Give a piece of code demonstrating the
same.

yes , give only the welcome jsp page.

36) What is ActionMapping ?

Action mapping is the important issue in struts , all the jsp pages are mapping(or)forwarding
through the actionmapping.

37) What is super class of Action and ActionForm?

Object is the super class for Action and ActionForm. Action is a class and ActionForm is an abstract class.

38) Explain Struts Framework flow? and How JSP file can be processed?

Struts frame work uses front controller design pattern for its centralized flow. First it matches
the incoming path(*.do) with appropriate action in actionMapping of struts-config.xml. From
this appropriate ActionForm is taken from fromBeans Tag and populates that frombean with
incoming data and validate method is called for any validations required.If no validation errors
are there then execute() method of Action class is called.Then the results are presented to the
View.

i) All requests are passed through a controller servlet, known as Action-servlet.

This is achieved by suitable 'url-mapping' in web.xml file.We have been doing 'URL-
pattern' in Tomcat4,when using servlets.

And in j2ee webserver like Tomcat, this facilitates 'centralized-declarative change


management', by editing the concerned XML files, without touching the source or class
files of the servlets.or Struts Actions...

ii) All data submitted by user are sent to corresponding ActionForm.There are many
actionforms but only one ActionServlet(because, it is the controller).

iii) The ActionServlet, examines the source of request and extracts the data from
specified actionform and sends it to a specified instance of Action class.(as specified in
struts-config.xml).

iv) The action object carries out the business logic either directly or through helper
classes , creates an instance of valuebean, populates this bean with data and sends the
bean to the View JSP.( an instance of ActionForward).

v) The important and distinctive feature of this arrangement is that the entire thing is
done by 'Declarative-Management'.(and hence ActionMapping)
vi) Sometimes, the data submitted has to be validated and error messages , generated.
(ActionErrors).

vii) We use tags in input side and also for output view.(The input form also belongs to
'view' category in MVC.)( Struts-tags)

The details about the ActionServlet and other servlets if any ,in our application are given
in web.xml

viii) ix) Details about various action classes,forms, action-forwards etc are given in
struts-config.xml

39) What is the difference between Apache struts and Jakarta Struts?? why there are
2 names??

40) Why we use static method in Business Logic?

Both apache struts and jakarta struts ar e one and the same.Struts was originally created by
Craig McClanahan and donated to the Apache Foundation in May, 2000.However after gaining
prominence in the J2EE community through its evolution as a Jakarta Project, in early 2004 it
become an official Apache Project.Thus there is no difference between them.

41) wats meant by struts?how to use struts in IBM websphere appli. ?


and how to managed with struts?(plz answer simply just an intro. don\'t go very
deep)

Struts is a framework developed so that applications are build in proper MVC (Model view
controller) architecture. The key player in struts is struts-config.xml. struts-config.xml is a
configuration file where you configure action classes, form beans and set global forwards.
Struts makes coding the web part of the application much simpler.

struts is a framework based on MVC (Model View Controller) architecture.action form works as model
,action class as controller and jsp as view.all infortion abt these classes r provided in struts-config.xml
file.using struts developing applications will be easy and we can use build in validations also.all validation we
provide in validation.xml file

42) What is difference between Design Pattern and FrameWork.

A Framework is a skeleton of code used for developing an application with ease.It could have used several
design patterns to implement the skeleton upon which we generally build applications.Eg. Struts Framework
uses MVC2 architecture, various design patterns like Front- Controller,Composite,Command patterns.

Such design patterns used in the framework also helps to build applications with simplicity eg.. struts-
config.xml makes ur app configurable ,resuable,fewer impacts on changes to functionality (Command
pattern)Can go thru Struts architecture for further details.

43) In which pattern does all the action classes in the struts are organized
In which pattern does all the action classes in the struts are organized
Answer: MODEL VIEW CONTROLLER DESIGN PATTERN

44) how can i pass info from dyna form bean to Entity Bean(CMP)

First you need to import Home Interface,Remote Interfaces into your bean,(.jar file should be placed in
WEB-INF/lib folder) and then,

you get access to the HomeOjbect using the InitialContext Object,and by passing dyna form values to
findByPrimaryKey() method you can forward info to ejb.

we can access dynaform bean information in action class after that calls ejb entity beans in
execute method .use that entity beans and pass the information of form beans in create or
findByprimarykey methods after use if u require.

45) how to build struts in java? what are the function of struts?

To build struts in Java, we need the struts taglib. They provide many of the inbuilt tags that
provide the many activities like loop,tiles(to beautify the page) etc. For this the struts.jar file
has to be in the classpath. Any jsp engine will then apply the struts.This is mainly the web
platform to develop the dynamic pages.

46) Can we use any other technology than JSP to construct a view ?

Yes, other than JSP we can use Swing, JSF, Cocoon etc as a front end for our struts
application. Here is a link to the article for using struts with swing as front end\

47) Does Struts provide support for Validator & Tiles by default ?

No, These features are turned off by default. One has to enable the plugins by properly
inserting entries in Struts-config.xml

Yes, Struts provide the support for Validator & Tiles framework.

in fact Now they are part of Struts.

48) Is there any way to put my custom name to LIB folder which i am going to place
in WEB-INF folder of struts application?

no,not possible beacause web servers are strictly denoting the directory structure and names
.so that it will recognise that lib is a directory having library files

49) How you will save the data across different pages for a particular client request
usingStruts

Several ways. The similar to the ways session tracking is enabled. Using cookies, URL-
rewriting, SSLSession, and possibilty threw in the database.

50) What is Struts?

STRUTS is a design pattern that follows the MVC framework. It provides a way to seperate the
appliation logic from the business logic
51)RE: Explain Struts navigation flow

Actual flow

The struts framework are most flaxible and example of loose coupling component

1-web.xml->actionservlet

2-Actionservlet class call the RequestProcesser class which deside the appropriate action for perticular
request.

3-struts-config 4-formbean & action class 5-perticular jsp

52) What is the difference between ActionForm and DynaActionForm

53) What part of MVC does Struts represent

Hey Guys,
Struts is mainly famous for its Action Controller - which is nothing but the CONTROLLER part of
MVC Pattern.
To add up, Struts is the framework which started mainly using the MVC-2 Pattern where in the
Business logic is STRICTLY SEPARATED from the Presentation logic (mainly in JSPs).

54) What are the Important Components of Struts?

1. Action Servlet 2. Action Classes 3. Action Form 4. Validator Framework

5. Message Resources 6. Struts Configuration XML Files 7. View components like JSP

Struts Configuration File, ActionServlet


RequestProcessor, ActionForm
Action
ActionFroward , ActionMapping
ActionErrors

55) What is DispatchAction

Dispatch Action allows you to specify a class with multiple methods, where one of the method
is invoked based on the value of a special request parameter specified in the configuration file.
DispatchAction uses the value of the request parameter to determin which method to invoke.
Your class should extend DispatchAction and should not contain execute()

56) What are the various Struts tag libraries

we have 13 type of tag-libs in struts.that will followed by down.

struts-bean.tld struts-html.tld struts-logic.tld struts-nested.tld struts-template.tld


c.tld , c-rt.tld , fmt.tld ,fmt-rt.tld ,sql.tld ,sql-rt.tld ,x.tld ,x-rt.tld
Following are the six Struts libraries:

• Bean Tags , HTML Tags ,Logic Tags ,Nested Tags ,Template Tags ,Tiles Tags

57) What is the purpose of tiles-def.xml file, resourcebundle.properties file,


validation.xml file

The Tiles Framework is an advanced version of that comes bundled with the Struts Webapp
framework. Its purpose is reduce the duplication between jsp pages as well as make layouts
flexible and easy to maintain. It integrates with Struts using the concept of named views or
definitions.

This validation.xml configuration file defines which validation routines that is used to validate
Form Beans. You can define validation logic for any number of Form Beans in this configuration
file. Inside that definition, you specify the validations you want to apply to the Form Bean's
fields. The definitions in this file use the logical names of Form Beans from the struts-
config.xml file along with the logical names of validation routines from the validator-rules.xml
file to tie the two together.

58) How you will handle errors and exceptions using Struts

To handle errors server side validation can be used using ActionErrors classes can be
used

to handle the errors:: in struts project to handle the error objet by using ActionError object and to handle the
errors by using ActionErrors object.

for suppose ActionError ae1=new ActionError("err.one");

ActionError ae2=new ActionError("err.two");

Action Errors aes=new ActionErrors();

aes.add(ae1); aes.add(ae2);

saveErrors(request,aes);//store the errors object in request object

to handle exception:

1)using try and cach blocks

2)using declarative exception handling technique

to handle the exceptions by using global exceptons tag in struts-config.xml

<global-exceptions>

<exception key="gen.err" type="java.lang.ClassNotFoundException" path="/gen.jsp"/>

whenever that exception will be came it executes the gen.jsp page.


59) What are the core classes of struts?

The core classes of struts are ActionForm, Action, ActionMapping, ActionForward etc.

60) Explain about token feature in Struts

Tokens are used to check for invalid path for by the uer:
1) if the user presses back button and submits the same page
2)or if the user refreshes the page which will result to the resubmit of the previous action and
might lead to unstabality..

to solve the abv probs we use tokens


1) in previous action type saveTokens(HttpServletreuest)
2) in current action check for duplication bu
if(!isValidToken())

Another important usage of tokens is to trap an event when the user hits the "Submit" button
twice. Tokens allows to prevent duplicate processing for such a request.

Struts has a token feature that puts a single-use token on a form to prevent duplicate
submits. Redirecting after post prevents duplicate submissions using the "back" button but will
not prevent a duplicate post if a user submits more than once in rapid succession.

Typically when a Struts action is going to forward to a page that will post information the
action will call Action.saveToken(HttpServletRequest). Struts will then automatically add the
token to the form when the <html:form> tag is rendered.

When the post occurs the action should perform an Action.isValidToken(HttpServletRequest,


true) to verify and invalidate the token. Any succeeding posts with the token will be cause
isValidToken() to return false.

61) What is the difference between ActionErrors and ActionMessages

in struts 1.0 to dispaly the errors, ActionError was used but struts1.1 that feature depricated by
ActionMessage tag.

The difference between the classes is zero -- all behavior in ActionErrors was pushed up into
ActionMessages and all behavior in ActionError was pushed up into ActionMessage. This was
done in the attempt to clearly signal that these classes can be used to pass any kind of
messages from the controller to the view -- errors being only one kind of message

The difference between the classes is zero -- all behavior in ActionErrors was pushed up into
ActionMessages and all behavior in ActionError was pushed up into ActionMessage. This was
done in the attempt to clearly signal that these classes can be used to pass any kind of
messages from the controller to the view -- errors being only one kind of message

62) What we will define in Struts-config.xml file. And explain their purpose

The main control file in the Struts framework is the struts-config.xml XML file, where action
mappings are specified. This file's structure is described by the struts-config DTD file, which is
defined at http://jakarta.apache.org/struts/. A copy of the DTD can be found on the
/docs/dtds subdirectory of the framework's installation root directory. The top-level element is
struts-config. Basically, it consists of the following elements:

data-sources—A set of data-source elements, describing parameters needed to instantiate


JDBC 2.0 Standard Extension DataSource objects
form-beans—A set of form-bean elements that describe the form beans that this application
uses

global-forwards—A set of forward elements describing general available forward URIs

action-mappings—A set of action elements describing a request-to-action mapping

You might also like