JSP Technology Is Used To Create Web Application Just Like Servlet
JSP Technology Is Used To Create Web Application Just Like Servlet
JSP Technology Is Used To Create Web Application Just Like Servlet
A JSP page consists of HTML tags and JSP tags. The JSP pages are
easier to maintain than Servlet because we can separate designing and
development. It provides some additional features such as Expression
Language, Custom Tags, etc.
1) Extension to Servlet
2) Easy to maintain
JSP can be easily managed because we can easily separate our business
logic with presentation logic. In Servlet technology, we mix our business
logic with the presentation logic.
3) Fast Development: No need to recompile and redeploy
In JSP, we can use many tags such as action tags, JSTLs( a collection of
useful JSP tags which encapsulates the core functionality common to
many JSP applications) custom tags, etc. that reduces the code.
Moreover, we can use EL, implicit objects, etc.
1. javax.servlet.jsp
2. javax.servlet.jsp.tagext
javax.servlet.jsp package
1. JspPage
2. HttpJspPage
o JspWriter
o PageContext
o JspFactory
o JspEngineInfo
o JspException
o JspError
According to the JSP specification, all the generated servlet classes must
implement the JspPage interface. It extends the Servlet interface. It
provides two life cycle methods.
Methods of JspPage interface
1. public void jspInit(): It is invoked only once during the life cycle
of the JSP when JSP page is requested firstly. It is used to perform
initialization. It is same as the init() method of Servlet interface.
2. public void jspDestroy(): It is invoked only once during the life
cycle of the JSP before the JSP page is destroyed. It can be used to
perform some clean up operation.
The HttpJspPage interface provides the one life cycle method of JSP. It
extends the JspPage interface.
1. Scripting elements
2. JSP scriptlet tag
3. Simple Example of JSP scriptlet tag
4. Example of JSP scriptlet tag that prints the user name
In JSP, java code can be written inside the jsp page using the scriptlet
tag. Let's see what are the scripting elements first.
JSP Scripting elements
The scripting elements provides the ability to insert java code inside the
jsp. There are three types of scripting elements:
o scriptlet tag
o expression tag
o declaration tag
The code placed within JSP expression tag is written to the output
stream of the response. So you need not write out.print() to write data. It
is mainly used to print the values of variable or method.
The code written inside the jsp declaration tag is placed outside the
service() method of auto generated servlet. So it doesn't get memory at
each request.
The jsp scriptlet tag can The jsp declaration tag can declare variables as we
only declare variables not
methods.
The declaration of The declaration of jsp declaration tag is placed out
scriptlet tag is placed _jspService() method.
inside the _jspService()
method.
There are 9 jsp implicit objects. These objects are created by the web
container that are available to all the jsp pages.
out JspWriter
request HttpServletRequest
response HttpServletResponse
config ServletConfig
application ServletContext
session HttpSession
pageContext PageContext
page Object
exception Throwable
PrintWriter out=response.getWriter();