The Object-Graph Navigation Language OGNL is a powerful expression language that is used to
reference and manipulate data on the ValueStack. OGNL also helps in data transfer and type
conversion.
22.Which components are available using ActionContext map?
The ActionContext map consists of the following −
application − application scoped variables.
session − session scoped variables.
root / value stack − all your action variables are stored here.
request − request scoped variables.
parameters − request parameters.
atributes − the attributes stored in page, request, session and application scope.
23.Which interceptor is responsible for file upload support?
File uploading in Struts is possible through a pre-defined interceptor called FileUpload interceptor
which is available through the org.apache.struts2.interceptor.FileUploadInterceptor class and
included as part of the defaultStack.
24.What are the Struts2 configuration properties that control file uploading process?
Following are the Struts2 configuration properties that control file uploading process −
struts.multipart.maxSize − The maximum size inbytes of a file to be accepted as a file
upload. Default is 250M.
struts.multipart.parser − The library used to upload the multipart form. By default is
jakarta.
struts.multipart.saveDir − The location to store the temporary file. By default is
javax.servlet.context.tempdir.
25.What are the Struts2 error message keys that can come during file uploading process?
The fileUplaod interceptor uses several default error message keys −
struts.messages.error.uploading A general error that occurs when the file could not be
uploaded.
struts.messages.error.file.too.large Occurs when the uploaded file is too large as
specified by maximumSize.
struts.messages.error.content.type.not.allowed Occurs when the uploaded file does
not match the expected content types specified.
26.How to override the default error message that can come during file uploading process?
You can override the text of these messages in WebContent/WEB-INF/classes/messages.properties
resource files.
27.What is Structs 2 validation framework?
At Struts's core, we have the validation framework that assists the application to run the rules to
perform validation before the action method is executed. Action class should extend the
ActionSupport class, in order to get the validate method executed.
28.How Struts 2 validation works?
When the user presses the submit button, Struts 2 will automatically execute the validate method
and if any of the if statements listed inside the method are true, Struts 2 will call its addFieldError
method. If any errors have been added then Struts 2 will not proceed to call the execute method.
Rather the Struts 2 framework will return input as the result of calling the action.
So when validation fails and Struts 2 returns input, the Struts 2 framework will redisplay the view
file. Since we used Struts 2 form tags, Struts 2 will automatically add the error messages just above
the form filed.
These error messages are the ones we specified in the addFieldError method call. The
addFieldError method takes two arguments. The first is the form field name to which the error
applies and the second is the error message to display above that form field.
29.What is XML Based Validation in struts2?
The second method of doing validation is by placing an xml file next to the action class. Struts2
XML based validation provides more options of validation like email validation, integer range
validation, form validation field, expression validation, regex validation, required validation,
requiredstring validation, stringlength validation and etc.
30.What should be the name of xml file used for validation in struts?
The xml file needs to be named '[action-class]'-validation.xml.
31.What types of validations are available in xml based validation in struts2?
Following is the list of various types of field level and non-field level validation available in Struts2
−
date validator
double validator
email validator
expression validator
int validator
regex validator
required validator
requiredstring validator
stringlength validator
url validator
32.What is Internationalization?
Internationalization i18n is the process of planning and implementing products and services so that
they can easily be adapted to specific local languages and cultures, a process called localization.
The internationalization process is sometimes called translation or localization enablement.
33.How struts2 supports Internationalization?
Struts2 provides localization ie. internationalization i18n support through resource bundles,
interceptors and tag libraries in the following places −
The UI Tags.
Messages and Errors.
Within action classes.
34.What is the naming convention for a resource bundle file in struts2?
The simplest naming format for a resource file is −
bundlenam e_language_country.properties
Here bundlename could be ActionClass, Interface, SuperClass, Model, Package, Global resource
properties. Next part language_country represents the country locale for example Spanish Spain
locale is represented by es_ES and English UnitedStates locale is represented by en_US etc. Here you
can skip country part which is optional.
35.In which order Struts framework searches for a message bundle?
When you reference a message element by its key, Struts framework searches for a corresponding
message bundle in the following order −
ActionClass.properties
Interface.properties
SuperClass.properties
model.properties
package.properties
struts.properties
global.properties
36.Which class of struts is responsible to converts data types from string and vice versa?
StrutsTypeConverter class tells Struts how to convert Environment to a String and vice versa by
overriding two methods convertFromString and convertToString.
37.What inbuilt themes are provided by Struts2?
Struts 2 comes with three built-in themes −
simple theme − A minimal theme with no "bells and whistles". For example, the textfield tag
renders the HTML tag without a label, validation, error reporting, or any other
formatting or functionality.
xhtml theme − This is the default theme used by Struts 2 and provides all the basics that
the simple theme provides and adds several features like standard two-column table layout
for the HTML, Labels for each of the HTML, Validation and error reporting etc.
css_xhtml theme − This theme provides all the basics that the simple theme provides and
adds several features like standard two-column CSS-based layout, using
for the HTML
Struts Tags, Labels for each of the HTML Struts Tags, placed according to the CSS stylesheet.
38.How to handle exceptions in Structs?
Struts makes the exception handling easy by the use of the "exception" interceptor. The
"exception" interceptor is included as part of the default stack, so you don't have to do anything
extra to configure it. It is available out-of-the-box ready for you to use.
39.What is the purpose of @Results annotation?
A @Results annotation is a collection of results. Under the @Results annotation, we can have
multiple @Result annotations.
@ Results({
@ Result(nam e="success", value="/success.jsp"),
@ Result(nam e="error", value="/error.jsp")
})
public class Em ployee extends ActionSupport{
...
}
40.What is the purpose of @Result annotation?
The @result annotations have the name that correspond to the outcome of the execute method.
They also contain a location as to which view should be served corresponding to return value from
execute.
@ Result(nam e="success", value="/success.jsp")
public class Em ployee extends ActionSupport{
...
}