Monday, May 5, 2008

Java Server Pages

JavaServer Pages (JSP) is a Java technology that allows software developers to dynamically generate HTML, XML or other types of documents in response to a Web client request. The technology allows Java code and certain pre-defined actions to be embedded into static content.

Benefits for Developers.

  • Use JSP technology without having to learn the Java language.
  • Extend the JSP language: Java tag library developers and designers can extend the JSP language with "simple tag handlers," which utilize a new, much simpler and cleaner, tag extension API.
  • Easily write and maintain pages: The JavaServer Pages Standard Tag Library (JSTL) expression language is now integrated into JSP technology and has been upgraded to support functions.

Working and architecture of JSP

JSPs are compiled into Java Servlets by a JSP compiler. A JSP compiler may generate a servlet in Java code that is then compiled by the Java compiler, or it may generate byte code(class file that is generated after compilation) for the servlet directly. JSPs can also be interpreted on-the-fly reducing the time taken to reload changes.
1. A user visits a website made using JSP technology. The requests for a webpage are made by clicking on a link or by entering a URL address or by clicking a SUBMIT on a web user form.
2. The request is carried via HTTP GET or POST commands to the webserver, which is then passed to servlet container.
3. The servlet container then passes the request to the appropriate servlet generated after the compilation of the JSP into a servlet.
4. It is here the servlet container passes the objects of classes HttpServletRequest and HttpServletResponse as arguments to the methods of the servlet.
5. The servlet receive the request objects which contains packaged info like info about request URL, cookies, sessions and more useful info.
6. The servlets processes the request and generates the required html which is then passed via the HttpSerlvetResponse object, back to the serlvet container, then to the web server and then via the HTTP to the web browser of the user.

JSP syntax
A JavaServer Page may be broken down into the following pieces:

  • Static data such as HTML .
  • JSP directives such as the include directive .
  • JSP scripting elements and variables .
  • JSP actions .
  • Custom tags with correct library

No comments: