Personal notes on Java
For other technologies like HTML, CSS, .NET, PHP, etc. check my other blog

MVC


MVC

Notes [1]:
Why Combine Servlets & JSP?
- Typical picture: use JSP to make it easier to develop and maintain the HTML content
    - For simple dynamic code, call servlet code from scripting elements
    - For slightly more complex applications, use custom classes called from scripting elements
    - For moderately complex applications, use beans and custom tags
- But, that’s not enough
    - For complex processing, starting with JSP is awkward
    - Despite the ease of separating the real code into separate classes, beans, and custom tags, the assumption behind JSP is that a single page gives a single basic look


Possibilities for Handling a Single Request
Servlet only. Works well when:
    - Output is a binary type. E.g.: an image
    - There is no output. E.g.: you are doing forwarding or redirection as in Search Engine example.
    - Format/layout of page is highly variable. E.g.: portal.
JSP only. Works well when:
    - Output is mostly character data. E.g.: HTML
    - Format/layout mostly fixed.
Combination (MVC architecture). Needed when:
    - A single request will result in multiple substantially differentlooking results.
    - You have a large development team with different team members doing the Web development and the business logic.
    - You perform complicated data processing, but have a relatively fixed layout.


MVC Misconceptions
- An elaborate framework is necessary
    - Frameworks are often useful
- JSF (JavaServer Faces)
    - You should strongly consider JSF 2.0 for medium/large projects!
- Struts
    - They are not required!
- Implementing MVC with the builtin RequestDispatcher works very well for most simple and even moderately complex applications
- MVC totally changes your system design
    - You can use MVC for individual requests
    - Think of it as the MVC approach, not the MVC architecture (aka "Model 2 approach")


MVC-Based Alternative to Servlets and JSP: JSF 2
- Servlets and JSP
    - Well-established standard
    - Used by google.com, ebay.com, walmart.com, and thousands of other popular sites
    - Relatively low level by today’s standards
    - Covered in this tutorial
- JSF (JavaServer Faces) Version 2
    - Now an official part of Java EE 6
- But runs in any recent Java-enabled server, including Tomcat 6+
    - Higher-level features: integrated Ajax support, field validation, page templating, rich third-party component libraries, etc. Designed around the MVC approach.
    - Not yet as widely used, but recommended for many or most new projects
    - Covered at http://www.coreservlets.com/JSF-Tutorial/jsf2/

References:
[1] - The Model View Controller (MVC) Architecture: Integrating Servlets and JSP

Sem comentários:

Enviar um comentário