Java Server Pages
Home ] Up ] Introduction ] Exceptions ] I/O, Files, and Streams ] Serialization ] Reflection ] Threads ] Swing and Threads ] Networking ] RMI ] JDBC ] Java Beans ] Servlets ] [ Java Server Pages ] Java and XML ]


What's  a Java Server Page?
How Does a JSP Work?
Do JSPs Replace Servlets?
JSP Expressions vs. Scriplets
Conditional JSPs
JSP Declarations
A JSP Hit Counter


As you've already seen, Java Servlets are Java classes which typically contain many print statements to output HTML (or other) content.  In other words, the HTML is embedded inside the servlet's Java code.

It is not uncommon to have more HTML than Java code.  This is a problem for a number of reasons:

  • You often have different developers involved in HTML vs. Java code.  HTML experts often know little to nothing about Java, and vice versa.  Often, the HTML experts are graphic designers, who know how to make a web site look attractive.  Java experts know code, but are often more look-and-feel challenged.
  • There are different sets of tools for HTML development vs. Java development. Embedding HTML inside Java precludes using these (often very good, and time-saving) HTML tools, such as Dreamweaver, etc.
  • In a large project, you need to be able to separate out the work in order to feed it to the appropriate person/group.  Embedding HTML in Java doesn't help with this.
  • It's very important to separate form from function.  A web application's look and feel (as reflected in a web site) should have little or no effect on how it is implemented behind the scenes.  Web sites' look and feel are often changed;  such changes should have minimal impact on the implementation.

As a result, Java Server Pages (JSPs) were invented.

With JSPs, we reverse the situation:

  • We embed Java code inside an HTML page.

For similar reasons to the above, however, we don't want to place a lot of Java code inside an HTML page.  That also makes things hard to manage.

The page was last updated February 19, 2008