MEMENTO Note Score Definition: MEMENTO is an object that saves another object's internal status copy. This object can be restored to the originally saved state.
MEMENTO mode is relatively good, let's see the following code:
public class Originator {private int number; private File file = null; public Originator () {} // Create a Memento public Memento getMemento () {return new Memento (this);} // return to the original value public void setMemento (Memento m) {Number = m.Number; file = m.file;}}
Let's take a look at the MEMENTO class:
Private class meteo imports java.io.serializable {private int number; private file file = null; public memento (Originator O) {Number = O.Number; File = O.File;}}
It can be seen that the value of Number and File in Originator is saved in Memento. By calling the setMemento () method by calling the Number and File values in the originator, it can be recovered by calling the setmemento () method.
The shortcoming of Memento mode is that it costs, if there are many internal status, then save one, there is no intention to waste a lot of memory.
MEMENTO mode In JSP JavaBean, in JSP applications, we usually have a lot of forms that require user input, such as user registration, you need to enter your name and email, if some item users have not filled or fill in errors, we hope to press in the user After "Submit Submit", through the JSP program check, it is found that there is no fill in the project, then the red word is displayed under the project, and the user has just entered the entered entry.
The first name is the user has entered, and the Last Name is not input, and we prompt the red word warning.
The implementation of this technology is to use the JavaBean scope = "request" or scope = "session" feature, which is MEMENTO mode.
Specific examples and code See JavaWorld's English original, the JavaBean form input feature See my other article.