Jpetstore analysis of Spring self-band (II.)

Source: Internet
Author: User
Tags abstract error handling
The Jpetstore struts MVC version of Spring Band
The use of multi-level inheritance system, there are baseaction,securebaseaction,baseactionform. These parent classes encapsulate commonly used functions and can be useful for writing actual programs.
===baseaction===
Inherited org.apache.struts.action.Action, in fact, org.apache.struts.action.DispatchAction may be more powerful. All the action inherits this class.
Private Petstore
Save this business object in all the action, encapsulating all the methods of data access
Overloaded with this method:
public void Setservlet (Actionservlet actionservlet)
Struts automatically executes this method when creating an action instance. This method obtains the implementation of the Petstorefacade interface through spring
This method is added.
Protected Petstorefacade Getpetstore ()
Returns the Petstore object, only the sort that can access this method
===securebaseaction===
This class is used to protect actions that need to be logged in to perform.
In the Execute method:
Check the Accountform object in session, if (Acctform = null | | | acctform.getaccount () = null), nonexistent or not logged in, save current address, jump to login page]
Defines an abstract method that replaces the Execute method used by this class.
Protected abstract Actionforward Doexecute
===baseactionform===
This class provides a common framework for form validation, as long as the validation section is implemented in subclasses.
Request.setattribute ("Errors", errorlist), and save the validated results to the request.
The error handling of struts is also provided here, Actionerrors.add (Actionerrors.global_error, New Actionerror ("Global.error"));
This will not work in the new Struts version, with Actionmessages. The page can display the error directly with struts taglib, but there seems to be no deposit of errors in the actionerrors, only the traditional way to handle the error, there is no use of struts error handling mechanism.
An error is displayed in the includetop.jsp.
This class also provides a common method:
protected void Adderrorifstringempty (List errors, String message, string value);
Check that the value is empty, and if the null person adds the message to the Errors list.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.