• +91 9723535972
  • info@interviewmaterial.com

Struts Interview Questions and Answers

Question - How can I 'chain' Actions?

Answer - Chaining actions can be done by simply using the proper mapping in your forward entries in the struts-config.xml file. Assume you had the following two classes: /* com/AAction.java */ ... public class AAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Do something return mapping.findForward("success"); } }   /* com/BAction.java */ ... public class BAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Do something else return mapping.findForward("success"); } } Then you can chain together these two actions with the Struts configuration as shown in the following excerpt: ... ... Here we are assuming you are using a suffix-based (.do) servlet mapping, which is recommended since module support requires it. When you send your browser to the web application and name the action x.do (i.e. http://localhost:8080/app/x.do) it will execute AAction.execute(), which will then forward to the "success" mapping. This causes the execution of BAction.execute() since the entry for "success" in the configuration file uses the .do suffix. Of course it is also possible to chain actions programmatically, but the power and ease of being able to "reroute" your web application's structure using the XML configuration file is much easier to maintain. A

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners