Java Reference
In-Depth Information
Strengths of servlets as Controllers are as follows:
Servlets have very robust server-side processing capabilities because they have access to
almost the entire Java SDK.
The servlet architecture lends itself well to a transactional style of programming, which
is analogous to MVC Controllers.
Weaknesses of servlets as Controllers are as follows:
Servlets require an advanced level of Java understanding that HTML programmers usu-
ally do not have.
Servlets generally require recompilation in order to change the client presentation layer.
If we consider the previous lists, we can determine that servlets make prime candidates for
MVC Controllers, where there will be fewer changes because the presentation logic has been
abstracted.
JSPs as MVC Views
JavaServer Pages were chosen as MVC Views after a similar examination of their strengths and
weaknesses.
Strengths of JSPs as Views are as follows:
JSPs do not require programmer recompilation after source changes.
JSPs allow you to access Java objects that are stored in the HTTP session.
JSPs allow you to embed Java code directly into HTML pages with scriptlets.
Weaknesses of JSPs as Views are as follows:
As your JSP code becomes more complicated, so does your scriptlet code. This results in
confusing and difficult-to-maintain JSPs.
If you plan to allow your HTML programmers to maintain your JSPs, which is very
common, they will require a good understanding of Java.
After examining the previous lists, we can determine that JSPs make great candidates for MVC
Views. This is because we can leverage a JSP's access to Java objects, while conquering one of
their major weaknesses by limiting scriptlet code to presentation only.
Summary
In this chapter, we laid the foundation for the rest of this text. We looked at the MVC design
pattern and saw how we could combine servlets and JSPs to implement a server-side solution
for Web applications.
Search WWH ::




Custom Search