Advanced Java Interview Questions -27

Advanced Java Interview Questions -27

1.What are the types of resultsets?

The values are defined in the class java.sql.Connection and are:
TYPE_FORWARD_ONLY specifies that a resultset is not scrollable, that is, rows within it can be advanced only in the forward direction.
TYPE_SCROLL_INSENSITIVE specifies that a resultset is scrollable in either direction but is insensitive to changes committed by other transactions or other statements in the same transaction.
TYPE_SCROLL_SENSITIVE specifies that a resultset is scrollable in either direction and is affected by changes committed by other transactions or statements within the same transaction.

2.What is ActionServlet?

ActionServlet is a simple servlet which is the backbone of all Struts applications. It is the main Controller component that handles client requests and determines which Action will process each received request. It serves as an Action factory – creating specific Action classes based on user’s request.

3.What is role of ActionServlet?

ActionServlet performs the role of Controller:
Process user requests Determine what the user is trying to achieve according to the request Pull data from the model (if necessary) to be
given to the appropriate view,Select the proper view to respond to the userDelegates most of this grunt work to Action classes Is responsible
for initialization and clean-up of resources.

4.What is the ActionForm?

ActionForm is javabean which represents the form inputs containing the request parameters from the View referencing the Action bean.

5.What are the important methods of ActionForm?

The important methods of ActionForm are : validate() & reset().

6.Describe validate() and reset() methods ?

validate() : Used to validate properties after they have been populated; Called before FormBean is handed to Action. Returns a collection of ActionError as ActionErrors. Following is the method signature for the validate() method.
public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)
reset(): reset() method is called by Struts Framework with each request that uses the defined ActionForm. The purpose of this method is to reset all of the ActionForm's data members prior to the new request values being set.
public void reset() {}

7.What is ActionMapping?

Action mapping contains all the deployment information for a particular Action bean. This class is to determine where the results of the Action will be sent once its processing is complete.

8.How is the Action Mapping specified ?

We can specify the action mapping in the configuration file called struts-config.xml. Struts framework creates ActionMapping object from <ActionMapping> configuration element of struts-config.xml file

<action-mappings>
 <action path="/submit"
    type="submit.SubmitAction"
         name="submitForm"
         input="/submit.jsp"
         scope="request"
         validate="true">
  <forward name="success" path="/success.jsp"/>
  <forward name="failure" path="/error.jsp"/>
 </action>
</action-mappings>

9.What is role of Action Class?

An Action Class performs a role of an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request.

10.In which method of Action class the business logic is executed ?

In the execute() method of Action class the business logic is executed.
public ActionForward execute(
        ActionMapping mapping,
             ActionForm form,
             HttpServletRequest request,
             HttpServletResponse response)
          throws Exception ;

execute() method of Action class:
Perform the processing required to deal with this request
Update the server-side objects (Scope variables) that will be used to create the next page of the user interface
Return an appropriate ActionForward object

11.What are callable statements ?

Callable statements are used from JDBC application to invoke stored procedures and functions.

12.How to call a stored procedure from JDBC ?

PL/SQL stored procedures are called from within JDBC programs by means of the prepareCall() method of the Connection object created. A call to this method takes variable bind parameters as input parameters as well as output variables and creates an object instance of the CallableStatement class.

13.What is a framework?

A framework is made up of the set of classes which allow us to use a library in a best possible way for a specific requirement.

14.What is Struts framework?

Struts framework is an open-source framework for developing the web applications in Java EE, based on MVC-2 architecture. It uses and extends the Java Servlet API. Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.

15.What are the components of Struts?

Struts components can be categorize into Model, View and Controller:
Model: Components like business logic /business processes and data are the part of model.
View: HTML, JSP are the view components.
Controller: Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.

16.Which type of JDBC driver is the fastest one?

JDBC Net pure Java driver(Type IV) is the fastest driver because it converts the JDBC calls into vendor specific protocol calls and it directly interacts with the database.

17.Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?

No. You can open only one Statement object per connection when you are using the JDBC-ODBC Bridge.

18.What are the standard isolation levels defined by JDBC?

