JSP (Java Server Pages):
JSP refers to the java server pages. Before starting discussion on jsp let us discuss the some problems of servlet.
Problems in servlet:
- In servlet presentation logic and dynamic content generation logic are intermixed which result into maintains problem.
- Every time when presentation is changed servlet needs to compile and deploy again.
- A developer needs to write HTML code to the output stream of the servlet.
JSP:
JSP is the extension of servlet that provides the solution of all above problems. JSP defines a structure which is java code inside HTML code. With this structure it simplifies the web development.
Javax.servlet.jsp package.
Javax.servlet.jsp and its sub packages provide the classes and interfaces 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 initialization process. This method is called by the web container only once when first request comes.
Syntax:
public void jspInit()
2. jspDestroy(): It is used to perform 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 web container every time when a request is come for the jsp.
Syntax:
public void _jspService() throws ServletException,IOException
Note: In this method underscore (_) represents that implementation of this method is provided by auto generated servlet and it can’t be overridden by developer.
How JSP page works?
- A request comes for 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 first request all 6 steps will be executed but for next requests of this JSP page 2nd and 3rd step will not execute.
JSP Basic tutorial:
-
- JSP lifecycle phases
- JSP Hello World Example
- JSP Scriptlet tag
- JSP Declaration tag
- JSP Expression tag
- JSP comment tag
- JSP directives
- import attribute of JSP page directive
- Session attribute of JSP page directive
- buffer attribute in JSP page directive
- autoFlush attribute in JSP page directive
- contentType attribute in JSP page directive
- isErrorPage and errorPage attribute in JSP page directive
- isThreadSafe attribute in JSP page directive
- language attribute in JSP page directive
- info attribute in JSP page directive
- 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, jsp:setProperty and jsp:getProperty action tag
- Exception handling in JSP
- JSP Expression Language
JSTL (JSP Standard Tag Library) tutorial:
- JSTL (JSP Standard Tag Library)
- JSTL Core Tags
- JSTL c:out Core Tag
- JSTL c:set 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