j2ee struts

29
J2EE & Struts 1) What is J2EE? J2EE means Java 2 Enterprise Edition. The functionality of J2EE is developing multitier web-based applications .The J2EE platform is consists of a set of services, application programming interfaces (APIs), and protocols. 2) What are the four components of J2EE application? Application clients components. Servlet and JSP technology are web components. Business components (JavaBeans). Resource adapter components 3) What are types of J2EE clients? Applets Application clients Java Web Start-enabled clients, by Java Web Start technology. Wireless clients, based on MIDP technology. 4) What are considered as a web component? Java Servlet and Java Server Pages technology components are web components. Servlets are Java programming language that dynamically receive requests and make responses. JSP pages execute as servlets but allow a more natural approach to creating static content. 5) What is JSF? JavaServer Faces (JSF) is a user interface (UI) designing framework for Java web applications. JSF provide a set of reusable UI components, standard for web applications.JSF is based on MVC design pattern. It automatically saves the form data to server and populates the form date when display at client side.

Upload: phanindra-atreyapurapu

Post on 07-Jul-2016

222 views

Category:

Documents


0 download

DESCRIPTION

java J2EE-struts interview questions

TRANSCRIPT

Page 1: J2EE Struts

J2EE & Struts

1) What is J2EE?

J2EE means Java 2 Enterprise Edition. The functionality of J2EE is developing multitier web-based applications .The J2EE platform is consists of a set of services, application programming interfaces (APIs), and protocols.

2) What are the four components of J2EE application?

Application clients components. Servlet and JSP technology are web components. Business components (JavaBeans). Resource adapter components

3) What are types of J2EE clients?

Applets Application clients Java Web Start-enabled clients, by Java Web Start technology. Wireless clients, based on MIDP technology.

4) What are considered as a web component? 

Java Servlet and Java Server Pages technology components are web components. Servlets are Java programming language that dynamically receive requests and make responses. JSP pages execute as servlets but allow a more natural approach to creating static content.

5) What is JSF?

JavaServer Faces (JSF) is a user interface (UI) designing framework for Java web applications. JSF provide a set of reusable UI components, standard for web applications.JSF is based on MVC design pattern. It automatically saves the form data to server and populates the form date when display at client side.

6) Define Hash table

HashTable is just like Hash Map,Collection having key(Unique),value pairs. Hashtable is a collection Synchronozed object .It does not allow duplicate values but it allows null values.

7) What is Hibernate?

Hibernate is a open source object-relational mapping and query service. In hibernate we can write HQL instead of SQL which save developers to spend more time on writing the native SQL. Hibernate has more powerful association, inheritance, polymorphism, composition, and

Page 2: J2EE Struts

collections. It is a beautiful approach for persisting into database using the java objects. Hibernate also allows you to express queries using java-based criteria .

8 ) What is the limitation of hibernate?

 Slower in executing the queries than queries are used directly. Only query language support for composite keys. No shared references to value types.

9) What are the advantage of hibernate.

 Hibernate is portable i mean database independent, Vendor independence.  Standard ORM also supports JPA  Mapping of Domain object to relational database.  Hibernate is better then plain JDBC.  JPA provider in JPA based applications.

10) What is ORM?

ORM stands for Object-Relational mapping. The objects in a Java class which is mapped in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.

11) Difference between save and saveorupdate

save() – This method in hibernate is used to stores an object into the database. It insert an entry if the record doesn’t exist, otherwise  not.

saveorupdate () -This method in the hibernate is used for updating the object using identifier. If the identifier is missing this method calls save(). If the identifier exists, it will call update method.

12) Difference between load and get method?

load() can’t find the object from cache or database, an exception is thrown and the load() method never returns null.

get() method returns null if the object can’t be found. The load() method may return a proxy instead of a real persistent instance get() never returns a proxy.

13) How to invoke stored procedure in hibernate?

{ ? = call thisISTheProcedure() }

Page 3: J2EE Struts

14) What are the benefits of ORM?

Productivity Maintainability Performance Vendor independence

15) What the Core interfaces are of hibernate framework?

 Session Interface SessionFactory Interface Configuration Interface Transaction Interface Query and Criteria Interface

16) What is the file extension used for hibernate mapping file?

The name of the file should be like this : filename.hbm.xml

17) What is the file name of hibernate configuration file?

The name of the file should be like this : hibernate.cfg.xml

18) How hibernate is database independent explain?