The values are defined in the class java.sql.Connection and are:
TRANSACTION_NONE
TRANSACTION_READ_COMMITTED
TRANSACTION_READ_UNCOMMITTED
TRANSACTION_REPEATABLE_READ
TRANSACTION_SERIALIZABLE
Any given database may not support all of these levels.

19.What are the core classes of the Struts Framework?

Struts is a set of cooperating classes, servlets, and JSP tags that make up a reusable MVC 2 design.JavaBeans components for managing application state and behavior.
Event-driven development.Pages that represent MVC-style views; pages reference view roots via the JSF component tree.

20.What is rowset?

A RowSet is an object that encapsulates a set of rows from either Java Database Connectivity (JDBC) result sets or tabular data sources like a file or spreadsheet. RowSets support component-based development models like JavaBeans, with a standard set of properties and an event notification mechanism.

21.What are the different types  of RowSet ?

There are two types of RowSet are there. They are:
Connected - A connected RowSet object connects to the database once and remains connected until the application terminates.
Disconnected - A disconnected RowSet object connects to the database, executes a query to retrieve the data from the database and then closes the connection. A program may change the data in a disconnected RowSet while it is disconnected. Modified data can be updated in the database after a disconnected RowSet reestablishes the connection with the database.

22.What is the need of BatchUpdates?

The BatchUpdates feature allows us to group SQL statements together and send to database server in one single trip.

23.What is a DataSource?

A DataSource object is the representation of a data source in the Java programming language. In basic terms,
A DataSource is a facility for storing data.
DataSource can be referenced by JNDI.
Data Source may point to RDBMS, file System , any DBMS etc..

24.What are the advantages of DataSource?

The few advantages of data source are :
An application does not need to hardcode driver information, as it does with the DriverManager.
The DataSource implementations can easily change the properties of data sources. For example: There is no need to modify the application code when making changes to the database details.
The DataSource facility allows developers to implement a DataSource class to take advantage of features like connection pooling and distributed transactions.

25.What is connection pooling? what is the main advantage of using connection pooling?

A connection pool is a mechanism to reuse connections created. Connection pooling can increase performance dramatically by reusing connections rather than creating a new physical connection each time a connection is requested..

26. How will we make any Of the Message Resources Definitions file available to the Struts Framework Environment?

Message Resources Definitions file are simple property files which consists of messages that can be used in the struts applications. Message Resources Definitions files can also be added to the struts-config.xml file using <message-resources /> tag.

E.g. <message-resources parameter=”Message Resources” />

27. What is Struts Validator Framework?

Struts Framework provides the functionality to validate the form data. This can be used to validate data on both the client side as well as server side. It emits the java scripts and can be used to validate data on the user’s browser and incase of server side validation, it is done by sub classing the From Bean with DynaValidatorForm class.

The Validator framework comes integrated with the Struts Framework and can be used without doing any extra change in settings.

28. Is struts thread safe?

Struts is thread safe as well as thread-dependant. Light-weight Action object handles the response to a request instead of individual servlets. The Action class is instantiated only once and lets the other requests to be threaded through the original object available. This technique helps to provide the best possible throughput and conserves resources. A properly-designed application will exploit this further by routing related operations through a single Action.

29. What is Struts Flow?

Struts Flow is a port of Cocoon’s Control Flow to Struts in order to allow complex workflow, like multi-form wizards, which is easily implemented using continuations-capable JavaScript. It provides the ability to describe the order of web pages that have to be sent to the client, at any given point of time in an application.

30. Why is ActionForm a base class rather than an interface?

Making ActionForm a class gives advantage of the single inheritance restriction of Java in order to make difficult for people to do things that they are not supposed to.
However, if ActionForm is implemented as interface encourages matching of property types to the underlying business tier, violating one of the important purpose of ActionForm and also encourages using of existing DAO objects which violates MVC design pattern.


31. What are the core classes of the Struts Framework?

The core classes of Struts framework are:
ActionServlet is the back bone of the whole web application.
ActionForm is a Java bean that associates one or more ActionMappings.
The business logic is wrapped by the Action class which provides an interface to the Model of the application.
ActionMapping is used to provide mappings for Objects to Actions.
ActionForward represent the destination for the controller.

32. What are the different kinds of actions in Struts?

The different kinds of actions in Struts are as follows:
a. ForwardAction.
b. IncludeAction.
c. DispatchAction.
d. LookupDispatchAction.
e. SwitchAction.

33.What is the jspInit() method?

The jspInit() method of the javax.servlet.jsp.JspPage interface is similar to the init() method of servlets. This method is invoked by the container only once when a JSP page is initialized. It can be overridden by a page author to initialize resources such as database and network connections, and to allow a JSP page to read persistent configuration data.

34. What are the various Struts tag libraries?

The various Struts tag libraries are:
a. Bean tag library – to access JavaBeans and their properties.
b. HTML tag library – to give standard HTML output, like forms, text boxes, etc.
c. Logic tag library – in order to generate conditional output, iteration capabilities and flow management.
d. Tiles or Template tag library – for those application using tiles.
e. Nested tag library – in order to use the nested beans in the application.

35. How the exceptions are handled in struts?

Exceptions in Struts are handled in two ways:

a. Programmatic exception handling: It is the explicit try/catch blocks in the code that can throw exception. It works well when any error occurs in the custom value
b. Declarative exception handling: In this we either define <global-exceptions> handling tags in the struts-config.xml or exception handling tags within <action></action> tag. It works well when error occurs in custom page and applies only to exceptions thrown by Actions.

36. What are the contents of web.xml and struts-config.xml? Explain the difference between them.

The web.xml file contains the information used by servlets and JSPs, having the description of the application, mapping information about servlets and URL, JSP configuration information, error page information without the exceptions.
The struts-config.xml file contains information about struts framework at the time of deploying the web application. It includes information about form bean, action mappings, controller information containing the buffer size, content type, etc.

37. What is SwitchAction & ForwardAction in struts?

A SwitchAction switches between modules and forwards the control to the URL specified in the new module. There are two parameters namely page, to which control is forwarded after switching and prefix that specifies the module to which the control is switched.
A ForwardAction is used to forward a request to the specified URL, represented as a destination to the controller to which it is sent after the action is completed.

38. What is Struts? 

Struts is an open source software that helps developers to easily build web application. It is a web page development framework which comprises of Java Servlets, Java Server Pages, custom tags, and message resources into a single framework. It is also a cooperative platform for development teams as well as independent developers.

39. Explain the components of Struts?

Struts is based on the MVC design pattern and its components can be categorized into:
Model: Components like business logic / business processes and data are parts of this.
View: It contains JSP, HTML etc.
Controller: Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.

40.What are JSP directives?

JSP directives are messages for the JSP engine. i.e., JSP directives serve as a message from a JSP page to the JSP container and control the processing of the entire page
They are used to set global values such as a class declaration, method implementation, output content type, etc.
They do not produce any output to the client.
Directives are always enclosed within <%@ ….. %> tag.
Ex: page directive, include directive, etc.

41.What are implicit objects in JSP?

Implicit objects in JSP are the Java objects that the JSP Container makes available to developers in each page. These objects need not be declared or instantiated by the JSP author. They are automatically instantiated by the container and are accessed using standard variables; hence, they are called implicit objects.The implicit objects available in JSP are as follows:
request
response
pageContext
session
application
out
config
page
exception
The implicit objects are parsed by the container and inserted into the generated servlet code. They are available only within the jspService method and not in any declaration.

42. What is Action Class?

The Action Class is a part of the Model. Its purpose is to translate the HttpServletRequest to the business logic and use the Action, we need to have a Subclass and overwrite the execute() method, In which all the database/ business processing are done. The ActionServlet (command) passes the parameterized class to Action Form using the execute() method and its return type is used by the Struts Framework to forward the request to the file according the value of the returned ActionForward object.

43.What is the _jspService() method?

SThe _jspService() method of the javax.servlet.jsp.HttpJspPage interface is invoked every time a new request comes to a JSP page. This method takes the HttpServletRequest and HttpServletResponse objects as its arguments. A page author cannot override this method, as its implementation is provided by the container.

44.What is the jspDestroy() method?

The jspDestroy() method of the javax.servlet.jsp.JspPage interface is invoked by the container when a JSP page is about to be destroyed. This method is similar to the destroy() method of servlets. It can be overridden by a page author to perform any cleanup operation such as closing a database connection.

45.What JSP lifecycle methods can I override?

