JSP (Java Server Pages):
JSP refers to the Java server pages. Before starting the discussion on JSP let us discuss some problems of servlet.
Problems in servlet:
- In servlet presentation logic and dynamic content generation logic are intermixed which results in maintain problems.
- Whenever the presentation is changed servlet needs to be compiled and deployed again.
- A developer needs to write HTML code to the output stream of the servlet.
JSP:
JSP is the extension of the servlet that provides the solution to all the above problems. JSP defines a structure which is Java code inside HTML code. This structure simplifies web development.
Javax.servlet.jsp package.
Javax.servlet.jsp and its sub-packages provide the classes and interfaces that facilitate the development of JSP.
Interfaces in Javax.servlet.jsp package.
- JspPage.
- HttpJspPage.
Classes in Javax.servlet.jsp package.
- JspFactory.
- PageContext.
- JspWriter.
- JspEngineInfo.
- JspException.
- JspError.
JspPage interface:
JspPage extends the Servlet interface. JSP processor-generated servlet class must implement JspPage interface.
public interface JspPage extends Servlet
Methods of JspPage interface:
1. jspInit(): It is used to perform the initialization process. This method is called by the web container only once when the first request comes.
Syntax:
public void jspInit()
2. jspDestroy(): It is used to perform a cleanup process before destroying jsp page. This method is called by the web container only once.
Syntax:
public void jspDestroy()
HttpJspPage interface:
HttpJspPage interface extends the JspPage interface.
public interface HttpJspPage extends JspPage
Methods of HttpJspPage interface:
1. _jspService(): This method is called by the web container whenever a request comes for the jsp.
Syntax:
public void _jspService() throws ServletException,IOException
Note: In this method underscore (_) represents that implementation of this method is provided by an auto-generated servlet and it can’t be overridden by the developer.
How does the JSP page work?
- A request comes for the JSP page.
- Web container translates the JSP page into a servlet.
- Compile the auto-generated servlet class.
- _JspService()method is called.
- Dynamic content will be generated.
- Send dynamically generated content as a response to the client.
For the first request, all 6 steps will be executed but for the next requests of this JSP page 2nd and 3rd steps will not execute.
JSP Basic tutorial:
- Hello World Example in JSP
- Scriptlet tag in JSP
- JSP Declaration tag
- JSP Expression tag
- JSP comment tag
- JSP directives
- import attribute of JSP page directive
- JSP Session Attribute
- JSP Buffer attribute
- JSP autoFlush attribute
- JSP contentType attribute
- isErrorPage and errorPage attribute in JSP page directive
- JSP isThreadSafe attribute
- JSP language attribute
- JSP info attribute
- JSP include directive
- JSP taglib directive
- JSP implicit objects
- JSP out implicit object
- JSP Request implicit Object
- JSP response implicit object
- JSP config implicit object
- JSP application implicit object
- JSP session implicit object
- JSP pageContext implicit Object
- JSP page implicit object
- JSP exception implicit object
- JSP action tags
- JSP forward action tag
- Jsp include action tag
- JSP param action tag
- JSP usebean getproperty setproperty
- Exception handling in JSP
- JSTL (JSP Standard Tag Library)
- JSTL Core Tags
- JSTL cout Core Tag
- JSTL cset Core Tag
- JSTL c:remove Core Tag
- JSTL c:catch Core Tag
- JSTL c if Core Tag
- JSTL c:choose, c:when and c:otherwise Core Tags
- JSTL c:import Core Tag
- JSTL c:forEach Core Tag
- JSTL c:forTokens Core Tag
- JSTL c:url Core Tag
- JSTL c:param Core Tag
- JSTL c:redirect Core Tag
- JSTL Formatting Tags
- JSTL fmt:formatNumber Formatting Tag
- JSTL fmt:parseNumber Formatting Tag
- JSTL fmt:formatDate Formatting Tag
- JSTL fmt:parseDate Formatting Tag
- JSTL fmt:bundle Formatting Tag
- JSTL fmt:setLocale Formatting Tag
- JSTL fmt:setBundle Formatting Tag
- JSTL fmt:timeZone Formatting Tag
- JSTL fmt:setTimeZone Formatting Tag
- JSTL fmt:requestEncoding Formatting Tag
- JSTL Functions
- JSTL fn:contains() function
- JSTL fn:containsIgnoreCase() function
- JSTL fn:startsWith() function
- JSTL fn:endsWith() function
- JSTL fn:escapeXml() function
- JSTL fn:indexOf() function
- JSTL fn:join() and fn:split() function
- JSTL fn:length() function
- JSTL fn:replace() function
- JSTL fn:subString() function
- JSTL fn:subStringAfter() function
- JSTL fn:subStringBefore() function
- JSTL fn:toLowerCase() function
- JSTL fn:toUpperCase() function
- JSTL fn:trim() function
- Custom tags
- Custom tag with attributes
- JSP Expression Language
- JSP lifecycle phases
- eclipse maven jsp hello world