Only changing the property

123

<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property> and <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

 

full database can be replaced.

19) How to add hibernate mapping file in hibernate configuration file?

By <mapping resource=” filename.hbm.xml”/>

20) Define connection pooling?

Page 4: J2EE Struts

Connection pooling is a mechanism reuse the connection.which contains the number of already created object connection. So whenever there is a necessary for object, this mechanism is used to directly get objects without creating it.

21) What is the hibernate proxy?

An object proxy is just a way to avoid retrieving an object until you need it. Hibernate 2 does not proxy objects by default.

22) What do you create a SessionFactory?

1Configuration cfg = new Configuration(); cfg.addResource("dir/hibernate.hbm.xml"); cfg.setProperties( System.getProperties() ); SessionFactory sessions = cfg.buildSessionFactory();

 

23)  What is HQL?

HQL stands for Hibernate Query Language. Hibernate allows to the user to express queries in its own portable SQL extension and this is called as HQL. It also allows the user to express in native SQL.

24) What are the Collection types in Hibernate ?

Set, List, Array, Map, Bag

25) What is a thin client?

A thin client is a program interface to the application that does not have any operations like query of databases, execute complex business rules, or connect to legacy applications.

26) Differentiate between .ear,  .jar and .war files.

.jar files: These files are with the .jar extenstion. The .jar files contains the libraries, resources and accessories files like property files..war files: These files are with the .war extension. The .war file contains jsp, html, javascript and other files for necessary for the development of web applications..ear files: The .ear file contains the EJB modules of the application.

27) What are the JSP tag?

Configuration cfg = new Configuration(); cfg.addResource("dir/hibernate.hbm.xml"); cfg.setProperties( System.getProperties() ); SessionFactory sessions = cfg.buildSessionFactory();

Page 5: J2EE Struts

In JSP tags can be divided into 4 different types.

Directives Declarations Scriplets Expressions

28) How to access web.xml init parameters from jsp page?

For example, if you have:<context-param> <param-name>Id</param-name> <param-value>this is the value</param-value></context-param>You can access this parameterId: <h:outputText value=”#{initParam[‘Id’]}”/>

29) What are JSP Directives?

1.page Directives <%@page language=”java” %> 2. include Directives: <%@ include file=”/header.jsp” %> 3. taglib Directives <%@ taglib uri=”tlds/taglib.tld” prefix=”html” %>

30) What is the EAR file?

An EAR file is a JAR file with an .ear extension. A J2EE application with all of its modules is delivered in EAR file.

31) What will happen when you compile and run the following code?

1 public class MyClass { public static void main(String argv[]){ int array[]=new int[]{1,2,3}; System.out.println(array [1]); } } Answer: Compiled and shows output : 2

32) What is Struts?

Struts framework is a Model-View-Controller(MVC) architecture for designing large scale applications. Which is combines of Java Servlets, JSP, Custom tags, and message. Struts helps you to create an extensible development environment for your application, based on published standards and proven design patterns. Model in many applications represent the internal state of the system as a set of one or more JavaBeans.The View is most often constructed using JavaServer Pages (JSP) technology.The Controller is focused on receiving requests from the client and producing the next phase of the user interface to an appropriate View component. The

public class MyClass { public st

Page 6: J2EE Struts

primary component of the Controller in the framework is a servlet of class ActionServlet. This servlet is configured by defining a set of ActionMappings.

33.What is ActionErrors?

ActionErrors object that encapsulates any validation errors that have been found. If no errors are found, return null or an ActionErrors object with no recorded error messages.The default implementation attempts to forward to the HTTP version of this method. Holding request parameters  mapping and request  and returns set of validation errors, if validation failed; an empty set or null

34) What is ActionForm?

ActionForm is a Java bean that associates one or more ActionMappings. A java bean become FormBean when extend org.apache.struts.action.ActionForm class. ActionForm object is automatically populated on the server side which data has been entered by the client from UI. ActionForm maintains the session state for web application.

35) What is action mapping??

In action mapping we specify action class for particular url ie path and diffrent target view ie forwards on to which request response will be forwarded.The ActionMapping represents the information that the ActionServlet knows about the mapping of a particular request to an instance of a particular Action class.The mapping is passed to the execute() method of the Action class, enabling access to this information directly.

36) What is the MVC on struts.

MVC stands Model-View-Controller.

Model: Model in many applications represent the internal state of the system as a set of one or more JavaBeans.

View: The View is most often constructed using JavaServer Pages (JSP) technology.

Controller: The Controller is focused on receiving requests from the client and producing the next phase of the user interface to an appropriate View component. The primary component of the Controller in the framework is a servlet of class ActionServlet. This servlet is configured by defining a set of ActionMappings.

37) What are different modules in spring?

There are seven core modules in spring

The Core container module O/R mapping module (Object/Relational)

Page 7: J2EE Struts

DAO module Application context module Aspect Oriented Programming Web module MVC module

38) What is Bean Factory, have you used XMLBean factory?

1

XmlBeanFactory is one of the implementation of bean Factory org.springframework.beans.factory.xml.XmlBeanFactory is used to creat bean instance defined in our xml file. BeanFactory factory = new XmlBeanFactory(new FileInputStream("beans.xml")); Or ClassPathResource resorce = new ClassPathResource("beans.xml"); XmlBeanFactory factory = new XmlBeanFactory(resorce);

 

39) What is Spring?

Spring is a light weight open source framework  for the development of enterprise application that resolves the complexity of enterprise application development also providing a cohesive framework for J2EE application development. Which is primarily based on IOC (inversion of control) or DI (dependency injection) design pattern.

40) Functionality of ActionServlet and RequestProcessor?

Receiving the HttpServletRequest Populating JavaBean from the request parameters Displaying response on the web page Issues Content type issues handling Provide extension points

41) ActionServlet, RequestProcessor and Action classes are the components of

Controller

42) What is default scope in Spring?

Singleton.

43) What are advantages of Spring usage?

XmlBeanFactory is one of the im

Page 8: J2EE Struts

Pojo based programming enables reuse component. Improve productivity and subsequently reduce development cost. Dependency Injection can be used to improve testability. Spring required enterprise services without a need of expensive application server. It reduces coupling in code and improves maintainability.

44)What are the Benefits  Spring Framework ?

Light weight container Spring can effectively organize your middle tier objects Initialization of properties is easy ? no need to read from properties file application code is much easier to unit test Objects are created Lazily , Singleton – configuration Spring’s configuration management services can be used in any architectural layer, in

whatever runtime environment

45) Lifecycle interfaces in spring ?

1

1) InitializingBean <bean id="expInitBean" init-method="init"/> public class ExpBean { public void init() { // do some initialization code } } OR <bean id=" expInitBean "/> public class ExpBean implements InitializingBean { public void afterPropertiesSet() { // do some initialization code } } 2) DisposableBean <bean id="expInitBean" destroy-method="cleanup"/> public class ExpBean { public void cleanup() { // do some destruction code (like releasing pooled connections) } } OR <bean id="expInitBean"/> public class ExpBean implements DisposableBean { public void destroy() { // do some destruction code (like releasing pooled connections) } }

46) How to Create Object without using the keyword “new” in java?

Without new the Factory mehtods are used to create objects for a class. For exampleCalender c=Calender.getInstance();here Calender is a class and the method getInstance() is a Factory method which can create object for Calender class.

47) What is servlet?

Servlets is a server side components that provide a powerful mechanism for developing server side programs. Servlets is a server as well as platform-independent and Servlets are designed for a various protocols. Most commonly used HTTP protocols. Servlets uses the classes in the java packages javax.servlet, javax.servlet.http.HttpServletRequest,

1) InitializingBean <bean id="exp

Page 9: J2EE Struts

javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpSession;. All servlets must implement the Servlet interface, which defines life-cycle methods.

48) Servlet is pure java object or not?

Yes, pure java object.

49) What are the phases of the servlet life cycle?

The life cycle of a servlet consists of the following phases:

Servlet class loading Servlet instantiation  the init method Request handling (call the service method) Removal from service (call the destroy method)

50) What must be implemented by all Servlets?The Servlet Interface must be implemented by all servlets

Page 10: J2EE Struts

Q1. What are the components of Struts Framework?

Ans: Struts framework is comprised of following components:

1. Java Servlets2. JSP (Java Server Pages)3. Custom Tags4. Message Resources

Q2. What’s the role of a handler in MVC based applications?

Ans:. It’s the job of handlers to transfer the requests to appropriate models as they are bound to the model layer of MVC architecture. Handlers use mapping information from configuration files for request transfer.

Q3. What’s the flow of requests in Struts based applications?

Ans: Struts based applications use MVC design pattern. The flow of requests is as follows:

User interacts with View by clicking any link or by submitting any form. Upon user’s interaction, the request is passed towards the controller. Controller is responsible for passing the request to appropriate action. Action is responsible for calling a function in Model which has all business logic

implemented. Response from the model layer is received back by the action which then passes it

towards the view where user is able to see the response.

Q4.  Which file is used by controller to get mapping information for request routing?

Ans: Controller uses a configuration file “struts-config.xml file to get all mapping information to decide which action to use for routing of user’s request.

Q5.  What’s the role of Action Class in Struts?

Ans: In Struts, Action Class acts as a controller and performs following key tasks:

After receiving user request, it processes the user’s request. Uses appropriate model and pulls data from model (if required). Selects proper view to show the response to the user.

Page 11: J2EE Struts

Q6. How an actionForm bean is created?

Surrogate

Ans: actionForm bean is created by extending the class org.apache.struts.action.ActionForm

In the following example we have created an actionForm bean with the name 'testForm':

1234567891011121314151617

import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.*; public class testForm extends ActionForm { private String Id=null; private String State=null; public void setId(String id){this.Id=id; } public String getId(){return this.Id;}public void setState(String state){ this.State=state; } public String getState(){ return this.State; }

Q7. What are the two types of validations supported by Validator FrameWork?

Ans: Validator Framework is used for form data validation. This framework provides two types of validations:

1. Client Side validation on user’s browser2. Server side validation

Q8. What are the steps of Struts Installation?

Ans: In order to use Struts framework, we only need to add Struts.Jar file in our development environment. Once jar file is available in the CLASSPATH, we can use the framework and develop Strut based applications.

import javax.servlet.http.HttpSerimport org.apache.struts.action.public class testForm extends Aprivate String Id=null;

Page 12: J2EE Struts

Q9. How client side validation is enabled on a JSP form?

Ans: In order to enable client side validation in Struts, first we need to enable validator plug-in in struts-config.xml file. This is done by adding following configuration entries in this file:

123456

<!--  Validator plugin --><plug-in className="org.apache.struts.validator.ValidatorPlugIn"><set-propertyproperty="pathnames"value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/></plug-in>

 

Then Validation rules are defined in validation.xml file. If a form contains email field and we want to enable client side validation for this field, following code is added in validation.xml file:

123456

<form name="testForm"><field  property="email"depends="required"><arg key="testForm.email"/></field></form>

 

Q10. How action-mapping tag is used for request forwarding in Struts configuration file?

Ans: In Struts configuration file (struts-config.xml), forwarding options are defined under action-mapping tag.

In the following example, when a user will click on the hyperlink test.do, request will be forwarded to /pages/testing.jsp using following configurations from struts-config.xml file:

<!-- Validator plugin --><plug-in className="org.apach<set-propertyproperty="pathnames"

<form name="testForm"><field property="email"depends="required"><arg key="testForm.email"/>

Page 13: J2EE Struts

1 <action  path="/test" forward="/pages/testing.jsp">

 

This forwarding will take place when user will click on following hyperlink on the jsp page:

1 <html:link</strong> page="/test.do</strong>">Controller Example</html:link>

 

Q11. How duplicate form submission can be controlled in Struts?

Ans: In Struts, action class provides two important methods which can be used to avoid duplicate form submissions.

saveToken() method of action class generates a unique token and saves it in the user’s session. isTokenValid() method is used then used to check uniqueness of tokens.

Q12. In Struts, how can we access Java beans and their properties?

Ans: Bean Tag Library is a Struts library which can be used for accessing Java beans.

Q13. Which configuration file is used for storing JSP configuration information in Struts?

Ans: For JSP configuration details, Web.xml file is used.

Q14. What’s the purpose of Execute method of action class?

Ans: Execute method of action class is responsible for execution of business logic. If any processing is required on the user’s request, it’s performed in this method. This method returns actionForward object which routes the application to appropriate page.

In the following example, execute method will return an object of actionForward defined in struts-config.xml with the name “exampleAction”:

<action path="/test" forw ard="/

<html:link</strong> page="/test.d

Page 14: J2EE Struts

123456789101112131415161718

import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping; public class actionExample extends Action{public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{return mapping.findForward("exampleAction");}}

 

Q15. What’s the difference between validation.xml and validator-rules.xml files in Struts Validation framework?

Ans: In Validation.xml, we define validation rules for any specific Java bean while in validator-rules.xml file, standard and generic validation rules are defined.

Q16. How can we display all validation errors to user on JSP page?

Ans: To display all validation errors based on the validation rules defined in validation.xml file, we use <html:errors /> tag in our JSP file.

Q17. What’s declarative exception handling in Struts?

Ans: When logic for exception handling is defined in struts-config.xml or within the action tag, it’s known as declarative exception handling in Struts.

In the following example, we have defined exception in struts-config.xml file for NullPointerException:

import javax.servlet.http.HttpSerimport javax.servlet.http.HttpSer

import org.apache.struts.action.

Page 15: J2EE Struts

123456789

<global-exceptions> <exception key="test.key" Type="java.lang.NullPointerException" Path="/WEB-INF/errors/error_page.jsp" </global-exceptions>

 

Q18. What’s DynaActionForm?

Ans: DynaActionForm is a special type of actionForm class (sub-class of ActionForm Class) that’s used for dynamically creating form beans. It uses configuration files for form bean creation.

Q19. What configuration changes are required to use Tiles in Struts?

Ans: To create reusable components with Tiles framework, we need to add following plugin definition code in struts-config.xml file:

1234567

<plug-in className="org.apache.struts.tiles.TilesPlugin" > <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" /> <set-property property="moduleAware" value="true" /> </plug-in>

 

Q20. What’s the difference between Jakarta Struts and Apache Struts? Which one is better to use?

<global-exceptions>

<exception key="test.key"

<plug-in className="org.apach

<set-property property="definiti

Page 16: J2EE Struts

Ans: Both are same and there is no difference between them.

Q21. What’s the use of Struts.xml configuration file?

Ans: Struts.xml file is one the key configuration files of Struts framework which is used to define mapping between URL and action. When a user’s request is received by the controller, controller uses mapping information from this file to select appropriate action class.

Q22. How tag libraries are defined in Struts?

Ans: Tag libraries are defined in the configuration file (web.xml) inside <taglib> tag as follows:

1234567

<taglib> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib>

 

Q23. What’s the significance of logic tags in Struts?

Ans: Use of logic tags in Struts helps in writing a clean and efficient code at presentation layer without use of scriptlets.

Q24. What are the two scope types for formbeans?

Ans: 1. Request Scope: Formbean values are available in the current request only

<taglib>

<taglib-uri>/WEB-INF/struts-bea

Page 17: J2EE Struts

2. Session Scope: Formbean values are available for all requests in the current session.

Q25. How can we group related actions in one group in Struts?

Ans: To group multiple related actions in one group, we can use DispatcherAction class.

Q26. When should we use SwtichAction?

Ans: The best scenario to use SwitchAction class is when we have a modular application with multiple modules working separately. Using SwitchAction class we can switch from a resource in one module to another resource in some different module of the application.Q27. What are the benefits of Struts framework?

Ans: Struts is based on MVC and hence there is a good separation of different layers in Struts which makes Struts applications development and customization easy. Use of different configuration files makes Struts applications easily configurable. Also, Struts is open source and hence, cost effective.

Q28. What steps are required to for an application migration from Struts1 to Struts2?

Ans: Following Steps are required for Struts1 to Struts2 migration:

1. Move Struts1 actionForm to Struts2 POJO.2. Convert Struts1 configuration file (struts-config.xml) to Struts2 configuration file

(struts.xml)

Q29. How properties of a form are validated in Struts?

Ans: For validation of populated properties, validate() method of ActionForm class is used before handling the control of formbean to Action class.

Page 18: J2EE Struts

Q30. What’s the use of reset method of ActionForm class?

Ans: reset method of actionForm class is used to clear the values of a form before initiation of a new request.

Q31. What are disadvantages of Struts?

Ans: Although Struts have large number of advantages associated, it also requires bigger learning curve and also reduces transparency in the development process.

Struts also lack proper documentation and for many of its components, users are unable to get proper online resources for help.

Q32. What’s the use of resourcebundle.properties file in Struts Validation framework?

Ans: resourcebundle.properties file is used to define specific error messages in key value pairs for any possible errors that may occur in the code.

This approach helps to keep the code clean as developer doesn’t need to embed all error messages inside code.

Q33. Can I have html form property without associated getter and setter formbean methods?

Ans: For each html form property, getter and setter methods in the formbean must be defined otherwise application results in an error.

Q34. How many servlet controllers are used in a Struts Application?

Ans: Struts framework works on the concept of centralized control approach and the whole application is controlled by a single servlet controller. Hence, we require only one servlet controller in a servlet application.

Q35. For a single Struts application, can we have multiple struts-config.xml files?

Ans: We can have any number of Struts-config.xml files for a single application.

We need following configurations for this:

12

<servlet> 

<servlet>

<servlet-name>action</servlet-n

Page 19: J2EE Struts

345678910111213141516171819202122232425262728293031

<servlet-name>action</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-config_user.xml /WEB-INF/struts-config_admin.xml </param-value> </init-param> ............. ............. </servlet>

 

Q36. Which model components are supported by Struts?

Ans: Struts support all types of models including Java beans, EJB, CORBA. However, Struts doesn’t have any in-built support for any specific model and it’s the developer’s choice to opt for any model.

Q37. When it’s useful to use IncludeAction?

Ans: IncludeAction is action class provided by Struts which is useful when an integration is required between Struts and Servlet based application.

Q38. Is Struts thread safe?

Page 20: J2EE Struts

Ans: Yes Struts are thread safe. In Struts, a new servlet object is not required to handle each request; rather a new thread of action class object is used for each new request.

Q39. What configuration changes are required to use resource files in Struts?

Ans:  Resource files (.properties files) can be used in Struts by adding following configuration entry in struts-config.xml file:

<message-resources parameter=”com.login.struts.ApplicationResources”/>

Q40. How nested beans can be used in Struts applications?

Ans: Struts provide a separate tag library (Nested Tag Library) for this purpose. Using this library, we can nest the beans in any Struts based application.

Q41. What are the Core classes of Struts Framework?

Ans: Following are the core classes provided by Struts Framework:

Action Class ActionForm Class ActionMapping Class ActionForward Class ActionServlet Class

Q42. Can we handle exceptions in Struts programmatically?

Ans: Yes we can handle exceptions in Struts programmatically by using try, catch blocks in the code.

1234567891011

try { // Struts code } Catch (Exception e) { // exception handling code }

try {

// Struts code

Page 21: J2EE Struts

 

Q43. Is Struts Framework part of J2EE?

Ans: Although Struts framework is based on J2EE technologies like JSP, Java Beans, Servlets etc but it’s not a part of J2EE standards.

Q44.  How action mapping is configured in Struts?

Ans: Action mappings are configured in the configuration file struts-config.xml under the tag <action-mapping> as follows:

1234567891011

<pre><action-mappings><action path="/login"type="login.loginAction"name="loginForm"input="/login.jsp"scope="request"validate="true"><forward name="success" path="/index.jsp"/><forward name="failure" path="/login_error.jsp"/></action></action-mappings>

 

Q45. When should be opt for Struts Framework?

Ans: Struts should be used when any or some of the following conditions are true:

A highly robust enterprise level application development is required. A reusable, highly configurable application is required. A loosely coupled, MVC based application is required with clear segregation of different

layers.

Q46. Why ActionServlet is singleton in Struts?

Ans: In Struts framework, actionServlet acts as a controller and all the requests made by users are controlled by this controller. ActionServlet is based on singleton design patter as only one object needs to be created for this controller class. Multiple threads are created later for each user request.

<pre><action-mappings><action path="/login"type="login.loginAction"name="loginForm"

Page 22: J2EE Struts

Q47. What are the steps required for setting up validator framework in Struts?

Ans: Following Steps are required to setup validator framework in Struts: – Wrong Spelling

1. In WEB-INF directory place valdator-rules.xml and validation.xml files.2. Enable validation plugin in struts-config.xml files by adding following:

1234

<plug-in className="org.apache.struts.validator.ValidatorPlugIn"><set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/></plug-in>

 

Q48. Which technologies can be used at View Layer in Struts?

Ans: In Struts, we can use any of the following technologies in view layer:

JSP HTML XML/XSLT WML Files Velocity Templates Servlets

Q49. What are the conditions for actionForm to work correctly?

Ans: ActionForm must fulfill following conditions to work correctly:

It must have a no argument constructor. It should have public getter and setter methods for all its properties.

Q50.  Which library is provided by Struts for form elements like check boxes, text boxes etc?

Ans: Struts provide HTML Tags library which can be used for adding form elements like text fields, text boxes, radio buttons etc.

<plug-in className="org.apach<set-property property="pathna/WEB-INF/validation.xml"/></plug-in>