You cannot override the _jspService() method within a JSP page. You can however, override the jspInit() and jspDestroy() methods within a JSP page. jspInit() can be useful for allocating resources like database connections, network connections, and so forth for the JSP page. It is good programming practice to free any allocated resources within jspDestroy().

46.How can I override the jspInit() and jspDestroy() methods within a JSP page?

The jspInit() and jspDestroy() methods are each executed just once during the lifecycle of a JSP page and are typically declared as JSP declarations:

47.What are the advantages of JSP over Servlet?

JSP is a serverside technology to make content generation a simple appear.The advantage of JSP is that they are document-centric. Servlets, on the other hand, look and act like programs. A Java Server Page can contain Java program fragments that instantiate and execute Java classes, but these occur inside an HTML template file and are primarily used to generate dynamic content. Some of the JSP functionality can be achieved on the client, using JavaScript. The power of JSP is that it is server-based and provides a framework for Web application development.

48.What is the life-cycle of JSP?

When a request is mapped to a JSP page for the first time, it translates the JSP page into a servlet class and compiles the class. It is this servlet that services the client requests.
A JSP page has seven phases in its lifecycle, as listed below in the sequence of occurrence:
Translation
Compilation
Loading the class
Instantiating the class
jspInit() invocation
_jspService() invocation
jspDestroy() invocation

49.What is page directive?

A page directive is to inform the JSP engine about the headers or facilities that page should get from the environment.
Typically, the page directive is found at the top of almost all of our JSP pages.
There can be any number of page directives within a JSP page (although the attribute – value pair must be unique).
The syntax of the include directive is: <%@ page attribute="value">
Example:<%@ include file="header.jsp" %>

50.What are the attributes of page directive?

There are thirteen attributes defined for a page directive of which the important attributes are as follows:
import: It specifies the packages that are to be imported.
session: It specifies whether a session data is available to the JSP page.
contentType: It allows a user to set the content-type for a page.
isELIgnored: It specifies whether the EL expressions are ignored when a JSP is translated to a servlet.

51.What is the include directive?

There are thirteen attributes defined for a page directive of which the important attributes are as follows:
The include directive is used to statically insert the contents of a resource into the current JSP.
This enables a user to reuse the code without duplicating it, and includes the contents of the specified file at the translation time.
The syntax of the include directive is as follows:
<%@ include file = "FileName" %>
This directive has only one attribute called file that specifies the name of the file to be included.

52.What are the JSP standard actions?

The JSP standard actions affect the overall runtime behavior of a JSP page and also the response sent back to the client.
They can be used to include a file at the request time, to find or instantiate a JavaBean, to forward a request to a new page, to generate a browser-specific code, etc.
Ex: include, forward, useBean,etc. object

53.What are the standard actions available in JSP?

The standard actions available in JSP are as follows:
<jsp:include>: It includes a response from a servlet or a JSP page into the current page. It differs from an include directive in that it includes a resource at request processing time, whereas the include directive includes a resource at translation time.
<jsp:forward>: It forwards a response from a servlet or a JSP page to another page.
<jsp:useBean>: It makes a JavaBean available to a page and instantiates the bean.
<jsp:setProperty>: It sets the properties for a JavaBean.
<jsp:getProperty>: It gets the value of a property from a JavaBean component and adds it to the response.
<jsp:param>: It is used in conjunction with <jsp:forward>;, <jsp:, or plugin>; to add a parameter to a request. These parameters are provided using the name-value pairs.
<jsp:plugin>: It is used to include a Java applet or a JavaBean in the current JSP page.

54.What is the <jsp:useBean> standard action?

The <jsp:useBean> standard action is used to locate an existing JavaBean or to create a JavaBean if it does not exist. It has attributes to identify the object instance, to specify the lifetime of the bean, and to specify the fully qualified classpath and type.

55.What are the scopes available in <jsp:useBean>?

The scopes available in <jsp:useBean> are as follows:
page scope:: It specifies that the object will be available for the entire JSP page but not outside the page.
request scope: It specifies that the object will be associated with a particular request and exist as long as the request exists.
application scope: It specifies that the object will be available throughout the entire Web application but not outside the application.
session scope: It specifies that the object will be available throughout the session with a particular client.

