I build a classified ads web project with a listing generated by a Struts 1.3.9 Action which "works" but needs cleaning:
I just modified this from Servlet to Action. Would you propose I also change the simpler case of viewing one single object also from a Servlet to an Action, or should I keep it a Servlet? Thank you Niklas Rosencrantz
There sure is a lot of code in this one method. What "action" of the application is this method supposed to be implementing?
The method, as written, is not very object-oriented.
The purpose of the Action class (which is part of the Controller servlet) is to delegate to the business layer. Ideally, you should have/require very little code in the execute method. Also, you should avoid using the HttpSession as a storage bin. Below, there is a ContainerCache, and only the cache object reference is stored in the HttpSession. All other data and collections are stored in the cache, e.g BusinessDelegate
Below is an example of an execute method for logging into an application. All of the code for getting to the Session EJB, querying the database and validating an encrypted password is in the business tier, not the Struts action class.
[ May 01, 2008: Message edited by: James Clark ]
Joined: Apr 08, 2006
Thank you. I understand. I want the code to be clean and it needs cleaning. What is does is generate a list of object in a JSP page. You can see the program work at this web page. I'll try not to use the session object and will refactor the method, maybe take out the parts that work with XML reading and randomly selecting a news item from an XML file.
Joined: Apr 16, 2008
You are very welcome! [ May 02, 2008: Message edited by: James Clark ]