ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories >> Software >> Java-Related >> Java-J2EE >> Struts
 
 


 

Back to Questions Page
 
Question
Hai all.What is the use of <logic:iterate>tag in struts 
application.
Rank Answer Posted By  
 Question Submitted By :: Srinivas123vasu
This Interview Question Asked @   TCS
I also faced this Question!!   © ALL Interview .com
Answer
<logic:iterate> tag is used iterate over a collection in a
particular scope. The tag defines scope attribute which
defines the scope where to look for the collection. If not
defined following scopes are searched in order page,
request, session and application. This tag can also be used
to iterate over Maps and arrays.
 
0
Shirish
 
 
Question
Hai all.Can i develope Struts action class without execute(-,-
,-,-)method.Ifd it's possible plz provide some sample code.
Rank Answer Posted By  
 Question Submitted By :: Srinivas123vasu
This Interview Question Asked @   TCS
I also faced this Question!!   © ALL Interview .com
Answer
Yes , we have just use the Dispatch Action class for ignore the execute method.
 
0
Shashi
 
 
Answer
If your Action class extends from  Dyna Action Action, then 
you can develop struts action class with out execute 
method. Because in that action class we write our own 
methods insted of execute method.

EXAMPLE:
public class Dispatch_Action extends DispatchAction
{  

public ActionForward add(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{
    System.out.println("You are in add function.");
      return mapping.findForward("add");
  }

 public ActionForward delete(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception
 {
    System.out.println("You are in delete function.");
            return mapping.findForward("delete");
  }
 public ActionForward search(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{
    System.out.println("You are in search function");
    return mapping.findForward("search");
   }
  public ActionForward save(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{
    System.out.println("You are in save function");
    return mapping.findForward("save");
  
 }
}
 
0
Sreekanth Madamanchi
 
 
 
Answer
I want to add some points reply of Sreekanth Madamanchi.
1. DynaAction class should be used only when you are having
more then one action on you form.
2. JSP must have same action name as of method in the action
class
 
0
Naman Patidar
 
 
Question
What is the use of ActionErrors in Struts?
Rank Answer Posted By  
 Question Submitted By :: Surajkumar.java
This Interview Question Asked @   HCL
I also faced this Question!!   © ALL Interview .com
Answer
ActionErrors is a class(org.apache.struts.action.ActionErrors) 
which encapsulates the error messages being reported by the 
validate() method of an ActionForm. Validation errors are 
either global to the entire ActionForm bean or they are 
specific to a particular ActionForm  bean property. Each 
individual error is described by an "ActionError" object, 
which contains a message key which are mentioned in 
"Application.properties" file.
 
0
Surajkumar.java
 
 
Question
Hi Friends, am new to struts.I read that " you can store
variables in xml file(properties file) and for future
enhancements we just call properties file . Now i want to
implement this , where can i call properties file  to
enhance my application. My question is where this properties
file will be called.
Rank Answer Posted By  
 Question Submitted By :: Rajendra007
I also faced this Question!!   © ALL Interview .com
Answer
hi,
use properties file where ever u want it but my suggetion is
use that in service layer. by calling Properties class
methods. if u r testing this app in local means Tomcat place
this properties xml file in parallel to Source directory,
else ur deployed ur application in app servers  plz keep
this file in WEB-INF folder means parallel to web.xml.
i hope this ll give u some clarity. if any doubts reply to
me ll give u details.
 
0
M Gangadhar
 
 
Question
How display data base errors on web console by using the 
Struts Framework?
Rank Answer Posted By  
 Question Submitted By :: Ganesh_hyd
I also faced this Question!!   © ALL Interview .com
Answer
hi,
define a base class which handles all error related
operations. get Error code from E.getErrorCode() in Catch
block and then throw that error to action class.
Example.
Error code 00001: is defined for Unique constraint
voilation. for this 
catch{
  if(errorCode == 00001){
    throw new UniqueKeyException();
  } 
}
// this unique exception is userdefined exception in my
framework.

and catch this exception in your action class. and be
remember in your struts-config file action tag define
input="/ErrorPage.do" property. then only it redirects to
that page in what u defined in input tag action path.

if any thing regarding this one feel free to mail me.
Thanks a lot
 
0
M Gangadhar
 
 
Question
Main  reasons for using  servlet as a controller in struts.
why not jsp
Rank Answer Posted By  
 Question Submitted By :: Rajendra007
I also faced this Question!!   © ALL Interview .com
Answer
jsp means very less code in java.and also their is no tags 
for intigrate with other logic.i.e means controll with 
other logic just like as connection polling,data accessing 
object,persistance logic.suppose u take as jsp as 
controller programmer feels lot of complexity.Hence 
industry recomended struts as controller.in servlet easy 
intigrate with other logic.
Industry recomended as MVC rule servlets as controller,jsp 
as view layer.
 
0
Srinu
 
 
Answer
Controlling is a server side task and it makes no sense to
write you java code inside a jsp.
 
0
Naman Patidar
 
 
Question
Hi Friends,  why struts introduced in to web application.
Plz dont send any links . Need main reason for implementing
struts.  Thanks Prakash
Rank Answer Posted By  
 Question Submitted By :: Prakash
I also faced this Question!!   © ALL Interview .com
Answer
Before writing the answer i am assuming that u have idea 
about MVC Architecture.

When u r writing the programm using servlet and jsp,every 
time u have to write ur own Controoler which is responsible 
for handling the request and response.

 Writing the Controller is a very tedious task and u might 
suffer from so many ecceptions even errors....which is 
really very diffcult to handle.

So  manage to Controller Apache introduce the Struts.
Struts is also called controller........
In struts the Action servlet and Request Processor is 
responsible to handle the Request and Response.
HOW.............

The basic purpose of the Java Servlets in struts is to 
handle requests made by the client or by web browsers. In 
struts JavaServerPages (JSP) are used to design the dynamic 
web pages. In struts, servlets helps to route request which 
has been made by the web browsers to the appropriate 
ServerPage. The use of servlet as a router helps to make 
the web applications easier to design, create, and 
maintain. Struts is purely based on the Model- View- 
Contoller (MVC) design pattern. It is one of the best and 
most well developed design patterns in use. By using the 
MVC architecture we break the processing in three sections 
named Model, the View, and the Controller. Below we are 
describing the working of struts.

As we all are well aware of the fact that each application 
we develop has a deployment descriptor i.e. WEB-
INF/web.xml. This is the file which the container reads. 
This file has all the configuration information which we 
have defined for our web application. The configuration 
information includes the index file, the default welcome 
page, the mapping of our servlets including path and the 
extension name, any init parameters, information related to 
the context elements. 

In the file WEB-INF/web.xml of struts application we need 
to configure the Struts ActionServlet which handles all the 
request made by the web browsers to a given mapping.  
ActionServlet is the central component of the Struts 
controller. This servlet extends the HttpServlet. This 
servlet basically performs two important things. First is : 
When the container gets start, it reads the Struts 
Configuration files and loads it into memory in the init() 
method. You will know more about the Struts Configuration 
files below. Second point is: It intercepts the HTTP 
request in the doGet() and doPost() method and handles it 
appropriately.
   
In struts application we have another xml file which is a 
Struts configuration file named as struts.config.xml. The 
name of this file can be changed. The name of the struts 
configuration file can be configured in the web.xml file. 
This file is placed under the WEB-INF directory of the web 
application.  It is an XML document that describes all or 
part of Struts application. This file has all the 
information about many types of Struts resources and 
configures their interaction.  This file is used to 
associate paths with the controller components of your 
application., known as Action classes like <action path 
="/login" type = "LoginAction">.  This tag tells the Struts 
ActionServlet that whenever the incoming request is 
http://myhost/myapp/login.do, then it must invoke the 
controller component LoginAction. Above, you can see that 
we have written .do in the URL. This mapping is done to 
tell the web application that whenever a request is 
received with the .do extension then it should be appended 
to the URL.  
   
For each action we also have to configure Struts with the 
names of the resulting pages that will be shown as a result 
of that action. In our application there can be more than 
one view which depends on the result of an action. One can 
be for a success and the other for the failure. If the 
result action is "success" then the action tells the 
ActionServlet that the action has been successfully 
accomplished or vice- versa.  The struts knows how  to 
forward the specific page to the concerned destination. The 
model which we want to use is entirely to you, the model is 
called from within the controller components. 
   
Action can also get associate with a JavaBean in our Struts 
configuration file. Java bean is nothing but a class having 
getter and setter methods that can be used to communicate 
between the view and the controller layer. These java beans 
are validated by invoking the validate() method on the 
ActionForm by the help of the Struts system. The client 
sends the request by the normal form submission by using 
Get or Post method, and the Struts system updates that data 
in the Bean before calling the controller components.
   
The view we use in the struts can be either Jsp page, 
Velocity templates, XSLT pages etc. In struts there are set 
of JSP tags which has been bundled with the struts 
distribution, but it is not mandatory to use only Jsp tags, 
even plain HTML files can be used within our Struts 
application but the disadvantage of using the html is that 
it can't take the full advantage of all the dynamic 
features provided in the struts framework. 
The framework includes a set of custom tag libraries that 
facilitate in creating the user interfaces that can 
interact gracefully with ActionForm beans. The struts Jsp 
taglibs has a number of generic and struts specific tags 
tags which helps you to use dynamic data in your view. 
These tags helps us to interact with your controller 
without writing much java code inside your jsp. These tags 
are used create forms, internally forward to other pages by 
interacting with the bean and helps us to invoke other 
actions of the web application. 
There are many tags provided to you in the struts 
frameworks which helps you in sending error messages, 
internationalization etc. 
   
Note: The points we have described above will be in effect 
if and only if when the ActionServlet is handling the 
request. When the request is submitted to the container 
which call the ActionServlet, make sure that the extension 
of the file which we want to access should have the 
extension .do.


for futhere u may call me...

Thanks and Regards
Anjani Kumar Jha
09623154095
CDAC
 
0
Anjani Kumar Jha
 
 
Answer
there are two main reason one is expressive and other one 
is reusabilty
if u found any problem for that we don need to invent new 
solution for that just will have to pattern thats it and u 
can make very expressive ur applicaion by struts



Ramesh bajantri
 
0
Ramesh
 
 
Question
In ActionClass we can use only one action i.e execute(), but
in DispatchAction we can use multiple actions.My question is
 , we can use multiple actions in  Action class 
if(action.equals("add") if(action.equals("update"). Then
when to use Action and DispatchAction   which is  frequently
in webapplications.
Rank Answer Posted By  
 Question Submitted By :: Prakash
I also faced this Question!!   © ALL Interview .com
Answer
If multiple actions refer to the same formbean then we
should go for DispatchAction. Yes as you said it is possible
to write in Action. But by using dispatchAction we can
simply specify the parameter name in config file.

   No need to write the code in our appln
 
0
Sekhar Babu
 
 
Answer
DispatchAction is generally used when we need to group a set
of actions. E.g. addDepartment, editDepartment,
updateDepartment, deleteDepartment. The method to be called
is identified on the basis of a parameter which can be
configured in struts-config.com (action tag). The parameter
is usually passed from the JSP and is automatically mapped
to the action parameter (defined in action tag in
struts-config.xml). Also we need to add an attribute with
name same as the parameter name to the corresponding ActionForm
 
0
Shirish
 
 
Question
what is the purpose of load_on_startup entry in struts-
config.xml?
Rank Answer Posted By  
 Question Submitted By :: Chandranallam
This Interview Question Asked @   Satyam
I also faced this Question!!   © ALL Interview .com
Answer
If the struts configuration objects were to be created on 
the first call from the user it will adversely affect 
performance by delaying response for the first user.

By specifying load-on-startup = 1 we tell the servlet 
container to call the init() method immediately on start up 
of the servlet container.
 
0
Priyanka Bhattacharyya
 
 
Answer
If we use load on startup web container creates the objects 
based on the proirity when there are mutliple servlets.We 
use load on start up for giving the proirity.
 
5
Srinivasa
[Satyam Computer Services Limit]
 
 
Answer
If load_on_startup is not enabled in web.Xml then the
servlet crates the object that class and sevletConfig object
will be created after constructor will be executed after it
will go to life cycle methods in servlets.i.e means lot of
processing will be done when load-on-startup is not enabled.

If load_on_startup is enabled then that moment when
WEBAPPLICATION is deployed all lot of processing will be done.
Then immediately executes LIFECYCLE method in servlets  

Problem: suppose our webapplication contain 10 servlets then
which servlet object will be created?

solution: for this problem If we use load on startup web
container creates the objects based on the proirity when
there are mutliple servlets.We use load_ on_ start up for
giving the proirity.

Note:1 is highest priorty
     2 is next  highest priorty
    -1 ignores that value
EX:<load-on-startup>1</load-on-startup>
 
0
Srinu
[Satyam Computer Services Limit]
 
 
Answer
load_on_startup only shows the priority of the class loading
when u start ur web server in any web apps.

1----hightest prioritty
<load-on-startup>1</load-on-startup>
 
0
Anjani Kumar Jha
[Satyam Computer Services Limit]
 
 
Answer
If we are using any of the custom tags related to struts
like <html:form> etc, then it compulsory we need the tag of
<load-on-startup> in web.xml then only we will get the
output of corresponding jsp on to the browse or else we will
get the some errors like ActionMapping cannot resolve...
 
0
Sekhar Babu
[Satyam Computer Services Limit]
 
 
Answer
To create the servlet objects  when the web application is 
started.

In Case of Struts Action servlet object is created when the 
application is started on proirity basis.We can specify 
some integer value for this in such cases servlets will be 
created on priority basis . Low value servlet will be 
created fisrt...
 
0
Srinivasa
[Satyam Computer Services Limit]
 
 
Question
what are the struts tags?
Rank Answer Posted By  
 Question Submitted By :: Chandranallam
I also faced this Question!!   © ALL Interview .com
Answer
They are six type of tags in struts. 
1,Bean
2)HTML
3)Logic
4)Nested
5)Template
6)Tiles
 
0
Srinivas
 
 
Question
Hi All thanks in advance,
                       iam new to j2ee currently in my 
project we r using struts with hibernate can i have one 
sample application like CRUD application with code or any 
tutorials liks r ebooks plz....?
Rank Answer Posted By  
 Question Submitted By :: Komdu.mani@gmail.com
This Interview Question Asked @   IBM , IBM
I also faced this Question!!   © ALL Interview .com
Answer
You can find some examples in http://java2s.com
or in http://roseindia.net/
 
0
Sai Jithendra
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com