JSP Tutorial

Extension to Servlet JSP is the extension to the servlet technology. We can use all the features of Servlet in JSP. In addition to, we can use implicit objects, predefined tags, expression language and Custom tags in JSP, that makes JSP development easy.
Easy to maintain JSP can be easily managed because we can easily separate our business logic with presentation logic. In servet, we mix our business logic with the presentation logic.
Fast Development If JSP page is modified, we don't need to redeploy the project. The servlet code needs to be updated and recompiled if we have to change the look and feel of the application.

2.JSP LifeCycle
JSP files internally converts to servlet while exceution. JSP Engine converts JSP to Servlet, by following lifecycle methods

4.Tags in JSP

  1. Scripting Elements scriptlet tag, expression tag, declaration tag
  2. Directives page directive, include directive, taglib directive
The jsp directives are messages that tells the web container how to translate a JSP page into the corresponding servlet.
  1. Standard actions → . Each tag is used to perform some specific tasks. The action tags basically are used to control  the flow between pages and to use Java Bean -

  • The include directive includes the original content, so the actual page size grows at runtime.

Java Bean:    It should have a no-arg constructor.
                       It should be Serializable.
        It should provide methods to set and get the values of the properties, known as getter and setter methods.
There are two ways to provide values to the object, one way is by constructor and second is by setter method.
5.JSP Action Tags (Action Elements)

6.Jsp EL : The JSP Expression Language (EL) simplifies the accessibility of data stored  objects like request, session, application etc.
   Sysntax :  ${expression}                             ex:${param.name}

7. JSTL (JSP Standard Tag Library)
The JSP Standard Tag Library (JSTL) represents a set of tags to simplify the JSP development. There JSTL mainly provides 5 types of tags:

  1.core tags: The JSTL core tag provide variable support, URL management, flow control etc. The url for the core tag is http://java.sun.com/jsp/jstl/core . The prefix of core tag is c.
  2.sql tags: The JSTL sql tags provide SQL support. The url for the sql tags is http://java.sun.com/jsp/jstl/sql and prefix is sql.
  3.xml tags: The xml sql tags provide flow control, transformation etc. The url for the xml tags is http://java.sun.com/jsp/jstl/xml and prefix is x.
  4.internationalization tags: The internationalization tags provide support for message formatting, number and date formatting etc. The url for the internationalization tags is http://java.sun.com/jsp/jstl/fmt and prefix is fmt.
  5.functions tags: The functions tags provide support for string manipulation and string length. The url for the functions tags is http://java.sun.com/jsp/jstl/functions and prefix is fn.

8JSP Custom Tag API

The javax.servlet.jsp.tagext package contains classes and interfaces for JSP custom tag API. The JspTag is the root interface in the Custom Tag hierarchy.

Tag Interface
public static int EVAL_BODY_INCLUDE
public static int EVAL_PAGE
public static int SKIP_BODY
public static int SKIP_PAGE

For creating any custom tag, we need to follow following steps:
   1.Create the Tag handler class , by extending TagSupport class and overide doStartTag()
   2.Create the Tag Library Descriptor (TLD) file and define tags
   3.Create the JSP file that uses the Custom tag defined in the TLD file