Top 1. 0 Struts Interview Question And Answer. This time its Struts interview questions, After writing Spring interview questions few weeks back I was thinking what to pick for my interview series and than I thought about any web framework, and on that struts is my favorite. Struts are open source framework used for web application.
- Top 50 Struts Interview Questions. Download PDF. Q1. What are the components of Struts Framework? Ans: Struts framework is comprised of following components.
- Struts Interview Questions And Answers Pdf This is probably the most asked question in struts2 interview. What are Interview questions and answers – free pdf.
- . I am listing down some of the important Struts2 interview questions with answers to help you in interview. struts 2 struts2 interview questions. Written by.
These Struts interview questions are based on my experience as well as collected by friends and colleague and they are not only good for interview practice but also shows a new direction of learning for any one who is not very familiar with struts. Best way to use these interview questions is do revise before going for any Struts interview or any Java or J2. EE interview. I have also provided answers of these struts interview questions but you can also research more on Google but these answers of struts are sufficient on interview perspective. Question 1: What is Struts?
Struts2 Interview Questions And Answers Pdf Download PDF Ans: Following Steps are required for Struts1 to Struts2 migration: Move Struts1 actionForm to Struts2 POJO. Mohammad Makhanawala Page 1 Struts interview questions 1.What is MVC? Model-View-Controller (MVC) is a design pattern put together to help control change.
Why you have used struts in your application or project. Now why we use Struts?
So main reason is if we go with servlet all HTML code which is related with design part mostly will come inside java code which makes code unmaintainable and complex similarly if use JSP, all java code related with business come inside design part which again make code complex, that’s why MVC pattern come into existence and which separate the business, design and controller and struts was made based upon this pattern and easy to develop web application. The keyword to answer this Struts interview questions is MVC design pattern, Front Controller Pattern and better flow management which mostly interviewer are looking to hear. You can read more design pattern interview question on my post 1. Interview question on Singleton Pattern in Java.
Question 2: What are the main classes which are used in struts application? Ans 2: This is another beginner’s level Struts interview question which is used to check how familiar candidate is with Struts framework and API. Main classes in Struts Framework are: Action servlet: it’s a back- bone of web application it’s a controller class responsible for handling the entire request. Action class: using Action classes all the business logic is developed us call model of the application also. Action Form: it’s a java bean which represents our forms and associated with action mapping.
And it also maintains the session state its object is automatically populated on the server side with data entered from a form on the client side. Action Mapping: using this class we do the mapping between object and Action. Action. Forward: this class in Struts is used to forward the result from controller to destination. Question 3: How exceptions are handled in Struts application?
Ans: This is little tough Struts interview question though looks quite basic not every candidate knows about it. Below is my answer of this interview questions on Struts: There are two ways of handling exception in Struts: Programmatically handling: using try {} catch block in code where exception can come and flow of code is also decided by programmer . Declarative handling: There are two ways again either we define < global- Exception> tag inside struts config. Base. error. invalid.
Currency. Type" path="/Availble. Currency. jsp" type="Stock. Currency. Type. Exception"> < /exception> Programmatic and Declarative way is some time also asked as followup questions given candidate’s response on knowledge on Struts. Key: The key represent the key present in Message. Resource. properties file to describe the exception.
Type: The class of the exception occurred. Path: The page where the controls are to be followed is case exception occurred. Question 4: How validation is performed in struts application?
Ans: Another classic Struts interview question it’s higher on level than previous interview questions because it’s related to important validation concept on web application. In struts validation is performed using validator framework, Validator Framework in Struts consist of two XML configuration files. You can add new validation rules by adding an entry in this file. This was the original beauty of struts which makes it highly configurable. Validation. xml files which contain details regarding the validation routines that are applied to the different Form Beans. These two configuration file in Struts should be place somewhere inside the /WEB- INF folder of the application to keep it safe from client and make it available in Classpath.< !- - Validator plugin - -> < plug- in class. Name="org. apache.
Validator. Plug. In"> < set- propertyproperty="pathnames"value="/WEB- INF/validator- rules. WEB- INF/validation. Now the next step towards validation is create error messages inside the message resource property file which is used by validator framework. Message resource Contain: 1. Currency. Converter. Form. from. Currency = From Currency.
Currency. Converter. Form. to. Currency=To currency. Then validation rules are defined in validation.
Form bean code that extend Dyna. Validator. Form. Eg; < form- beans> < form- bean name="Currency. Converter. Form" type="org. Dyna. Validator. Form"> < form- property name="from.
Currency" type="java. Currecny" type="java. Validation. xml file contains< form- validation> < formset> < form name=" Currency. Converter. Form "> < field property=" from. Currency " depends="required"> < arg key=" Currency. Converter. Form. from. Currency "/> < /field> < field property=" to.
Currecny " depends="required "> < arg key=" Currency. Converter. Form. to. Currency "/> < /field> < /form> < /formset> < /form- validation> To associate more than one validation rule to the property we can specify a comma- delimited list of values. The first rule in the list will be checked first and then the next rule and so on. Answer of this Struts questions gets bit longer but it’s important to touch these important concept to make it useful. Top 1. 0 Interview Questions asked in Struts. Question 5: What is the Difference between Dispatch.
Action and Lookup. Dispatch. Action in Struts Framework? This Struts interview questions is pretty straight forward and I have put the differences in tabular format to make it easy to read. Dispatch Action. Lookup. Dispatch. Action.
It’s a parent class of Lookup. Dispatch. Action. Subclass of Dispatch Action. Dispatch. Action provides a mechanism for grouping a set of related functions into a single action, thus eliminating the need to create separate actions for each function. An abstract Action that dispatches to the subclass mapped executes 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 Action. Mapping. If not using Internalization functionality then dispatch action is more useful.
Lookup Dispatch Action is useful when we are using Internalization functionality. Dispatch. Action selects the method to execute depending on the request parameter value which is configured in the xml file. Dispatch. Action is not useful for I1. NLookup. Dispatch. Action is used for I1. N Question 6: How you can retrieve the value which is set in the JSP Page in case of Dyna.
Action. Form? Ans: Dyna. Action. Form is a popular topic in Struts interview questions. Dyna. Action. Form is subclass of Action. Form that allows the creation of form beans with dynamic sets of properties, without requiring the developer to create a Java class for each type of form bean. Dyna. Action. Form eliminates the need of Form. Bean class and now the form bean definition can be written into the struts- config. So, it makes the Form.
Bean declarative and this helps the programmer to reduce the development time. For Example: we have a Currency. Converter. Form and we don't want a java class. Currency. Converter. Form has properties from. Currency, to. Currencyin the struts- config. Currency. Converter.
Form " type="org. Dyna. Action. Form"> < form- property name=" from. Currency " type="java. String"/> < form- property name=" to.
Currency " type="java. String "/> < /form- bean> Add action mapping in the struts- config. Currency" type="com.
Convert. Currency. Action" name=" Currency. Converter. Form " scope="request" validate="true" input="/pages/ currency. Converterform. jsp"> < forward name="success" path="/jsp/success. In the Action class. Convert. Currency. Action extends Action { public Action.
Forward execute( Action. Mapping mapping, Action. Form form, Http. Servlet. Request request, Http. Servlet. Response response) throws Exception{ Dyna. Action. Form currency. Converter. Form = (Dyna.
Action. Form)form; // by this way we can retrieve the value which is set in the JSP Page String from. Currency = (String) currency. Converter. Form. get("from. Currency "); String to. Currency = (String) currency. Converter. Form. get("to.
Currency "); return mapping. Forward("success"); } } } In the JSP page < html: text property=" from. Currency " size="3.
Currency " size="3. Question 7: what the Validate () and reset () method does? Ans: This is one of my personal favorite Struts interview questions.
Used to validate properties after they have been populated, and this ,method is Called before Form. Bean is passed to Action.
Returns a collection of Action. Error as Action. Errors. Following is the method signature for the validate() method.
Action. Errors validate(Action. Mapping mapping, Http. Servlet. Request request) { Action.
Errors errors = new Action. Errors(); if ( String. Utils. is. Null. Or. Empty(username) & & String. Utils. is. Null. Or. Empty(password)){ errors. Action. Errors. GLOBAL_ERROR, new Action.
Error("error. usernamepassword. Struts Framework with each request that uses the defined Action. Form. The purpose of this method is to reset all of the Action. Form's data members prior to the new request values being set. Example : public void reset(Action. Mapping mapping, Http.