56.What is the <jsp:forward> standard action?

The <jsp:forward> standard action forwards a response from a servlet or a JSP page to another page.
The execution of the current page is stopped and control is transferred to the forwarded page.
The syntax of the <jsp:forward> standard action is : 
<jsp:forward page="/targetPage" />
Here, targetPage can be a JSP page, an HTML page, or a servlet within the same context.
If anything is written to the output stream that is not buffered before <jsp:forward>, an IllegalStateException will be thrown.

57.What is the <jsp:include> standard action?

The <jsp:include> standard action enables the current JSP page to include a static or a dynamic resource at runtime. In contrast to the include directive, the include action is used for resources that change frequently. The resource to be included must be in the same context.The syntax of the <jsp:include> standard action is as follows:
<jsp:include page="targetPage" flush="true"/>
Here, targetPage is the page to be included in the current JSP.

58.Why it called Struts?

Because the designers want to remind us of the invisible underpinnings that hold up our houses, buildings, bridges, and ourselves when we are on stilts. This excellent description of Struts reflect the role the Struts plays in developing web applications.

59.Do we need to pay the Struts if being used in commercial purpose?
No. Struts is available for commercial use at no charge under the Apache Software License. You can also integrate the Struts components into your own framework just as if they were written in house without any red tape, fees, or other hassles.

60.What are the core classes of Struts?

Action, ActionForm, ActionServlet, ActionMapping, ActionForward are basic classes of Structs.
What is the design role played by Struts?
The role played by Structs is controller in Model/View/Controller(MVC) style. The View is played by JSP and Model is played by JDBC or generic data source classes. The Struts controller is a set of programmable components that allow developers to define exactly how the application interacts with the user.

61.How Struts control data flow?

Struts implements the MVC/Layers pattern through the use of ActionForwards and ActionMappings to keep control-flow decisions out of presentation layer.

62.What configuration files are used in Struts?

ApplicationResources.properties
struts-config.xml
These two files are used to bridge the gap between the Controller and the Model.
What helpers in the form of JSP pages are provided in Struts framework?
–struts-html.tld
–struts-bean.tld
–struts-logic.tld

63.Is Struts efficient?

The Struts is not only thread-safe but thread-dependent(instantiates each Action once and allows other requests to be threaded through the original object.
ActionForm beans minimize subclass code and shorten subclass hierarchies
The Struts tag libraries provide general-purpose functionality
The Struts components are reusable by the application
The Struts localization strategies reduce the need for redundant JSPs
The Struts is designed with an open architecture–subclass available
The Struts is lightweight (5 core packages, 5 tag libraries)
The Struts is open source and well documented (code to be examined easily)
The Struts is model neutral

64.How you will enable front-end validation based on the xml in validation.xml?

The < html:javascript > tag to allow front-end validation based on the xml in validation.xml. For example the code: < html:javascript formName=logonForm dynamicJavascript=true staticJavascript=true / > generates the client side java script for the form logonForm as defined in the validation.xml file. The < html:javascript > when added in the jsp file generates the client site validation script.
What is ActionServlet?
The class org.apache.struts.action.ActionServlet is the called the ActionServlet. In the the Jakarta Struts Framework this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.
How you will make available any Message Resources Definitions file to the Struts Framework Environment?
Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources Definitions files can be added to the struts-config.xml file through < message-resources / > tag. Example: < message-resources parameter= MessageResources / >

65.What is Action Class?

The Action Class is part of the Model and is a wrapper around the business logic. The purpose of Action Class is to translate the HttpServletRequest to the business logic. To use the Action, we need to Subclass and overwrite the execute() method. In the Action Class all the database/business processing are done. It is advisable to perform all the database related stuffs in the Action Class. The ActionServlet (commad) passes the parameterized class to Action Form using the execute() method. The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object.

66.Write code of any Action Class?

Here is the code of Action Class that returns the ActionForward object.
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 TestAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
return mapping.findForward(\”testAction\”);
}
}

67.What is ActionForm?

An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from a form on the client side.
What is Struts Validator Framework?
Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class. The Validator framework was developed by David Winterfeldt as third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.
Give the Details of XML files used in Validator Framework?
The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean. How you will display validation fail errors on jsp page? – The following tag displays all the errors: < html:errors/ >

