JPETSTORE analysis of Spring Spring (2)

xiaoxiao2021-03-06  14

Spring with JPETSTORE Struts MVC

Used multi-level inheritance systems, with baseAction, SecureBaseAction, baseActionform. These parent classes have made some common functions, and there is still a reference value to write the actual procedure.

=== BaseAction ===

Inherit org.apache.struts.action.action, in fact org.apache.struts.Action.dispatchaction may be more functional. All Action has inherited this class.

Private petstore

Save this Business Object in all Action, encapsulate all data access methods

Overloaded this method:

Public Void SetServlet (ActionServlet ActionServlet)

Struts automatically performs this method when creating an Action instance. This method obtains the implementation of the PetStoreFacade interface via Spring

Increase this method

protected petstorefacade getpetstore ()

Returns the PetStore object, only if you have access to this method

=== SecureBaseAction ===

This class is used to protect the operation that needs to be logged in.

In the Execute method:

Check the Accountform object in Session, if (AccTform == Null || acctform.getAccount () == null), does not exist or not logged in, save the current address, jump to the login page]

A abstract method is defined instead of the Execute method used in this class.

Protected Abstract ActionForward Doexecute

=== baseActionform ===

This class provides a commonly used Form verification framework, and you can implement the authentication part in the subclass.

Request.setttribute ("ERRORS", ERRORLIST); Save the verification to the Request.

Here is also an error handling of Struts, ActionerRors.Add (ActionerRors.global_ERROR, New ActionError ("Global.Error");

This will not be used in the new Struts version, use ActionMessages. The page can be displayed directly with Struts taglib, but it seems that the error is not stored in ActionerRORS, but only uses a traditional way to handle errors, and there is no use of Struts error handling mechanism.

Display errors in IncludDETOP.JSP.

This class also provides a general method:

Protected Void AdderrorifstrINGempty (List Errors, String Message, String Value);

Check if the value is empty, if the space will join the Message in the list of Errors.

转载请注明原文地址:https://www.9cbs.com/read-50624.html

New Post(0)