wood burning stoves 2.0*
The moose likes Struts and the fly likes execute method of Struts 1.3.9 Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "execute method of Struts 1.3.9 Action" Watch "execute method of Struts 1.3.9 Action" New topic
Author

execute method of Struts 1.3.9 Action

Niklas Rosencrantz
Ranch Hand

Joined: Apr 08, 2006
Posts: 49
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
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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 ]
Niklas Rosencrantz
Ranch Hand

Joined: Apr 08, 2006
Posts: 49
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.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
You are very welcome!
[ May 02, 2008: Message edited by: James Clark ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: execute method of Struts 1.3.9 Action
 
Similar Threads
how to pass the image from servlet to jsp
IllegalStateException error come on servlet side
Struts 1.3.9 Password Reminder Action class
Displaying images and thumbnails directly from database
Jstl not reflecting values back to servlet