1. What is JSP?
JSP
stands for Java Server Pages. JSP is java server side technology to create
dynamic web pages.
JSP file compiled by JSP container and convert it into servlet file.
2. What are
the advantages of JSP?
JSP
page is more suitable for create web pages and it is allows HTML tags, Servlet code and XML.
JSP always
compile before its process and the length of code is reduced by using custom
tags and tag library. Java components can be easily embedded into the dynamic pages.
3. What is
the JSP life cycle?
jspInit(): When
a container loads a JSP it invokes the jspInit() method before servicing any
requests. _jspService(): Whenever
a browser requests a JSP and the page has been loaded and initialized, the JSP
engine invokes the _jspService() method in the JSP. The _jspService() method is
invoke once per a request and is responsible for generating the response for
that request. jspDestroy(): When
a JSP is being removed from use by a container then jspDestroy() method will
call.
4. Why _jspService() method starts with “_” ?
_jspService()
method will be written by the container hence any methods which are not to be
overridden by the end user are typically written starting with an “_”. This is
the reason why we don't override _jspService() method in any JSP page.
5. Can we
override JSP lifecycle methods?
We can
override jspInit() and jspDestroy() methods using JSP declaration scripting
element.
6. Is JSP technology extensible?
JSP
technology is extensible through the development of custom actions, or tags,
which are encapsulated in tag libraries.
7. What
is the difference between Servlet and JSP?
JSP
|
Servlet
|
JSP run slower, it takes compilation time to
convert into Java Servlets.
|
Servlets run faster
|
JSP act as a view
in MVC
|
Servlet act as a
controller in MVC
|
JSP allows HTML, java
code, XML
|
Servlet allows java code
only
|
In JSP we can build custom
tag
|
There is no such custom
tag facility in servlets
|
Length of the code will be
reduce by custom tags
|
There is no facility
|
8. What are the differences between
JSP and ASP?
JSP - Java Server Pages
|
ASP - Active Server Pages
|
JSP is java technology and
it is a server side scripting language developed by Sun Microsystems
|
ASP is .Net technology and
it is a server side scripting language developed by Microsoft
|
JSP is platform independent and can run on
any platform
|
ASP runs on only Microsoft Windows platform
|
Java Server Pages runs on Apache Tomcat server
|
Active Server Pages runs on IIS (Internet
Information Server)
|
We can connect it to any
data base through drivers(libraries)
|
We can connect ASP to MS
SQL or any other database with the help of ADO (ActiveX data object)
|
High security and easy to maintenance
|
Low security and hard to maintenance
|
Open source and we can
build custom tag
|
It is cost and no custom
tag facility
|
9. What is scriptlet syntax in JSP?
Scriptlet is
useful to write the java program statements, declarations and expressions.
Syntax: <%
write java code here %>
10. What is the syntax for comments in JSP?
JSP comment is useful when you want to hide or "comment out"
part of your JSP page.
Syntax: <%--
comment anything here in JSP file --%>
11. What is an output comment?
A comment is sent to the client in the viewable page source. The JSP
engine handles an output comment and returning the comment in the HTML output (browser
page source) sent to the client.
Syntax: <!--
output comment -->
12. What is a Hidden Comment?
A comment that documents the JSP page but is not sent to the client. The
JSP engine ignores a hidden comment, and does not process any code within
hidden comment tags.
Syntax: <%--
hidden comment --%>
13. What is JSP Expression?
JSP expression contains a scripting language expression that is
evaluated, converted to a String, and inserted where the expression appears in
the JSP file.
Syntax:
<%= expression %>
14. What are the JSP
directives?
Page: Defines page-dependent attributes, such as scripting language, error
page, and buffering requirements.
<%@page
contentType=" "%>
Include: include a jsp file into another
jsp file.
<%@include
file=" " %>
Taglib: Declares a tag library, containing
custom actions, used in the page.
<%@
taglib uri=" " prefix=" " %>
15. Can we include a JSP page into another JSP
page?
Yes, we can
include by using include directive.
<%@include
file=" " %>
16. What are the implicit
objects?
Implicit
objects that are available for the use in JSP documents without being declared
first. These objects are parsed by the JSP engine and inserted into the
generated servlet.
Implicit
objects are:
1. request
2. response
3. pageContext
4. session
5. application
6. out
7. config
8. page
9. exception
1. request
2. response
3. pageContext
4. session
5. application
6. out
7. config
8. page
9. exception
Above mentioned all the JSP Interview Questions and Answers are very informative and useful for java interviews.
ReplyDeletethanks for this.