Monday, 25 November 2013

ActionMapping Usage in Struts

 The ActionServlet needs some mechanism to determine how to route requests to Action classes. This is done using an ActionMapping class. 

The
 ActionMapping represents the information that the ActionServlet knows about the mapping of a particular request to an
instance of a particular
 Action class. 

The
 mapping is passed to the execute() method of the Action class, enabling access to this information directly. 

Example :
 Action Mappings are defined in the struts−config.xml file is
Code:
<action−mappings>
<action path="/search"
type="cdmanager.actions.SearchAction"
name="searchForm"
scope="request"
input="/search.jsp">
<forward name="success" path="/display.jsp"/>
</action>
</action−mappings>

The path property is the request URI path used to select this mapping. If extension mapping is used for the Controller Servlet, the extension will be stripped before comparisons against this value are made.

The
 type property specifies the fully qualified Java class name of the Action implementation used by this mapping.

The
 name property specifies the name of the Form Bean if there is one associated with this Action.

The
 scope property identifies the scope that can be Requested or the Session that the Form Bean (if there was one specified) creates. 

The
 input property is the Context-relative path of the input form to which control should be returned if a validation error is encountered. For example, this property is used if we have an
input form
 that uses validation and one of the required fields is missing. The Controller needs to know what to do when such a validation error occurs and is returned from theActionForm. The input property tells the Controller where to proceed next.

The
 forward property provides Action-local names of logical ActionForward instances that can be returned by the Action to control what does the actual presentation. The action is still called. 

Note :
 It is possible to specify multiple forward declarations for each action.

2 comments:

  1. Thanks a lot! You made a new blog entry to answer my question; I really appreciate your time and effort.
    best java institute in chennai |
    Core java training in chennai

    ReplyDelete
  2. Luxury Living Room Interior Designers in Hyderabad who craft exquisite and functional living spaces. Our designs blend premium furniture, elegant décor, ambient lighting, and modern layouts to create a stylish, comfortable, and inviting living room, perfect for entertaining guests or relaxing with family.

    ReplyDelete