Professional Documents
Culture Documents
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.
Yes, you can have tow ActionServlet class per context but then you should must have two
different struts config files and their pattern
struts 1.2 added new features. the usage of template tags and nested 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.
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........
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
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.
12) Can I have more than one struts-config.xml file for a single Struts application?
<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>
</init-param>
<init-param>
<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>
</init-param>
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 .
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.
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
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
1. request comes.
4. execute method of mapped action servlet will be executed and result will be mapped in struts.xml with
<forward> tag.
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.
A)In Jakarta Struts - you may be knowing that - both are custom tags defined in HTML Tag library.
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
<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.
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 .
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.
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?
AnsHiStruts 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.
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
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
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
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,
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)
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.
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.
Action mapping is the important issue in struts , all the jsp pages are mapping(or)forwarding
through the actionmapping.
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.
This is achieved by suitable 'url-mapping' in web.xml file.We have been doing 'URL-
pattern' in Tomcat4,when using servlets.
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??
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.
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
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.
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.
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.
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).
5. Message Resources 6. Struts Configuration XML Files 7. View components like JSP
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()
• Bean Tags , HTML Tags ,Logic Tags ,Nested Tags ,Template Tags ,Tiles Tags
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.
aes.add(ae1); aes.add(ae2);
to handle exception:
<global-exceptions>
The core classes of struts are ActionForm, Action, ActionMapping, ActionForward etc.
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..
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.
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: