Servlets and Teams

   

Servlets and Teams

Servlets come in two shapes : the regular servlets, which inherit from classes in javax.servlet.http , and the newer Java Server Pages (JSP) located in the javax.servlet.jsp package.

However, regardless of their form, servlets suffer from mixing HTML and Java code. The following code sample illustrates the problem:

 protected void doGet(HttpServletRequest request,                        HttpServletResponse response)      throws IOException   {      Writer w = response.getWriter();      String string = request.getParameter("string");      w.write("<HTML><HEAD><TITLE>Upper Case</TITLE></HEAD>");      w.write("<BODY><P>" + string + " in uppercase is <B>");   w.write(string.toUpperCase());      w.write("</B></BODY></HTML>");      w.flush();   } 

This servlet is trivial, but it illustrates the mixing of Java and HTML code. The Java code implements the application logic and is the responsibility of engineers , whereas the HTML code deals with the look and feel of the application and is the responsibility of designers.

However, because of the mixing of Java and HTML, when the designer needs to change the look and feel, he must rely on the programmer. This causes much frustration because

  • Designers often complain that developers are too slow to integrate their changes.

  • Programmers would rather focus their energy on improving performance or adding new functions rather than on implementing so-called frivolous changes from designers.

In fact, the fundamental problem is that servlets, like CGI scripts and ASP, force a very close collaboration between two groups (designers and developers) who have different priorities. Understandably, designers are very concerned with presentation, while programmers concentrate on coding.

Note

JSP does not solve this problem; it merely switches it around. Instead of having HTML in the middle of Java code, JSP places Java code right in the middle of HTML. Although writing JSP is often faster than writing regular servlets, it does not solve the fundamental problem of mixing HTML and Java.


In short, it's the old rivalry between engineers and artistic persons. The situation is particularly difficult in Web design because Web teams are under enormous pressure to deliver quickly.

Creating an Interface

If you're reading this book, you are probably more like the Java programmers than the designers. In this chapter, you build a solution to cleanly separate your work (Java development) from the design work. The main goals are to

  • Separate HTML and Java coding in the servlet

  • Provide the designer with tools to modify the presentation without requiring the assistance of the programmer

  • Allow the programmer to concentrate on the application logic

The solution is close to what you did in Chapter 4, "Content Syndication." In that chapter, you relied on a presentation-neutral XML document and used XSLT style sheets to produce the HTML. One of the major differences between that and what you'll do in this chapter is that the XML document will be dynamically generated by the servlet in this chapter.

In other words, the programmer will generate presentation-neutral XML code, while the designer will use XSLT to render it in an aesthetically pleasing layout. This provides a clear-cut separation between the two groups that mimics the organization of the team.

Additional Benefits

Although the primary motivation to use XML was to improve the day-to-day working of the Web team, the technique outlined in this chapter is also very valuable in the following cases:

  • A Web site revamping occurs and all the pages, including the servlets, must adopt the new look. However, programmers are typically busy working on new applications.

  • An application is shared among different sites; each site has its own look and feel; and the servlet must support them all.

  • Multilingual sites exist. For example, I live in Belgium where many sites are multilingual. In practice, accommodating the differences is difficult ”French words are often longer than their English counterparts. This might force you to redesign the page to provide more room on the button bar.

   


Applied XML Solutions
Applied XML Solutions
ISBN: 0672320541
EAN: 2147483647
Year: 1999
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net