Home arrow Java arrow Page 3 - J2EE Design Patterns: The Presentation Layer Patterns: Model-View-Controller
JAVA

J2EE Design Patterns: The Presentation Layer Patterns: Model-View-Controller


In any application, it is the presentation that matters most to the end user. The usability of software depends heavily on the User Interface or Presentation Layer in the case of J2EE. Since it is the Presentation Layer that presents the UI to the user, the solutions for recurring problems have to be standard. That is where Presentation Layer Design Patterns come into the picture.

Author Info:
By: A.P.Rajshekhar
Rating: 5 stars5 stars5 stars5 stars5 stars / 10
November 14, 2006
TABLE OF CONTENTS:
  1. · J2EE Design Patterns: The Presentation Layer Patterns: Model-View-Controller
  2. · MVC: the Types
  3. · MVC in the Real World
  4. · MVC in the Real World continued

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
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:

  1. subscribe.html -- provides the interface to enter user data.
  2. MailingBean.java -- a bean functioning as the Model.
  3. ListController.java -- the servlet that will be the Controller.
  4. 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(  );

}


blog comments powered by Disqus
JAVA ARTICLES

- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...
- Generics and Limitations in Java
- Getting Started with Java Web Development in...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials