JSP Technology:
- JSP technology is used to create web application just like Servlet technology.
- JSP dynamically creates web pages that are based on HTML, XML or different type of documents.
- Latest version of JSP is JSP2.2 released on 10th Dec, 2009.
- JSP is the extension of servlet technology. It provide all features of servlet as well as some added features like implicit objects, custom tags, expression language.
- JSP is easy to manage because we separate our business logic with presentation logic.
- If JSP page is modified, it avoid recompilation of class and redeployment of project like Servlet.
JSP API have two packages:
- javax.servlet.jsp
- javax.servlet.jsp.tagext
Life Cycle of jsp:
- JSP life cycle is the entire process from its creation till destruction.
3 methods:
- _jspInit() It is invoked for initialization
- _jspService() It is invoked for request processing
- _jspDestroy() It is invoked for destroying
Jsp Phases :
Jsp Tags:
- Directive tag
- Declaration tag
- Expression tag
- Scriptlet tag
- Comment tag
Directive Tags:
Directives
are the messages that tells the container about how to translate JSP page into
corresponding servlet.
It has
three types:
- Page Directive
- Include Directive
- Taglib Directive
Page directive:
Defines attributes
that apply to an entire page.
Syntax: <%@page
attribute=“value” %>
Attributes :
import, extends, info, buffer, session,
contentType, language, errorPage ,isError ..etc.
- Used for exception handling
- package import ,
- give some info
- set the contentType
- maintain session
- Threadsafe etc.....
Include Directive:
- It is used to include more than one file at runtime.
- it is basically used for layout designing.
- it allow reusability of a designed file for example in gmail the top and left part will not change but the centre part will change.
Syntax:
<%@include attribute=“value”%>
Example: <%@include file="top..jsp" %>
Taglib Directive:
It is used to define a tag library that defines many tags from give api.
It is used for....
- Custom Tags.
- Jstl implementation.
- Struts tags
- Spring tags
Syntax:
<%@taglib uri=“value” prefix=“value”%>
Declaration Tag:
- It is used to declare data-members in jsp such as fields ,method etc. . Code of this tags do not go in service() method of generated servlet.
- It declare as a class level.
- Statements in this tag are terminated by ;
Syntax:
<%! %>
Example:
<%! int a=10;
int add(int a,int b)
{
int c=a+b;
return c;
}
%>
Expression Tag:
It is the replacement of out.print().
It is used to show the output.
Code of this tag goes to the output stream of response
method.
Syntax: <%= %>
Example: <%= “JSP Technology” %>
Scriptlet Tag:
- It contains the java source code.
- Code of this tag goes to the service() method of generated servlet.
- Entire business logic is written here.
- We cant define method here.
Syntax: <% %>
Example:
<%
out.print(“Scriptlet
tag”);
%>
Comment Tag:
- It does not participant in translation phase.
- It makes our code more understandable .
Syntax:
<%-- --%>
<!-- -->
Note: Tag within tag is not allowed in JSP. It generate syntax error during compilation.
Jsp Implicit Object:
There is 9 implicit object define by web-container .These are.....
S.No.
|
Classes/Interfaces
|
Objects
|
1
|
JspWriter
|
out
|
2
|
HttpServletRequest
|
request
|
3
|
HttpServletResponse
|
response
|
4
|
ServletContext
|
application
|
5
|
ServletConfig
|
config
|
6
|
HttpSession
|
session
|
7
|
PageContext
|
pageContext
|
8
|
Object
|
page
|
9
|
Throwable
|
exception
|
Reach us At: - 0120-4029000 / 24 / 25 / 27 / 29 Mobile: 9953584548
Write us at: - Smruti@apextgi.com and pratap@apextgi.com
No comments:
Post a Comment