I am really new to Struts. I would like to know what is the best way to create and initialize classes that would be used across All Actions....
Since we are using struts for WEB, we already have api for checking entitlements of user, utility classes.
I would like to have only single instance of them created rather than creating in the methods as and when they are needed.
Please advice.
Thanks
Dimple
Discussions
Web tier: servlets, JSP, Web frameworks: Struts Quest:intializing and accessing classes used across actio
-
Struts Quest:intializing and accessing classes used across actio (4 messages)
- Posted by: Dimple Malhotra
- Posted on: January 05 2005 16:08 EST
Threaded Messages (4)
- Struts Quest:intializing and accessing classes used across actio by zqudlyba navis on January 06 2005 08:13 EST
- Struts Quest:intializing and accessing classes used across actio by Dimple Malhotra on January 06 2005 17:31 EST
- Struts Quest:intializing and accessing classes used across actio by Parag Desai on January 14 2005 00:58 EST
- Struts Quest:intializing and accessing classes used across actio by Kishore Senji on January 14 2005 02:20 EST
-
Struts Quest:intializing and accessing classes used across actio[ Go to top ]
- Posted by: zqudlyba navis
- Posted on: January 06 2005 08:13 EST
- in response to Dimple Malhotra
Hi Dimple,
You can put objects in a Session.
For example, in an Action class, this is how you would put an object in a Session:
public ActionForward execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
List nameList = new ArrayList();
nameList.add("Homer Simpson");
nameList.add("Bart Simpson");
HttpSession session = request.getSession(false);
session.setAttribute("ListOfNames", nameList)
}
This is how you would retrieve an object from the Session from an Action class futher downstream:
public ActionForward execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
HttpSession session = request.getSession(false);
List nameList = (ArrayList) session.getAttribute("ListOfNames");
} -
Struts Quest:intializing and accessing classes used across actio[ Go to top ]
- Posted by: Dimple Malhotra
- Posted on: January 06 2005 17:31 EST
- in response to zqudlyba navis
I am more looking at ways to intantiate during teh startup of the servlet and somehow use the reference of object in all Actions and Forms -
Struts Quest:intializing and accessing classes used across actio[ Go to top ]
- Posted by: Parag Desai
- Posted on: January 14 2005 00:58 EST
- in response to Dimple Malhotra
I think Static classes would serve your purpose. The values set into a static class in the servlet would reflect in any Action class that uses that static class. Hope this solves your problem.
-Parag -
Struts Quest:intializing and accessing classes used across actio[ Go to top ]
- Posted by: Kishore Senji
- Posted on: January 14 2005 02:20 EST
- in response to Dimple Malhotra
I am really new to Struts. I would like to know what is the best way to create and initialize classes that would be used across All Actions....Since we are using struts for WEB, we already have api for checking entitlements of user, utility classes. I would like to have only single instance of them created rather than creating in the methods as and when they are needed.Please advice.ThanksDimple
Implement a Plugin (http://struts.apache.org/api/org/apache/struts/action/PlugIn.html) and declare it in your <struts-config.xml>
In the init method of your Plugin; store (keep alive) your singleton model objects that you want to expose to the application