Saturday, May 18, 2024
HomeJavaWhat's Struts Motion Class in Java J2EE - How you can use

What’s Struts Motion Class in Java J2EE – How you can use


What’s Motion class in Struts

Struts in java is a framework, used to make internet software its is predicated on Mannequin View Controller or MVC design Sample the place Mannequin characterize the inner state and motion used to alter the state view characterize presentation element and a controller is chargeable for receiving the request from the shopper and determine which enterprise logic needs to be referred to as. Mainly, Struts have completely different courses to characterize this Mannequin, View, and Controller we name them as Motion, Motion Kind, and Motion Servlet. So

Mannequin – Motion courses

View – Motion kind courses

Controller – Motion Servlet courses

On this article, we’re specializing in the Mannequin layer of struts framework. Motion class is used to supply an interface to software mannequin layer.  What’s Motion class and how you can use Motion class can also be a well-liked Struts interview Query requested in varied J2EE interviews.

What’s Motion Class in Struts ?

What is Action Class in Struts How to useMotion Class in Struts framework is used to outline the enterprise logic it handles the shopper request put together the response or inform the place the response needs to be ahead, mainly its obtain the information from the view layer and ahead that knowledge to particular enterprise layer or course of the information and once more ahead the processed knowledge to view layer.

For instance, Motion class can create a library object add books to that library object, it could actually retailer chosen books by a selected reader to the session.

In short, we will describe Motion as:

Ø       Our Motion class is prolonged by “org.apache.struts.motion.Motion class.

Ø       We have to override execute() methodology of Motion class.

Ø       Motion servlet choose Motion class for incoming HTTP Request outlined beneath the motion mapping tag in struts-config.xml file

Ø       Motion class is used to invoke enterprise or knowledge entry logic get knowledge from bean and retailer processed knowledge to bean and return end result or errors relying on the state of affairs,

Ø       Motion courses are multi-threaded so we have to fastidiously deal with the motion variable as they don’t seem to be thread-safe when working with the multi-threaded atmosphere.

How you can Use Motion Class

In easy steps, we are going to see how you can use Motion class.

1.       First prolong the org.apache.struts.motion.Motion class.

2.       Override the next methodology 

           public ActionForward execute(ActionMapping mapping,

                    ActionForm kind,

                    HttpServletRequest request,

                    HttpServletResponse response) throws IOException, ServletException

Right here we develop our enterprise logic and put together the response to return the shopper.

  3.Then we configure this motion to struts config file of our software inside motion mapping :

<action-mappings>

<motion

      path=”/TestAction”

      sort=”Instance.TestAction”>

      <ahead identify=”success” path=”/ExamplePages/TestAction.jsp”/>

   </motion>  

</action-mappings>

That is all concerning the motion class in subsequent article will take care of completely different sort of motion class supplied by  struts framework.

Different Java article from Java67 Weblog

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments