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 with example
- JSP Declaration tag with example
- JSP Expression tag with example
- JSP comment tag with example
- JSP directives with example
- import attribute of JSP page directive with example
- Session attribute of JSP page directive with example
- buffer attribute in JSP page directive with example
- autoFlush attribute in JSP page directive with example
- contentType attribute in JSP page directive with example
- isErrorPage and errorPage attribute in JSP page directive with example
- isThreadSafe attribute in JSP page directive with example
- language attribute in JSP page directive with example
- info attribute in JSP page directive with example
- JSP include directive with example
- JSP taglib directive with example
- JSP implicit objects with example
- JSP out implicit object with example
- JSP request implicit Object with example
- JSP response implicit object with example
- JSP config implicit object with example
- JSP application implicit object with example
- JSP session implicit object with example
- JSP pageContext implicit object with example
- JSP page implicit object with example
- JSP exception implicit object with example
- JSP action tags with example
- jsp:forward action tag with example
- jsp:include action tag with example
- jsp:param action tag with example
- jsp:useBean, jsp:setProperty and jsp:getProperty action tag
- Exception handling in JSP with example
- JSP Expression Language with example
JSTL (JSP Standard Tag Library) tutorial:
- JSTL (JSP Standard Tag Library) with example
- JSTL Core Tags with example
- JSTL c:out Core Tag with example
- JSTL c:set Core Tag with example
- JSTL c:remove Core Tag with example
- JSTL c:catch Core Tag with example
- JSTL c:if Core Tag with example
- JSTL c:choose , c:when and c:otherwise Core Tags with example
- JSTL c:import Core Tag with example
- JSTL c:forEach Core Tag with example
- JSTL c:forTokens Core Tag with example
- JSTL c:url Core Tag with example
- JSTL c:param Core Tag with example
- JSTL c:redirect Core Tag with example
- JSTL Formatting Tags with example
- JSTL fmt:formatNumber Formatting Tag with example
- JSTL fmt:parseNumber Formatting Tag with example
- JSTL fmt:formatDate Formatting Tag with example
- JSTL fmt:parseDate Formatting Tag with example
- JSTL fmt:bundle Formatting Tag with example
- JSTL fmt:setBundle Formatting Tag with example
- JSTL fmt:setLocale Formatting Tag with example
- JSTL fmt:timeZone Formatting Tag with example
- JSTL fmt:setTimeZone Formatting Tag with example
- JSTL fmt:requestEncoding Formatting Tag with example
- JSTL Functions with example
- JSTL fn:contains() function with example
- JSTL fn:containsIgnoreCase() function with example
- JSTL fn:startsWith() function with example
- JSTL fn:endsWith() function with example
- JSTL fn:escapeXml() function with example
- JSTL fn:indexOf() function with example
- JSTL fn:join() and fn:split() function with example
- JSTL fn:length() function with example
- JSTL fn:replace() function with example
- JSTL fn:subString() function with example
- JSTL fn:subStringAfter() function with example
- JSTL fn:subStringBefore() function with example
- JSTL fn:toLowerCase() function with example
- JSTL fn:toUpperCase() function with example
- JSTL fn:trim() function with example
Custom tags tutorial:
Maven eclipse JSP:
JSP Interview Questions: