What is JavaServer Pages?
Java Server Page.
- JavaServer Pages (JSP) is a technology for developing Webpages that supports dynamic content. This helps developers insert java code in HTML pages by making use of special JSP tags, most of which start with <% and end with %>
- The JSP engine loads the JSP page from disk and converts it into a servlet content. This conversion is very simple in which all template text is converted to println( ) statements and all JSP elements are converted to Java code. This code implements the corresponding dynamic behavior of the page. .
JSP Life Cycle
JSP can have Life Cycle
- Translation of JSP page.
- Compilation of JSP page(Compilation of JSP page into _jsp.java).
- Classloading(_jsp.java is converted to class file _jsp.class).
- Instantiation(Object of generated servlet is created).
- Initialisation(_jspinit() method is invoked by container).
- Request Processing(_jspservice() method is invoked by the container).
- Destroy(_jspDestroy() method invoked by the container)
Simple JSP example
<html> <body> <form> <% String name=request.getParameter("uname"); out.print("welcome "+name); %> <input type="text" name="uname"/> <input type="submit"> </form> Today's date: <%= (new java.util.Date()).toLocaleString() %>