Lesson 27JavaServer Pages
The JavaServer Pages (JSP) technology was created as a next step in servlet evolution. JSP 2.3 is part of the Java EE 7 specification, and with JSP you can do everything that you can do with servlets, but more easily. In early Java EE specifications JSP was the only standardized web framework. But starting from Java EE 4 yet another web framework was introduced: JavaServlet Faces (JSF). While JSF has more features than JSP, I still see a lot more enterprise applications that use JSP, so this edition of the book covers JSP but not JSF. Now let’s see why using servlets is not enough for developing of the presentation tier for all Java EE web applications.
Let’s say you’ve created and deployed a servlet, which displays “Hello World.” The servlet gets a hold of the output stream of the response object and executes the following line of code:
out.println("<html><body>Hello World </body></html>");
Now imagine that you run a software company that employs Alex, an expensive Java developer, and Matilda, a junior web designer who doesn’t know Java but does know HTML. What if you need to change the layout of this HTML page, such as by adding several empty lines on top? It’s not a big problem—Alex can modify the preceding line of code, recompile it, and redeploy the servlet. But for making small changes in the HTML-based user interface (UI) it’s more cost-efficient to use Matilda. This is where JSP becomes very handy. Ask Matilda to create the following text ...
Get Java Programming 24-Hour Trainer, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.