More About Model-View-Controller Architecture : Struts Interview Questions
More About Model-View-Controller Architecture : Struts Interview Questions
Page 1 of 2
« Previous | 1 2 3 | Next »
1. What is MVC?
add to:
Model-View-Controller (MVC) is a design pattern put together to help control change. MVC decouples interface from business logic and data. Del.icio.us
Slashdot
Y! MyWeb
Model : The model contains the core of the application's functionality. The model encapsulates the state of the application. Sometimes the only Digg
Blink
Spurl
functionality it contains is state. It knows nothing about the view or controller. Furl
View: The view provides the presentation of the model. It is the look of the application. The view can access the model getters, but it has no
knowledge of the setters. In addition, it knows nothing about the controller. The view should be notified when changes to the model occur.
Controller:The controller reacts to the user input. It creates and sets the model.
6. What is ActionServlet?
ActionServlet is a simple servlet which is the backbone of all Struts applications. It is the main Controller component that handles client requests and determines which Action
will process each received request. It serves as an Action factory – creating specific Action classes based on user’s request.
reset(): reset() method is called by Struts Framework with each request that uses the defined ActionForm. The purpose of this method is to reset all of the ActionForm's data
members prior to the new request values being set.
<action-mappings>
<action path="/submit"
type="submit.SubmitAction"
name="submitForm"
input="/submit.jsp"
scope="request"
validate="true">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/error.jsp"/>
</action>
</action-mappings>
http://www.developersbook.com/struts/interview-questions/struts-interview-questions-f... 8/12/2010
Struts Interview Questions Struts FAQs JSF Interview Questions Spring Hibernate Int... Page 2 of 2
request.
http://www.developersbook.com/struts/interview-questions/struts-interview-questions-f... 8/12/2010
Struts Interview Questions Struts FAQs JSF Interview Questions Spring Hibernate Intervi... Page 1 of 3
16. Can we have more than one struts-config.xml file for a single Struts application?
Yes, we can have more than one struts-config.xml for a single Struts application. They can be configured as follows:
<servlet>
<servlet-name>action</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-admin.xml,
/WEB-INF/struts-config-forms.xml
</param-value>
</init-param>
.....
<servlet>
18. What is the difference between session scope and request scope when saving formbean ?
when the scope is request,the values of formbean would be available for the current request.
when the scope is session,the values of formbean would be available throughout the session.
http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs... 8/12/2010
Struts Interview Questions Struts FAQs JSF Interview Questions Spring Hibernate Intervi... Page 2 of 3
DispatchAction Example »
http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs... 8/12/2010
Struts Interview Questions Struts FAQs JSF Interview Questions Spring Hibernate Intervi... Page 3 of 3
28. What is difference between LookupDispatchAction and DispatchAction? People who read this, also read:-
The difference between LookupDispatchAction and DispatchAction is that the actual method that gets
called in LookupDispatchAction is based on a lookup of a key value instead of specifying the method
JSP Interview Questions
name directly.
JSF Standard Components
UML Certification
29. What is SwitchAction? JSF Integration with Spring Framework
The SwitchAction class provides a means to switch from a resource in one module to another resource JDBC Interview Questions
in a different module. SwitchAction is useful only if you have multiple modules in your Struts
application. The SwitchAction class can be used as is, without extending.
30. What if <action> element has <forward> declaration with same name as global forward?
In this case the global forward is not used. Instead the <action> element’s <forward> takes precendence.
http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs... 8/12/2010
Struts Interview Questions Struts FAQs JSF Interview Questions Spring Hibernate Intervi... Page 1 of 2
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;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
public class DynaActionFormExample extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaActionForm loginForm = (DynaActionForm) form;
ActionMessages errors = new ActionMessages();
if (((String) loginForm.get("userName")).equals("")) {
errors.add("userName", new ActionMessage(
"error.userName.required"));
}
if (((String) loginForm.get("password")).equals("")) {
errors.add("password", new ActionMessage(
"error.password.required"));
}
...........
<table border=1>
<logic:iterate id="customer" name="customers">
<tr>
<td><bean:write name="customer" property="firstName"/></td>
<td><bean:write name="customer" property="lastName"/></td>
<td><bean:write name="customer" property="address"/></td>
</tr>
</logic:iterate>
</table>
http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs... 8/12/2010
Struts Interview Questions Struts FAQs JSF Interview Questions Spring Hibernate Intervi... Page 2 of 2
<bean:write>: is used to retrieve and print the value of the bean property. <bean:write> has no body.
<bean:write name="customer" property="firstName"/>
Declarative exception handling :You can either define <global-exceptions> handling tags in your struts-config.xml or define the exception handling tags within
<action></action> tag. It works well when custom page needed when error occurs. This approach applies only to exceptions thrown by Actions.
<global-exceptions>
<exception key="some.key"
type="java.lang.NullPointerException"
path="/WEB-INF/errors/null.jsp"/>
</global-exceptions>
or
<exception key="some.key"
type="package.SomeException"
path="/WEB-INF/somepage.jsp"/>
http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs... 8/12/2010