Developing JSP pages is different from developing servlets when the content of the response is generated. With servlets, developers must embed HTML code into Java code, and they use methods of either the ServletOutputStream, or PrintWriter objects to do this. However, JSP development requires an approach that is focused more on presentation and document – that is, you embed portions of Java code in the HTML code that defines the presentation layout of the page. The Java Server PagesÔ 1.2 Specification defines special syntax elements that developers can use to embed their Java code in the JSP page. These syntax elements are:
· Scripting elements
Furthermore, the specification defines a set of variables that are implicitly available to use in the JSP expressions or scriptlets (that is, you can use these variables directly without declaring them first). The implicit variables represent some of the most important and frequently-used objects in servlet development. Read more about the implicit variables in Implicit Variables.
JSP pages are not different to servlets. You can program the same functions in a JSP as you can in servlets – you simply use a different syntax. Furthermore, JSP pages are translated into a servlet-like implementation class by the Web Container they are deployed in. All other phases of the life cycle of a JSP page are the same as those of a servlet – the class is instantiated and initialized, then it serves requests, and is finally destroyed by the Web Container.
The JSP syntax elements with their attributes and the JSP implicit object variables have their equivalents in servlets as objects and methods that are part of the Java Servlet 2.3 API. The J2EE Engine’s Web Container parses the JSP syntax elements at JSP translation phase and generates the servlet implementation class that is actually used to process client requests. You can read more about the semantics of the different JSP syntax elements in the following topics.