68.Why do we need Struts?

Java technologies give developers a serious boost when creating and maintaining applications to meet the demands of today’s public Web sites and enterprise intranets. Struts combines Java Servlets, Java ServerPages, custom tags, and message resources into a unified framework. The end result is a cooperative, synergistic platform, suitable for development teams, independent developers, and everyone in between.

69.How does Struts work?

Java Servlets are designed to handle requests made by Web browsers. Java ServerPages are designed to create dynamic Web pages that can turn billboard sites into live applications. Struts uses a special Servlet as a switchboard to route requests from Web browsers to the appropriate ServerPage. This makes Web applications much easier to design, create, and maintain.

70.Is Struts compatible with other Java technologies?

Yes. Struts is committed to supporting industry standards. Struts acts as an integrator of Java technologies so that they can be used in the “real world”.

71.Who wrote Struts?

There are several active committers to the Struts project, working cooperatively from around the globe. Dozens of individual developers and committers contributed to the Struts 1.x codebase. All interested Java developers are invited to contribute to the project. Struts is a Apache Software Foundation project, with the mission to “provide secure, enterprise-grade server solutions based on the Java Platform that are developed in an open and cooperative fashion”.
Struts was created by Craig R. McClanahan and donated to The Apache Software Foundation in May 2000. Craig was the primary developer of both Struts 1.x and Tomcat 4. Tomcat 4 was the basis for the official reference implementation for a servlet 2.3 and JSP 1.2 container.
Craig’s current focus is as architect of the Sun Java Studio Creator (formerly Project Rave). Craig also serves as the Specification Lead for JavaServer Faces (JSR-127), and is the Web Layer Architect for the Java2 Enterprise Edition (J2EE) platform as a whole

72.What is the term action mapping?

Struts provides a number of tag libraries that helps to create view components easily.
These tag libraries are:
a) Bean Tags: Bean Tags are used to access the beans and their properties.
b) HTML Tags: HTML Tags provides tags for creating the view components like forms, buttons, etc..
c) Logic Tags: Logic Tags provides presentation logics that eliminate the need for script lets.
d) Nested Tags: Nested Tags helps to work with the nested context

73.Can I setup Apache Struts to use multiple configuration files?

Yes Struts can use multiple configuration files. Here is the configuration example:
banking
org.apache.struts.action.ActionServlet
config /WEB-INF/struts-config.xml,
/WEB-INF/struts-authentication.xml,
/WEB-INF/struts-help.xml

74.What is LookupDispatchAction?

An abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping.

75..What is the <jsp:param> standard action?

The <jsp:param> standard action is used with <jsp:include> or <jsp:forward> to pass parameter names and values to the target resource. The syntax of the <jsp:param> standard action is as follows:
<jsp:param name="paramName" value="paramValue"/>

76..What is the jsp:plugin action ?

This action lets you insert the browser-specific OBJECT or EMBED element needed to specify that the browser run an applet using the Java plugin.

77.What are scripting elements?

JSP scripting elements let you insert Java code into the servlet that will be generated from the current JSP page. There are three forms:
Expressions of the form <%= expression %> that are evaluated and inserted into the output,
Scriptlets of the form <% code %> that are inserted into the servlet's service method,
Declarations of the form <%! code %> that are inserted into the body of the servlet class, outside of any existing methods.

78.What is a scriptlet?

A scriptlet contains Java code that is executed every time a JSP is invoked. When a JSP is translated to a servlet, the scriptlet code goes into the service() method. Hence, methods and variables written in scriptlets are local to the service() method. A scriptlet is written between the <% and %> tags and is executed by the container at request processing time.

79.What are JSP declarations?

As the name implies, JSP declarations are used to declare class variables and methods in a JSP page. They are initialized when the class is initialized. Anything defined in a declaration is available for the whole JSP page. A declaration block is enclosed between the <%! and %> tags. A declaration is not included in the service() method when a JSP is translated to a servlet.

80.What is a JSP expression?

A JSP expression is used to write an output without using the out.print statement. It can be said as a shorthand representation for scriptlets. An expression is written between the <%= and %> tags. It is not required to end the expression with a semicolon, as it implicitly adds a semicolon to all the expressions within the expression tags.

