A reader sent it a set of Jakarta Struts questions used at his company.
- What is Jakarta Struts Framework? - 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.
- 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” />
- 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.
- 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"); } } - 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/>
- 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.

26 Comments on Jakarta struts questions
Hi,
I want to know why do we need abstarct class, methods and its advnatges. Please send me answer for my questions
Can the STRUTS nested tags support many parent to child relationships in one bean? i.e. a bean of many chapters contains a collection of many sections which belong to a chapter
The chapter bean with a collection of sections contains…
Chapter One
Section A
Section B
Chapter Two
Section C
Section D
It appears I have loaded the beans and collection correctly, but I can not get them to display correct. I get all the chapters and only the last section added to the collection.
hai ,
this is ravi.anyone pls give me the diff.between validate() and reset() methods in FormBean in struts
This is prasad.
In the form bean the reset() method will set the default values. and validate() method provides the any validations carryout by manually. in this method u r providing the code for validations.
Hi
I have one question.
how do we configure web.xml using with MVC design pettern struts.
Deven
hi,
1 . i want one answer i.e why java does not support multiple Inheitence?
2 . Why we need reset() setter() methos in struts?
1 . Why java does’nt support Multiple Inheritence?
2. what is ment by setter() and reset() in struts?what is the difference b/w them and validite()?
hi deven,
we can configue with web.xml is we can forward the config from the action class in that web.xml class=actionclass name=formclass and path and input are given then it forwarded to what ever jsp page u want that can be given in the input.
which class can be use EJB ans Where can be use EJB in Struts Architecture?
hi, i amith,i want to know what is the real use of actionmessages in realtime application.
Hi i am using struts validator framework for validating my form. Here i am stuck up with a problem
i need to do email validation. I have written a function of my own to check for invalid characters. In validator.xml i am calling first that function thn email validation. i am getting 2 alerts where i should get only one if i am entering invalid characters in email feild.
Help me on this..
setter() automatically sets the values from html into form bean .Reset() is used to change the values .validate() is used to for validation purpose
question 4’s answer appears to be incorrect.Action is not part of model.
this is from “complete reference on struts” book:
“Action classes provide the glue between the View and Model layers and are responsible for processing specific requests. Action classes are intended to transfer data from the View layer to a specific business process in the Model layer, and then to return data from the business process to the View layer. Business logic should not be embedded in actions, because that violates the principles of MVC.”
bean.reset() is called when a new request is obtained, then the old request values will be reset in the form fields, Validate() is used to check the validation of the input parameters, like number format, min length, max length , if it has any error the new Action Error object is created and added with ActionErrors Object, the framework automatically reroute reposnse to the error page as u given in the action mappings tags attribute of input=”Error.jsp” in struts-config.xml file.
In strut framework when we use reset() it means that the new requestwill come and the previous request is not in real manner.
The Validate() is used to check the validation of the input parameters, like number format, min length, max length , if any error is there, the new Action Error object is created and added with ActionErrors Object, the framework automatically reroute reposnse to the error page. The code is input=â€ÂError.jsp†in struts-config.xml file.
Interface contains 10 methods,if Class implents an inteface all methods will be excutes.Now question is I want to restrict one of the in iteface. It is possible if yes how?
I want delete my table in database,before going to delete the Database can u check weather any Primary key or fkey is there or not(use java code)
in interface contains 10 methods,i want restrict one method if i implement the class.is it possible pls explain
in ArrayList can i remove or insert the elements in reverse order(Collection)
When we will use Abstraction And Interface?
If user close the Browser wile Our log file displaying in command promt.It will closed our JSP file ?
Can u create new date using Java if yes how
Pls any one help me this question.
In EJB,Why the cleint can not communicate Dirctly in to EJBContaine?
In strut framework when we use reset() it means that the new requestwill come and the previous request is not in real manner.
The Validate() is used to check the validation of the input parameters, like number format, min length, max length , if any error is there, the new Action Error object is created and added with ActionErrors Object, the framework automatically reroute reposnse to the error page. The code is input=â€ÂError.jsp†in struts-config.xml file.
The answer of question number 4 is incorrect, the action class is not the part of the Model, It’s strongly coupled with ActionServlet i.e the Controller component of the Struts framework.
Infact the struts doesn’t have any inbuilt support for model component, the action class acts as helper to Controller component.
When we will use Abstraction And Interface?
An Abstract class is used as a Single inheritence but Interface supports the muliple inheritance in java.
An abstract class considers only the abstract methods which will become compulsary in the respective subclasses. But the interface methods must and should me implemented in the class that implements that interface.