- Home
- Interview Questions
- Struts
11.
Write code of any Action Class?
Here is the code of Action Class that returns the ActionForward object. package j2eeonline.jdj.com; 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"); } }
12.
What is an "Action Class"?
The "Action Class" is part of the "Model" and 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", we need to subclass and overwrite the execute() method.
All the database and business processing is done in the "Action" class.
It is advisable to perform all the database related work in the "Action" class.
The ActionServlet (command) passes the parameterized class to ActionForm 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 according to the value of the returned ActionForward object.
13.
How can one make any "Message Resources" definitions file available to the "Struts Framework" environment?
"Message Resources" definitions file are simple .properties files and
these files contain the messages that can be used in the struts project.
"Message Resources" definition files can be added to the struts-config.xml file
through <message-resources /> tag. Example:
<message-resources parameter="MessageResources" />
14.
What is an ActionServlet?
The class org.apache.struts.action.ActionServletis called the ActionServlet. In the Jakarta Struts Framework this class plays the role of controller. All the requests to the server go through the "Controller". The "Controller" is responsible for handling all the requests.
15.
What is the Jakarta Struts Framework?
Jakarta Struts is an open source implementation of MVC
(Model-View-Controller) pattern for the development of web based applications.
Jakarta Struts is a robust architecture and can be used for the development of applications of any size.
The "Struts framework" makes it easier to design scalable, reliable Web applications.