Question: What are Access
Specifiers available in Java?
Answer: Access specifiers are keywords that determines the type of access to the member of a class. These are:
Answer: Wrapper class is wrapper around a primitive data type. An instance of a wrapper class contains, or wraps, a primitive value of the corresponding type.
Following table lists the primitive types and the corresponding wrapper classes:
Question: Read the following program:
public class test {
public static void main(String [] args) {
int x = 3;
int y = 1;
if (x = y)
System.out.println("Not equal");
else
System.out.println("Equal");
}}
What is the result?
A. The output is “Equal”
B. The output in “Not Equal”
C. An error at " if (x = y)" causes compilation to fall.
D. The program executes but no output is show on console. Answer: C
Question: what is the class variables ?
Answer: When we create a number of objects of the same class, then each object will share a common copy of variables. That means that there is only one copy per class, no matter how many objects are created from it. Class variables or static variables are declared with the static keyword in a class, but mind it that it should be declared outside outside a class. These variables are stored in static memory. Class variables are mostly used for constants, variable that never change its initial value. Static variables are always called by the class name. This variable is created when the program starts i.e. it is created before the instance is created of class by using new operator and gets destroyed when the programs stops. The scope of the class variable is same a instance variable. The class variable can be defined anywhere at class level with the keyword static. It initial value is same as instance variable. When the class variable is defined as int then it's initial value is by default zero, when declared boolean its default value is false and null for object references. Class variables are associated with the class, rather than with any object.
Question: What is the difference between the instanceof and getclass, these two are same or not ?
Answer: instanceof is a operator, not a function while getClass is a method of java.lang.Object class. Consider a condition where we use
if(o.getClass().getName().equals("java.lang.Math")){ }
This method only checks if the classname we have passed is equal to java.lang.Math. The class java.lang.Math is loaded by the bootstrap ClassLoader. This class is an abstract class.This class loader is responsible for loading classes. Every Class object contains a reference to the ClassLoader that defines. getClass() method returns the runtime class of an object. It fetches the java instance of the given fully qualified type name. The code we have written is not necessary, because we should not compare getClass.getName(). The reason behind it is that if the two different class loaders load the same class but for the JVM, it will consider both classes as different classes so, we can't compare their names. It can only gives the implementing class but can't compare a interface, but instanceof operator can.
The instanceof operator compares an object to a specified type. We can use it to test if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface. We should try to use instanceof operator in place of getClass() method. Remember instanceof opeator and getClass are not same. Try this example, it will help you to better understand the difference between the two.
Interface one{
}
Class Two implements one {
}
Class Three implements one {
}
public class Test {
public static void main(String args[]) {
one test1 = new Two();
one test2 = new Three();
System.out.println(test1 instanceof one); //true
System.out.println(test2 instanceof one); //true
System.out.println(Test.getClass().equals(test2.getClass())); //false
}
}
A: 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.
Q: How you will make available any Message Resources Definitions file to the Struts Framework Environment?
A: 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" />
Q: What is Action Class?
A: 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.
Q: Write code of any Action Class?
A: Here is the code of Action Class that returns the ActionForward object.
TestAction.java
Q: What is ActionForm?
A: An ActionForm is a JavaBean that extends
Q: What is Struts Validator Framework?
A: 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.
Q. Give the Details of XML files used in Validator Framework?
A: 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.
Q. How you will display validation fail errors on jsp page?
A: Following tag displays all the errors:
<html:errors/>
Q. How you will enable front-end validation based on the xml in validation.xml?
A: 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.
Question: Can I setup Apache Struts to use multiple configuration files?
Answer: Yes Struts can use multiple configuration files. Here is the configuration example:
<servlet>
<servlet-name>banking</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-authentication.xml,
/WEB-INF/struts-help.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Question: What are the disadvantages of Struts?
Answer: Struts is very robust framework and is being used extensively in the industry. But there are some disadvantages of the Struts:
a) High Learning Curve
Struts requires lot of efforts to learn and master it. For any small project less experience developers could spend more time on learning the Struts.
b) Harder to learn
Struts are harder to learn, benchmark and optimize.
Question: What is Struts Flow?
Answer: Struts Flow is a port of Cocoon's Control Flow to Struts to allow complex workflow, like multi-form wizards, to be 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 in time in an application. The code is based on a proof-of-concept Dave Johnson put together to show how the Control Flow could be extracted from Cocoon.
Question: What are the difference between <bean:message> and <bean:write>?
Answer: <bean:message>: This tag is used to output locale-specific text (from the properties files) from a MessageResources bundle.
<bean:write>: This tag is used to output property values from a bean. <bean:write> is a commonly used tag which enables the programmers to easily present the data.
Question: What is LookupDispatchAction?
Answer: 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. (Ref. http://struts.apache.org/1.2.7/api/org/apache/struts/actions/LookupDispatchAction.html).
Question: What are the components of Struts?
Answer: Struts is based on the MVC design pattern. Struts components can be categories into Model, View and Controller.
Model: Components like business logic / business processes and data are the part of Model.
View: JSP, HTML etc. are part of View
Controller: Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.
Question: What are Tag Libraries provided with Struts?
Answer: 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 scriptlets.
d) Nested Tags: Nested Tags helps to work with the nested context.
Question: What are the core classes of the Struts Framework?
Answer: Core classes of Struts Framework are ActionForm, Action, ActionMapping, ActionForward, ActionServlet etc.
Question: What are difference between ActionErrors and ActionMessage?
Answer: ActionMessage: A class that encapsulates messages. Messages can be either global or they are specific to a particular bean property.
Each individual message is described by an ActionMessage object, which contains a message key (to be looked up in an appropriate message resources database), and up to four placeholder arguments used for parametric substitution in the resulting message.
ActionErrors: A class that encapsulates the error messages being reported by the validate() method of an ActionForm. Validation errors are either global to the entire ActionForm bean they are associated with, or they are specific to a particular bean property (and, therefore, a particular input field on the corresponding form).
Question: How you will handle exceptions in Struts?
Answer: In Struts you can handle the exceptions in two ways:
a) Declarative Exception Handling: You can either define global exception handling tags in your struts-config.xml or define the exception handling tags within <action>..</action> tag.
b) Programmatic Exception Handling: Here you can use try{}catch{} block to handle the exception.
Struts is a light weight package.It consists of 5 core packages and 5 tag lig directories.
whenever client send request first it goes to CONTROLLER
part(ActionServlet)it reads the request data& decides about which action
should be performed to process the client request after that it forwards to the
appropriate action class(MODEL part)where the functionality code(bussiness
logic) will be there, from this MODEL part the control goes back to CONTROLLER
part from here the appropriate jsp pages(VIEW part) can be picked up for
presenthing(displaying) the result on the clients browser.
when ever client sends a request, first it will reads the
web.xml and creates a action servlet object and wc(webcontainer) calls the
init()on action servlet.The struts code that is part of a init()reads the
information that is available in the StrutsConfig.xml and executes the
appropriate action class with the help of action mapping that is part of a
SC.xml.
Struts is a framework with set of cooperating classes,
servlets and JSP tags that make up a reusable MVC 2 design.
> Client (Browser): A request from the client browser creates an HTTP request. The Web container will
respond to the request with an HTTP response, which gets displayed on the browser.
> Controller (ActionServlet class and Request Processor class): The controller receives the request from the browser, and makes the decision where to send the request based on the struts-config.xml.
Design pattern: Struts controller uses the command design pattern by calling the Action classes based on the configuration file struts-config.xml and the RequestProcessor class?s process() method uses template
method design pattern (Refer Q11 in How would you go about ? section) by calling a sequence of methods
like:
? processPath(request, response):- read the request URI to determine path element.
?processMapping(request,response):- use the path information to get the action mapping
?processRoles(request,respose,mapping):- Struts Web application security which provides an authorization scheme. By default calls request.isUserInRole(). For example allow /addCustomer action if the role is executive.
<action path=?/addCustomer? roles=?executive?>
?processValidate(request,response,form,mapping):- calls the vaildate() method of the ActionForm.
?processActionCreate(request,response,mapping):- gets the name of the action class from the ?type? attribute of the <action> element.
?processActionPerform(req,res,action,form,mapping):- This method calls the execute method of the Action class which is where business logic is written.
> Business Logic (Action class): The Servlet dispatches the request to Action classes, which act as a thin wrapper to the business logic (The actual business logic is carried out by either EJB session beans and/or plain Java classes). The action class helps control the workflow of the application. (Note: The Action class
should only control the workflow and not the business logic of the application). The Action class uses the Adapter design pattern
> ActionForm class: Java representation of HTTP input data. They can carry data over from one request to another, but actually represent the data submitted with the request.
> View (JSP): The view is a JSP file. There is no business or flow logic and no state information. The JSP should just have tags to represent the data on the browser.
ActionServlet class is the controller part of the MVC implementation and is the core of the framework. It processes user requests, determines what the user is trying to achieve according to the request, pulls data from
the model (if necessary) to be given to the appropriate view, and selects the proper view to respond to the user.
As discussed above ActionServlet class delegates the grunt of the work to the RequestProcessor and Action classes.
The ActionForm class maintains the state for the Web application. ActionForm is an abstract class, which is subclassed for every input form model. The struts-config.xml file controls, which HTML form request maps to
which ActionForm.
The Action class is a wrapper around the business logic. The purpose of the Action class is to translate the HttpServletRequest to the business logic. To use the Action class, subclass and overwrite the execute() method.
The actual business logic should be in a separate package or EJB to allow reuse of business logic in protocol independent manner (ie the business logic should be used not only by HTTP clients but also by WAP clients, EJB clients, Applet clients etc).
Struts is a framework that follows MVC2 design pattern.
Below is the high level flow of struts framework.
Whenever user submits the JSP page, lets assume login page, whenever user gives user name and password and clicks on submit, first it goes to controller (struts-config.xml) and verifies the correcponding action like in login.jsp, if user clicks on SUBMIT button suppose it should go to /login.do, then corresponding login action will be invoked in struts-config.xml.
Based on the validate parameter value of struts action, control will go to either form.Validate() (if validate=true in struts-config) or action.performAction() (if validate=false in struts-config), and once the form validate is executed with out any action errors, action class will be executed and from action class --> command class --> Service class --> DAO Class and once all the business logic is done then based on the <forward> tag in action of struts config corresponding view will be displayed.
This is the high level flow.
Q:What is the purpose of tiles-def.xml file, resourcebundle.properties file, validation.xml file?
1. tiles-def.xml
tiles-def.xml is used as a configuration file for an appliction during tiles development
You can define the layout / header / footer / body content for your View.
Eg:
<tiles-definitions>
<definition name="siteLayoutDef" path="/layout/thbiSiteLayout.jsp">
<put name="title" value="Title of the page" />
<put name="header" value="/include/thbiheader.jsp" />
<put name="footer" value="/include/thbifooter.jsp" />
<put name="content" type="string">
Content goes here
</put>
</definition>
</tiles-definitions>
<tiles-definitions>
<definition name="userlogin" extends="siteLayoutDef">
<put name="content" value="/dir/login.jsp" />
</definition>
</tiles-definitions>
2. validation.xml
The validation.xml file is used to declare sets of validations that should be applied to Form Beans.
Each Form Bean you want to validate has its own definition in this file
Inside that definition, you specify the validations you want to apply to the Form Bean's fields.
Eg:
<form-validation>
<formset>
<form name="logonForm">
<field property="username"
depends="required">
<arg0 key=" prompt.username"/>
</field>
<field property="password"
depends="required">
<arg0 key="prompt.password"/>
</field>
</form>
</formset>
</form-validation>
3. Resourcebundle.properties
Instead of having hard-coded error messages in the framework, Struts Validator allows you to specify a key to a message in the ApplicationResources.properties (or resourcebundle.properties) file that should be returned if a validation fails.
Eg:
In ApplicationResources.properties
errors.registrationForm.name={0} Is an invalid name.
In the registrationForm.jsp
<html:messages id="messages" property="name">
<font color="red">
<bean:write name="messages" />
</html:messages>
Output(in red color) : abc Is an invalid name
Submitted by Krishnam R Lalisetti (bluecrims@gmail.com)
________________
1. Purpose of tiles-def.xml file is used to in the design face of the webpage. For example in the webpage "top or bottom or left is
fixed" center might be dynamically chaged.
It is used for the easy design of the web sites. Reusability
2. resourcebundle.properties file is used for lot of purpose. One of its purpose is internationalization. We can make our page to view on any language. It is independent of it. Just based on the browser setting it selects the language and it displayed as you mentioned in the resourcebundle.properties file.
3. Validation rule.xml is used to put all the validation of the front-end in the validationrule.xml. So it verifies. If the same rule is applied in more than one page. No need to write the code once again in each page. Use validation to chek the errors in forms.
Submitted by R.Eswaramoorthy (eswar@cgvakindia.com)
_____________
tiles-def.xml - is required if your application incorporates the tiles framework in the "View" part of MVC. Generally we used to have a traditional JSP's (Which contgains HTML & java scriplets) are used in view. But Tiles is an advanced (mode or less ) implementation of frames used in HTML. We used to define the frames in HTML to seperate the header html, footer html, menu or left tree and body.html to reuse the contents. Hence in the same way, Tiles are defined to reuse the jsp's in struts like architectures, and we can define the jsp's which all are to be display at runtime, by providing the jsp names at runtime. To incorporate this we need tile-def.xml and the Class generally which extends RequestProcessor should extend TilesRequestProcessor.
resourcebundle.properties -- It is to incorporate i18n (internationalization) in View part of MVC.
validation.xml - This file is responsible for business validations carried at server side before processing the request actually. It reduces the complexity in writing _JavaScript validations, and in this way, we can hide the validations from the user, in View of MVC.
Submitted by Sagar GV (mydearsagar@yahoo.com)
____________________
1.The Tiles Framework is an advanced version of that
comes bundled with the Struts Webapp framework. Its
purpose is reduce the duplication between jsp pages as
well as make layouts flexible and easy to maintain. It
integrates with Struts using the concept of named
views or definitions.
2.Resourcebundle.properties is used to maintian all
the strings that are used in the application and thier
corresponding equalents in different desired
languages. All the strings/labels in the application
using Struts will get it labels from this file only
depending on locale. This is an i18n implementation of
struts
3. This validation.xml configuration file defines
which validation routines that is used to validate
Form Beans. You can define validation logic for any
number of Form Beans in this configuration file.
Inside that definition, you specify the validations
you want to apply to the Form Bean's fields. The
definitions in this file use the logical names of Form
Beans from the struts-config.xml file along with the
logical names of validation routines from the
validator-rules.xml file to tie the two together.
Submitted by Binaya Patel (binaya_patel@yahoo.co.in)
Tiles Framework is one of the advanced framework which
reduces the replication in JSP Codes. Suppose we have an application where Page
should display with some header (Logo of the company,
welcome message if user is logged in), vertical menu (like available products
as links), body part(product details once user clicks
on product link of vertical menu), footer (licence info, contact links etc),
then tiles helps us to have a common header jsp, vertical menu jsp, footer jsp
and different body.jsps for each product and allows to merge them seperately
with one name. Tiles-def.xml is a configuration file used to merge the JSPs
with one common name.
Validation.xml : Validation framework allows user to validate the input data before performing the business logic. We have two configuration files in validation framework, they are
Validation-rules.xml
Validation.xml
User can declare more than one validation.xml in sdingle applicaiton based on the requirement (like suppose u have 3 modules in appln, then u can create 3 different validation.xmls, one for each module). Validation-rules.xml helps the user to declare the common predefined values and common validators and based on these validation-rules.xml, user can write his own validation.xmls for each form.
Application resources.properties: Struts supports internationalization, where based on the locale value lables in the page may vary(like English in US, french in france etc). This can be implemented with application resources.properties file where resource file for each locale and system loads the reource properties based on the locale value.
What is the difference between a normal servlet and action servlet?
In struts , their is no facility of backward flow.
Suppose we are in page 1 and when we submit it calls action mapping page2.Their may be lot of variable stored in session , which is available to page2.Now we wish to go page1 from page 2, for this we have to call the action mapping of page1. But struts flow is always in forward direction. So when we call page 1, values stored in session never get reversed.So it reduces the performance.
To resolve this problem of struts, Their is a framework called Web Flow Nevigation Manager(WFNM) of Sourgeforge.net.This framework can be integrated with struts.
The Draw of Struts is Navigation of Different pages.
Case:
Suppose we have 10 pages right now we r in 4 page we want to go to 2 page by using <- we went to 2nd page after modification is done in 2nd page we come to 3 ,4 .. pages the was not persist it seems new pages.
In struts the first to recieve the request is
Actionservlet. So, there is no chance for you to make changes before
Functionality of Action Servlet can be changed by making
use of " RequestProcessor" class.
Request can be manipulated in RequestPreProcessor before
reaching to ActionServlet. This class is responsible to populate the request
values to ActionForm bean.
action class implemented by org.apache.struts.action.Action
public ActionForwad execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse)
{
return mapping.findForward("");
}
1. We can seperate the business logic from presentation
logic
2.It facilitates to write the java code inside a html environment
if we use servlets then we need to write the html tags inside out.write() number of times. it is not possible in all cases and it combines the businesslogic and presentation logic which reduces security
"...it is not possible in all cases and it combines
the businesslogic and presentation logic which reduces security" -
This is incorrect as jsp is translated into a servlet by the container and there is no difference between jsp & servlet except that "It facilitates to write the java code inside a html environment"
It's a reference to struts in the architectural sense, a
reminder of the nearly invisible pieces that hold up buildings, houses, and
bridges.
This tag is used whenever the requested
variable has a value which is present in the sub string. To evaluate the
contents present in the nested tag, logic match is used. This tag is used when
the requested value is present in the tag of the variable in which this value
is present.
Answer: Access specifiers are keywords that determines the type of access to the member of a class. These are:
- Public
- Protected
- Private
- Defaults
Answer: Wrapper class is wrapper around a primitive data type. An instance of a wrapper class contains, or wraps, a primitive value of the corresponding type.
Following table lists the primitive types and the corresponding wrapper classes:
Primitive
|
Wrapper
|
boolean
|
java.lang.Boolean
|
byte
|
java.lang.Byte
|
char
|
java.lang.Character
|
double
|
java.lang.Double
|
float
|
java.lang.Float
|
int
|
java.lang.Integer
|
long
|
java.lang.Long
|
short
|
java.lang.Short
|
void
|
java.lang.Void
|
Question: Read the following program:
public static void main(String [] args) {
int x = 3;
int y = 1;
if (x = y)
System.out.println("Not equal");
else
System.out.println("Equal");
}}
What is the result?
A. The output is “Equal”
B. The output in “Not Equal”
C. An error at " if (x = y)" causes compilation to fall.
D. The program executes but no output is show on console. Answer: C
Question: what is the class variables ?
Answer: When we create a number of objects of the same class, then each object will share a common copy of variables. That means that there is only one copy per class, no matter how many objects are created from it. Class variables or static variables are declared with the static keyword in a class, but mind it that it should be declared outside outside a class. These variables are stored in static memory. Class variables are mostly used for constants, variable that never change its initial value. Static variables are always called by the class name. This variable is created when the program starts i.e. it is created before the instance is created of class by using new operator and gets destroyed when the programs stops. The scope of the class variable is same a instance variable. The class variable can be defined anywhere at class level with the keyword static. It initial value is same as instance variable. When the class variable is defined as int then it's initial value is by default zero, when declared boolean its default value is false and null for object references. Class variables are associated with the class, rather than with any object.
Question: What is the difference between the instanceof and getclass, these two are same or not ?
Answer: instanceof is a operator, not a function while getClass is a method of java.lang.Object class. Consider a condition where we use
if(o.getClass().getName().equals("java.lang.Math")){ }
This method only checks if the classname we have passed is equal to java.lang.Math. The class java.lang.Math is loaded by the bootstrap ClassLoader. This class is an abstract class.This class loader is responsible for loading classes. Every Class object contains a reference to the ClassLoader that defines. getClass() method returns the runtime class of an object. It fetches the java instance of the given fully qualified type name. The code we have written is not necessary, because we should not compare getClass.getName(). The reason behind it is that if the two different class loaders load the same class but for the JVM, it will consider both classes as different classes so, we can't compare their names. It can only gives the implementing class but can't compare a interface, but instanceof operator can.
The instanceof operator compares an object to a specified type. We can use it to test if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface. We should try to use instanceof operator in place of getClass() method. Remember instanceof opeator and getClass are not same. Try this example, it will help you to better understand the difference between the two.
Interface one{
}
Class Two implements one {
}
Class Three implements one {
}
public class Test {
public static void main(String args[]) {
one test1 = new Two();
one test2 = new Three();
System.out.println(test1 instanceof one); //true
System.out.println(test2 instanceof one); //true
System.out.println(Test.getClass().equals(test2.getClass())); //false
}
}
Q: What is Jakarta Struts Framework?
A: Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta 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.
Q: What is ActionServlet?A: Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta 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.
A: 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.
Q: How you will make available any Message Resources Definitions file to the Struts Framework Environment?
A: 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" />
Q: What is Action Class?
A: 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.
Q: Write code of any Action Class?
A: Here is the code of Action Class that returns the ActionForward object.
TestAction.java
|
A: 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.Q: What is Struts Validator Framework?
A: 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.
Q. Give the Details of XML files used in Validator Framework?
A: 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.
Q. How you will display validation fail errors on jsp page?
A: Following tag displays all the errors:
<html:errors/>
Q. How you will enable front-end validation based on the xml in validation.xml?
A: 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.
Question: Can I setup Apache Struts to use multiple configuration files?
Answer: Yes Struts can use multiple configuration files. Here is the configuration example:
<servlet>
<servlet-name>banking</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-authentication.xml,
/WEB-INF/struts-help.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Question: What are the disadvantages of Struts?
Answer: Struts is very robust framework and is being used extensively in the industry. But there are some disadvantages of the Struts:
a) High Learning Curve
Struts requires lot of efforts to learn and master it. For any small project less experience developers could spend more time on learning the Struts.
b) Harder to learn
Struts are harder to learn, benchmark and optimize.
Question: What is Struts Flow?
Answer: Struts Flow is a port of Cocoon's Control Flow to Struts to allow complex workflow, like multi-form wizards, to be 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 in time in an application. The code is based on a proof-of-concept Dave Johnson put together to show how the Control Flow could be extracted from Cocoon.
Question: What are the difference between <bean:message> and <bean:write>?
Answer: <bean:message>: This tag is used to output locale-specific text (from the properties files) from a MessageResources bundle.
<bean:write>: This tag is used to output property values from a bean. <bean:write> is a commonly used tag which enables the programmers to easily present the data.
Question: What is LookupDispatchAction?
Answer: 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. (Ref. http://struts.apache.org/1.2.7/api/org/apache/struts/actions/LookupDispatchAction.html).
Question: What are the components of Struts?
Answer: Struts is based on the MVC design pattern. Struts components can be categories into Model, View and Controller.
Model: Components like business logic / business processes and data are the part of Model.
View: JSP, HTML etc. are part of View
Controller: Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.
Question: What are Tag Libraries provided with Struts?
Answer: 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 scriptlets.
d) Nested Tags: Nested Tags helps to work with the nested context.
Question: What are the core classes of the Struts Framework?
Answer: Core classes of Struts Framework are ActionForm, Action, ActionMapping, ActionForward, ActionServlet etc.
Question: What are difference between ActionErrors and ActionMessage?
Answer: ActionMessage: A class that encapsulates messages. Messages can be either global or they are specific to a particular bean property.
Each individual message is described by an ActionMessage object, which contains a message key (to be looked up in an appropriate message resources database), and up to four placeholder arguments used for parametric substitution in the resulting message.
ActionErrors: A class that encapsulates the error messages being reported by the validate() method of an ActionForm. Validation errors are either global to the entire ActionForm bean they are associated with, or they are specific to a particular bean property (and, therefore, a particular input field on the corresponding form).
Question: How you will handle exceptions in Struts?
Answer: In Struts you can handle the exceptions in two ways:
a) Declarative Exception Handling: You can either define global exception handling tags in your struts-config.xml or define the exception handling tags within <action>..</action> tag.
b) Programmatic Exception Handling: Here you can use try{}catch{} block to handle the exception.
What is struts flow? Explain in detail??
Struts is a open source
implementation of MVC design pattern to develop large
scale web applications.Struts framework makes it easier to design
realible,scalable web applications in java.Struts is not only thread safe but
also thread dependent.It instantiates each action once and allows others to be
threaded through the original object.Struts reduces the for redundant
jsp's.ActionForm stratagy reduces the need of sub class hierarchy.Struts is a light weight package.It consists of 5 core packages and 5 tag lig directories.
> Client (Browser): A request from the client browser creates an HTTP request. The Web container will
respond to the request with an HTTP response, which gets displayed on the browser.
> Controller (ActionServlet class and Request Processor class): The controller receives the request from the browser, and makes the decision where to send the request based on the struts-config.xml.
Design pattern: Struts controller uses the command design pattern by calling the Action classes based on the configuration file struts-config.xml and the RequestProcessor class?s process() method uses template
method design pattern (Refer Q11 in How would you go about ? section) by calling a sequence of methods
like:
? processPath(request, response):- read the request URI to determine path element.
?processMapping(request,response):- use the path information to get the action mapping
?processRoles(request,respose,mapping):- Struts Web application security which provides an authorization scheme. By default calls request.isUserInRole(). For example allow /addCustomer action if the role is executive.
<action path=?/addCustomer? roles=?executive?>
?processValidate(request,response,form,mapping):- calls the vaildate() method of the ActionForm.
?processActionCreate(request,response,mapping):- gets the name of the action class from the ?type? attribute of the <action> element.
?processActionPerform(req,res,action,form,mapping):- This method calls the execute method of the Action class which is where business logic is written.
> Business Logic (Action class): The Servlet dispatches the request to Action classes, which act as a thin wrapper to the business logic (The actual business logic is carried out by either EJB session beans and/or plain Java classes). The action class helps control the workflow of the application. (Note: The Action class
should only control the workflow and not the business logic of the application). The Action class uses the Adapter design pattern
> ActionForm class: Java representation of HTTP input data. They can carry data over from one request to another, but actually represent the data submitted with the request.
> View (JSP): The view is a JSP file. There is no business or flow logic and no state information. The JSP should just have tags to represent the data on the browser.
ActionServlet class is the controller part of the MVC implementation and is the core of the framework. It processes user requests, determines what the user is trying to achieve according to the request, pulls data from
the model (if necessary) to be given to the appropriate view, and selects the proper view to respond to the user.
As discussed above ActionServlet class delegates the grunt of the work to the RequestProcessor and Action classes.
The ActionForm class maintains the state for the Web application. ActionForm is an abstract class, which is subclassed for every input form model. The struts-config.xml file controls, which HTML form request maps to
which ActionForm.
The Action class is a wrapper around the business logic. The purpose of the Action class is to translate the HttpServletRequest to the business logic. To use the Action class, subclass and overwrite the execute() method.
The actual business logic should be in a separate package or EJB to allow reuse of business logic in protocol independent manner (ie the business logic should be used not only by HTTP clients but also by WAP clients, EJB clients, Applet clients etc).
Whenever user submits the JSP page, lets assume login page, whenever user gives user name and password and clicks on submit, first it goes to controller (struts-config.xml) and verifies the correcponding action like in login.jsp, if user clicks on SUBMIT button suppose it should go to /login.do, then corresponding login action will be invoked in struts-config.xml.
Based on the validate parameter value of struts action, control will go to either form.Validate() (if validate=true in struts-config) or action.performAction() (if validate=false in struts-config), and once the form validate is executed with out any action errors, action class will be executed and from action class --> command class --> Service class --> DAO Class and once all the business logic is done then based on the <forward> tag in action of struts config corresponding view will be displayed.
This is the high level flow.
Q:What is the purpose of tiles-def.xml file, resourcebundle.properties file, validation.xml file?
1. tiles-def.xml
tiles-def.xml is used as a configuration file for an appliction during tiles development
You can define the layout / header / footer / body content for your View.
Eg:
<tiles-definitions>
<definition name="siteLayoutDef" path="/layout/thbiSiteLayout.jsp">
<put name="title" value="Title of the page" />
<put name="header" value="/include/thbiheader.jsp" />
<put name="footer" value="/include/thbifooter.jsp" />
<put name="content" type="string">
Content goes here
</put>
</definition>
</tiles-definitions>
<tiles-definitions>
<definition name="userlogin" extends="siteLayoutDef">
<put name="content" value="/dir/login.jsp" />
</definition>
</tiles-definitions>
2. validation.xml
The validation.xml file is used to declare sets of validations that should be applied to Form Beans.
Each Form Bean you want to validate has its own definition in this file
Inside that definition, you specify the validations you want to apply to the Form Bean's fields.
Eg:
<form-validation>
<formset>
<form name="logonForm">
<field property="username"
depends="required">
<arg0 key=" prompt.username"/>
</field>
<field property="password"
depends="required">
<arg0 key="prompt.password"/>
</field>
</form>
</formset>
</form-validation>
3. Resourcebundle.properties
Instead of having hard-coded error messages in the framework, Struts Validator allows you to specify a key to a message in the ApplicationResources.properties (or resourcebundle.properties) file that should be returned if a validation fails.
Eg:
In ApplicationResources.properties
errors.registrationForm.name={0} Is an invalid name.
In the registrationForm.jsp
<html:messages id="messages" property="name">
<font color="red">
<bean:write name="messages" />
</html:messages>
Output(in red color) : abc Is an invalid name
Submitted by Krishnam R Lalisetti (bluecrims@gmail.com)
________________
1. Purpose of tiles-def.xml file is used to in the design face of the webpage. For example in the webpage "top or bottom or left is
fixed" center might be dynamically chaged.
It is used for the easy design of the web sites. Reusability
2. resourcebundle.properties file is used for lot of purpose. One of its purpose is internationalization. We can make our page to view on any language. It is independent of it. Just based on the browser setting it selects the language and it displayed as you mentioned in the resourcebundle.properties file.
3. Validation rule.xml is used to put all the validation of the front-end in the validationrule.xml. So it verifies. If the same rule is applied in more than one page. No need to write the code once again in each page. Use validation to chek the errors in forms.
Submitted by R.Eswaramoorthy (eswar@cgvakindia.com)
_____________
tiles-def.xml - is required if your application incorporates the tiles framework in the "View" part of MVC. Generally we used to have a traditional JSP's (Which contgains HTML & java scriplets) are used in view. But Tiles is an advanced (mode or less ) implementation of frames used in HTML. We used to define the frames in HTML to seperate the header html, footer html, menu or left tree and body.html to reuse the contents. Hence in the same way, Tiles are defined to reuse the jsp's in struts like architectures, and we can define the jsp's which all are to be display at runtime, by providing the jsp names at runtime. To incorporate this we need tile-def.xml and the Class generally which extends RequestProcessor should extend TilesRequestProcessor.
resourcebundle.properties -- It is to incorporate i18n (internationalization) in View part of MVC.
validation.xml - This file is responsible for business validations carried at server side before processing the request actually. It reduces the complexity in writing _JavaScript validations, and in this way, we can hide the validations from the user, in View of MVC.
Submitted by Sagar GV (mydearsagar@yahoo.com)
____________________
1.The Tiles Framework is an advanced version of that
comes bundled with the Struts Webapp framework. Its
purpose is reduce the duplication between jsp pages as
well as make layouts flexible and easy to maintain. It
integrates with Struts using the concept of named
views or definitions.
2.Resourcebundle.properties is used to maintian all
the strings that are used in the application and thier
corresponding equalents in different desired
languages. All the strings/labels in the application
using Struts will get it labels from this file only
depending on locale. This is an i18n implementation of
struts
3. This validation.xml configuration file defines
which validation routines that is used to validate
Form Beans. You can define validation logic for any
number of Form Beans in this configuration file.
Inside that definition, you specify the validations
you want to apply to the Form Bean's fields. The
definitions in this file use the logical names of Form
Beans from the struts-config.xml file along with the
logical names of validation routines from the
validator-rules.xml file to tie the two together.
Submitted by Binaya Patel (binaya_patel@yahoo.co.in)
Validation.xml : Validation framework allows user to validate the input data before performing the business logic. We have two configuration files in validation framework, they are
Validation-rules.xml
Validation.xml
User can declare more than one validation.xml in sdingle applicaiton based on the requirement (like suppose u have 3 modules in appln, then u can create 3 different validation.xmls, one for each module). Validation-rules.xml helps the user to declare the common predefined values and common validators and based on these validation-rules.xml, user can write his own validation.xmls for each form.
Application resources.properties: Struts supports internationalization, where based on the locale value lables in the page may vary(like English in US, french in france etc). This can be implemented with application resources.properties file where resource file for each locale and system loads the reource properties based on the locale value.
What is the difference between a normal servlet and action servlet?
Both r used for controlling
purpose,but Normal servlet is servlet
the user is resposible.But the action servlet is by deafaulty configure with struts Framework.
ActionServlets implements FrontController Design pattern.
ActionServlet is a singleton,but NormalServlet is not a Singleton
the user is resposible.But the action servlet is by deafaulty configure with struts Framework.
ActionServlets implements FrontController Design pattern.
ActionServlet is a singleton,but NormalServlet is not a Singleton
What is the difference between
Struts 1.0 and Struts 1.1.
The new features added to Struts 1.1 are 1.
RequestProcessor class 2. Method perform() replaced by execute() in Struts base
Action Class 3. Changes to web.xml and struts-config.xml4.Declarative exception
handling5.Dynamic ActionForms6.Plug-ins7.Multiple Application
Modules8.Nested Tags9.The Struts Validator10.Change to the ORO package11.Change
to Commons logging12.Removal of Admin actions13. Deprecation of the
GenericDataSource
What
are the drawbacks of Struts
Suppose we are in page 1 and when we submit it calls action mapping page2.Their may be lot of variable stored in session , which is available to page2.Now we wish to go page1 from page 2, for this we have to call the action mapping of page1. But struts flow is always in forward direction. So when we call page 1, values stored in session never get reversed.So it reduces the performance.
To resolve this problem of struts, Their is a framework called Web Flow Nevigation Manager(WFNM) of Sourgeforge.net.This framework can be integrated with struts.
Case:
Suppose we have 10 pages right now we r in 4 page we want to go to 2 page by using <- we went to 2nd page after modification is done in 2nd page we come to 3 ,4 .. pages the was not persist it seems new pages.
In struts, if any changes are made
to before the request reaches to actionservlet, where you do the changes?
What
is Action Class. What are the methods in Action class
An Action is an adapter between the contents of an incoming HTTP request and
the corresponding business logic that should be executed to process this
request. The controller (RequestProcessor) will select
an appropriate Action for each request, create an instance (if necessary), and
call the execute method.
Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. This means you should design with the following items in mind:
Instance and static variables MUST NOT be used to store information related to the state of a particular request. They MAY be used to share global resources across requests for the same action.
Access to other resources (JavaBeans, session variables, etc.) MUST be synchronized if those resources require protection. (Generally, however, resource classes should be designed to provide their own protection where necessary.
When an Action instance is first created, the controller will call setServlet with a non-null argument to identify the servlet instance to which this Action is attached. When the servlet is to be shut down (or restarted), the setServlet method will be called with a null argument, which can be used to clean up any allocated resources in use by this Action.
Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. This means you should design with the following items in mind:
Instance and static variables MUST NOT be used to store information related to the state of a particular request. They MAY be used to share global resources across requests for the same action.
Access to other resources (JavaBeans, session variables, etc.) MUST be synchronized if those resources require protection. (Generally, however, resource classes should be designed to provide their own protection where necessary.
When an Action instance is first created, the controller will call setServlet with a non-null argument to identify the servlet instance to which this Action is attached. When the servlet is to be shut down (or restarted), the setServlet method will be called with a null argument, which can be used to clean up any allocated resources in use by this Action.
public ActionForwad execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse)
{
return mapping.findForward("");
}
In struts why we use jsp as
presentation layer? can we use servlet as presentation layer?
2.It facilitates to write the java code inside a html environment
if we use servlets then we need to write the html tags inside out.write() number of times. it is not possible in all cases and it combines the businesslogic and presentation logic which reduces security
This is incorrect as jsp is translated into a servlet by the container and there is no difference between jsp & servlet except that "It facilitates to write the java code inside a html environment"
What's the difference between Struts
and Turbine? What's the difference between Struts and Espresso?
If you are starting from scratch, packages
like Turbine and Espresso can be very helpful since they try to provide all of
the basic services that your team is likely to need.
Such services include things like data persistence and
logging.
If you are not starting from scratch, and need to hook up your web application to an existing infrastructure, then "plain vanilla" Struts can be a better choice. The core Struts framework does not presuppose that you are using a given set of data persistence, presentation, or logging tools. Anything goes =:0)
Compared to other offerings, Struts endeavors to be a minimalist framework. We try leverage existing technologies whenever we can and provide only the missing pieces you need to combine disparate technologies into a coherent application. This is great when you want to select your own tools to use with Struts. But, if you prefer a more integrated infrastructure, then packages like Turbine or Espresso (which uses Struts) are perfectly good ways to go.
See also
If you are not starting from scratch, and need to hook up your web application to an existing infrastructure, then "plain vanilla" Struts can be a better choice. The core Struts framework does not presuppose that you are using a given set of data persistence, presentation, or logging tools. Anything goes =:0)
Compared to other offerings, Struts endeavors to be a minimalist framework. We try leverage existing technologies whenever we can and provide only the missing pieces you need to combine disparate technologies into a coherent application. This is great when you want to select your own tools to use with Struts. But, if you prefer a more integrated infrastructure, then packages like Turbine or Espresso (which uses Struts) are perfectly good ways to go.
See also
What
is the difference between strsuts 1.0 and struts 1.1 ?
In Struts1.0 Dayna action is not there
what
is oro ?
The Jakarta-ORO Java classes are a set of
text-processing Java classes that provide Perl5 compatible regular expressions,
AWK-like regular expressions, glob expressions, and utility classes for performing substitutions, splits, filtering filenames, etc.
This library is the successor to the OROMatcher, AwkTools, PerlTools, and
TextTools libraries originally from ORO, Inc. Despite little activity in the
form of new development initiatives, issue reports, questions, and suggestions
are responded to quickly.
What are the core classes of Struts?
Action, ActionForm, ActionServlet,
ActionMapping, ActionForward are basic classes of Structs.
Why
is it called Struts?
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
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
Will the Struts tags support other
markup languages such as WML ?
Struts itself is markup neutral. The
original Struts taglibs are only one example of how presentation
layer components can access the framework. The framework objects are exposed
through the standard application, session, and request
contexts, where any Java component in the application can make use of them.
Markup extensions that use Struts are available for Velocity and XLST, among others. A new Struts tag library for Java Server Faces is also in development.
For more about using WAP/WML with Struts see the article WAP up your EAserver.
Markup extensions that use Struts are available for Velocity and XLST, among others. A new Struts tag library for Java Server Faces is also in development.
For more about using WAP/WML with Struts see the article WAP up your EAserver.
Explain
the necessity of empty tag?
When the requested variable does not
contain any information, (null or empty) then this tag is used to know the
contents present in the other body parts of the tag. If the tag is nested then
it is advisable to use this tag as it may contain a bit of information.
Explain
about logic match tag?
What
part of MVC does Struts represent
Struts is mainly famous for its Action
Controller - which is nothing but the CONTROLLER part of MVC Pattern.
To add up, Struts is the framework which started mainly using the MVC-2 Pattern where in the Business logic is STRICTLY SEPARATED from the Presentation logic (mainly in JSPs).
To add up, Struts is the framework which started mainly using the MVC-2 Pattern where in the Business logic is STRICTLY SEPARATED from the Presentation logic (mainly in JSPs).
What is
Struts?
Struts is a web page development framework and an open source software that helps developers build web applications quickly and easily. Struts combines Java Servlets, Java Server Pages, custom tags, and message resources into a unified framework. It is a cooperative, synergistic platform, suitable for development teams, independent developers, and everyone between.
Struts is a web page development framework and an open source software that helps developers build web applications quickly and easily. Struts combines Java Servlets, Java Server Pages, custom tags, and message resources into a unified framework. It is a cooperative, synergistic platform, suitable for development teams, independent developers, and everyone between.
How is the MVC design pattern used in
Struts framework?
In the MVC design pattern, application flow is mediated by a central Controller. The Controller delegates requests to an appropriate handler. The handlers are tied to a Model, and each handler acts as an adapter between the request and the Model. The Model represents, or encapsulates, an application's business logic or state. Control is usually then forwarded back through the Controller to the appropriate View. The forwarding can be determined by consulting a set of mappings, usually loaded from a database or configuration file. This provides a loose coupling between the View and Model, which can make an application significantly easier to create and maintain.
Controller--Servlet controller which supplied by Struts itself; View --- what you can see on the screen, a JSP page and presentation components; Model --- System state and a business logic JavaBeans.
In the MVC design pattern, application flow is mediated by a central Controller. The Controller delegates requests to an appropriate handler. The handlers are tied to a Model, and each handler acts as an adapter between the request and the Model. The Model represents, or encapsulates, an application's business logic or state. Control is usually then forwarded back through the Controller to the appropriate View. The forwarding can be determined by consulting a set of mappings, usually loaded from a database or configuration file. This provides a loose coupling between the View and Model, which can make an application significantly easier to create and maintain.
Controller--Servlet controller which supplied by Struts itself; View --- what you can see on the screen, a JSP page and presentation components; Model --- System state and a business logic JavaBeans.
Who makes the Struts?
Struts is hosted by the Apache Software Foundation(ASF) as part of its Jakarta project, like Tomcat, Ant and Velocity.
Struts is hosted by the Apache Software Foundation(ASF) as part of its Jakarta project, like Tomcat, Ant and Velocity.
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.
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.
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.
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.
What are the core classes of Struts?
Action, ActionForm, ActionServlet, ActionMapping, ActionForward are basic classes of Structs.
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.
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.
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.
Struts implements the MVC/Layers pattern through the use of ActionForwards and ActionMappings to keep control-flow decisions out of presentation layer.
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.
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
--struts-html.tld
--struts-bean.tld
--struts-logic.tld
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
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
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.
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.
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 / >
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 / >
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.
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.
No comments:
Post a Comment