81.How is scripting disabled?

Scripting is disabled by setting the scripting-invalid element of the deployment descriptor to true. It is a subelement of jsp-property-group. Its valid values are true and false. The syntax for disabling scripting is as follows:
<jsp-property-group>
   <url-pattern>*.jsp</url-pattern>
   <scripting-invalid>true</scripting-invalid>
</jsp-property-group>

82. What is ActionServlet?

The class org.apache.struts.action.ActionServlet is the called the ActionServlet. In the the Jakarta Struts Framework this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.
 
83.How you will make available any Message Resources Definitions file to the Struts Framework Environment?

Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources Definitions files can be added to the struts-config.xml file through <message-resources /> tag.
Example:
<message-resources parameter="MessageResources" />

84.What is Action Class?

the Action is part of the controller. The purpose of Action Class is to translate the HttpServletRequest to the business logic. To use the Action, we need to  Subclass and overwrite the execute()  method. The ActionServlet (commad) passes the parameterized class to Action Form using the execute() method. There should be no database interactions in the action. The action should receive the request, call business objects (which then handle database, or interface with J2EE, etc) and then determine where to go next. Even better, the business objects could be handed to the action at runtime (IoC style) thus removing any dependencies on the model.   The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object.

85.What is ActionForm?

An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from a form on the client side.
 
86.What is Struts Validator Framework?

Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class.

The Validator framework was developed by David Winterfeldt as third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.

87.Give the Details of XML files used in Validator Framework?

The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean.

88.How you will enable front-end validation based on the xml in validation.xml?

The <html:javascript> tag to allow front-end validation based on the xml in validation.xml. For  example the code: <html:javascript formName="logonForm" dynamicJavascript="true" staticJavascript="true" /> generates the client side java script for the form "logonForm" as defined in the validation.xml file. The <html:javascript> when added in the jsp file generates the client site validation script.

89. What are the loop holes of Struts?

The drawbacks of Struts are following:
Absence of backward flow mechanism.
Only one single controller Servlets is used.
Bigger learning curve
Worst documentation
No exception present in this framework
Less transparent
Rigid approach.
With struts 1, embedding application into JSP can’t be prevented.
Non-XML compliance of JSP syntax

90.Difference between Html tags and Struts specific HTML Tags

Difference between HTML tag and Struts specific HTLM tags are:
HTML tags are static in nature but Struts specific HTML tags are dynamic in nature.
HTML tags are not User Defined whereas Struts tags can be user defined.
HTML tags provide the different templates and themes to the programmer whereas Struts specific HTML tag provides the integrating the property value with the Formbean properties.
HTML tags are integral part of Struts whereas Struts have HTML tag libraries.
Q24. What is the difference between session scope and request scope when saving FormBean?
The difference between session scope and request scope when saving FormBean are following:
In Request Scope, values of FormBean are available to current request but in Session Scope, values of FormBean are available throughout the session.

91. How to display validation errors on JSP page?

Validation error: Validation error are those error which arises when user or client enters the invalid format data into the form. For this validation of data struts enables the programmer with the Validator() method which validates both the data from client side and the server side.
We can display all error in the JSP page by using the following syntax in the code.
SYNTAX: <html:error/>

92. How to use forward action to restrict a strut application to MVC?

We can use the ForwarAction to restrict the Struts application to Model View Controller by following coding:
<global-forwards>
<statements>
<forward name="CitizenDetailsPage"
path="/gotoCitizenDetails.do" />
</global-forwards>
<action-mappings>
<statements>
<action path=”/gotoCitizenDetails”
parameter=”/CitizenDetails.jsp”
type=”org.apache.struts.actions.ForwardAction” />
</action-mappings>

93. What is ActionMapping?

In action mapping is the mapping of the action performed by the user or client on the application.

-We specify the action class for a specific user’s action. Like we provide the path or URL and different view based on user event.
-We can also define where control of the page deviate in case of validation error in the form.
-We can include ActionMapping in code like this:
<action-mappings>
<action path="/a" type=myclasse.A name="myForm">
<forward name="Login" path="/login.jsp"/>
<forward name="error" path="/error.jsp"/>
</action-mappings>

94. What is role of Action Class?

