J2EE Design Patterns: The Presentation Layer Patterns: Model-View-Controller - MVC in the Real World
(Page 3 of 4 )
The application to be developed will have the following features:
- First the user enters his or her first name, last name, and email address into a form which will be added to the list and reports whether the submission was successful.
- If the submission was successful, the success page will be shown, or else the user will be redirected to the first page.
The following are the files that will be used:
- subscribe.html -- provides the interface to enter user data.
- MailingBean.java -- a bean functioning as the Model.
- ListController.java -- the servlet that will be the Controller.
- redirect.jsp -- the View component that contains a part of the Controller logic.
So first comes subscribe.html. It's a simple HTML file. It calls the Controller servlet.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<HTML>
<HEAD>
<TITLE>Subscribe!</TITLE>
</HEAD>
<BODY>
<FORM action="/servlets/ListController" method="get">
First Name: <INPUT type="text" name="first"> <br>
Last Name: <INPUT type="text" name="last"> <br>
Email Address: <INPUT type="text" name="email"> <br>
<INPUT type="submit" name="Subscribe!">
</FORM>
</BODY>
</HTML>
Next is the Model. Since Models will be discussed in detail in coming parts, the actual implementation is left out for the present. It is an interface. Why it has been kept as an interface and how to implement it will be discussed in the future. It uses getters to retrieve the value and setters to place the value within the bean.
public interface MailingBean {
// first name
public String getFirst( );
public void setFirst(String first);
// last name
public String getLast( );
public void setLast(String last);
// email address
public String getEmail( );
public void setEmail(String email);
// business method
public boolean doSubscribe( );
// subscription result
public String getErrorString( );
}
Next: MVC in the Real World continued >>
More Java Articles
More By A.P.Rajshekhar