An Action class in the struts application is used to handle the request.
It acts as interface or communication medium between the HTTP request coming to it and business logic used to develop the application.
Action class consists of RequestProcessor which act as controller. This controller will choose the best action for each incoming request, generate the instance of that action and execute that action.
This should be in thread-safe manner, because RequestProcessor uses the same instance for no. of requests at same time.

95. In how many ways duplicate form submission can occurs?

The submission form can be duplicated by the any of the following ways:
Using refresh button.
By clicking submit button more than once before the server sent back the response.
By clicking back navigation button present in browser.
The browser is restores to submit the form again.
By clicking multiple times on a transaction that is delayed than usual.

96. What is the difference between Struts 1 and struts2?

The difference between struts1 and struts2 are below:
Struts1 uses ActionServlet as Controller where as Struts2 uses Filter as a controller.
Struts1 uses the ActionForm for mapping the JSP forms but in struts2 there no such ActionForm.
Struts1 uses Validation() method to validate the data in the page forms where as struts 2 validation of data is ensure by Validator Framework.
In Struts 1 the bean and logic tag libraries are often replaced by JSTL, but Struts 2 has such tag libraries that we don’t need to use JSTL.

97.How to combine the Struts with Velocity Template?
We can combine Struts and Velocity template by performing following steps:
1. Set classpath to Velocity JARs
2. Make web.xml file to identify the Velocity servlet.
3. Select Velocity toolbox.xml in WEB-INF directory.
4. Modify struts-config to point its views to Velocity templates instead of JSPs.
5. Create a Velocity template for each page you want to render.

98. What are the steps used to setup dispatch action?

To setup the dispatch action the following steps are used:
Create a subclass for DispatchAction.
Create method for logical action and their related actions.
Request Parameter is created for each action.
Define ActionMapping.
The JSP takes on the subclass defined for dispatch action method names as their values

99. What is difference between Interceptors and Filters?

The difference between Interceptors and filter are below:
Filters are based on Servlet Specification whereas Interceptors are based on Struts2.
Filters are executed only when patter matches whereas Interceptors executes for all request qualifies for a front controller.
Filters are not Configurable method calls whereas Interceptors methods can be configured.

100. What are the Custom tags?

Custom Tags are User Defined Tags, which means that user can create those tags depending upon their need in the application.

When a JSP page consisting of user- defined or custom tag is translated into a Servlet, the custom is also get translated into operation
Help in fast development of the application due to custom tag reusability.

101. What is the difference between empty default namespace and root namespace?

The difference between the empty default namespace and root name space are:
When namespace attribute is not defined then it is referred to as Empty Default Namespace whereas when name space attribute is assign with forward slash(/) then it is referred to as Root Name Space.
The root namespace must be matched.

102. What is the difference between RequestAware and ServletRequestAware interface?

The difference between RequestAware and ServletRequestAware are:
RequestAware enables programmer with the attributes in the Servlet Request as a map whereas ServletRequestAware enables programmer with HttpServletRequest object.
ServletRequestAware are more flexible than RequestAware.
ServletRequestAware makes action class highly coupled with Servlet environment which is not possible in RequestAware.

103. What are inner class and anonymous class?

Inner class: classes that are defined within other classes.
The nesting is a relationship performed between two different classes.
An inner class can access private members and data.
Inner classes have clearly two benefits:
1.Name control
2.Access control.
Anonymous class: Anonymous class is a class defined inside a method without a name.
It is instantiated and declared in the same method.
It does not have explicit constructors.

104. What is struts.devMode?

The struts.devMode is used to make sure that framework is running in development mode or production mode by setting true or false. struts.devMode is set to false in production phase to reduce impact of performance. By default it is "false". It is used because of the following reasons:
Resource Reloading: Resource bundle reload on every request
Modification: struts.xml can be modified without restarting or redeploying the application
Error Handling: The error occurs in the application will be reported, as oppose to production mode.

105. What are action errors?

Action error: when user or client submits the incorrect or invalid data in the application, then these errors are known as Action error.
Action errors are generated by the clients.
Action error should be determined as soon as possible.
The impacts of such Action Error are:
Wastage of server time and resources.
Negative impact on code quality.



-------------------------------------
Also Read:





































 

0 comments:

Post a Comment