Beruflich Dokumente
Kultur Dokumente
Servlets
1.Define Java Servlet?
Ans: A Java Servlet is a simple Java Class, which is dynamically loaded onto Web Server and therefore,
enhances the functionality of the Web Server. A Java Servlet is secure and portable as it runs on the Web
Server and cannot operate outside its domain.
The following methods of the ServletResponse interface are used to access and set buffering informations:
int getBufferSize() : Gets the buffer size of the Underlying buffer being used.
Reset() : Clears the data in the buffer , including the status codes and headers sets, if the response is not
committed.
resetBuffer() : Clears the data in the buffer if the response in not Committed.
=>URL rewriting
=>Cookies
=>HTTP Session
Page : Starts when a request enters the service method of a Servlet and ends as a request leaves the service
method.
Request : Starts when a request object comes into the scope of a Web Component and ends when the request
object goes out of the Web Component scope.
Session : Starts when a client request enters the session and ends when the client leaves the Session.
Context(or)application : Starts when a Web application is started and ends when the Web Application is
destroyed.
=>When getSession(false) method is used, the Web container tries to locate and return the Session, but if the
Web Container is not able to locate the session, it returns null.
=>when getSesssion() or getSession(true) is used, the Web Container tries to locate the Session and returns it,
but if the Web Container is not able to locate the Session, it creates new session and associates it with the
client request.
<init-param> tag part of web.xml will initialize the parameters in ServletConfig object
<context-param> tag part of web.xml will initialize the parameters in ServletContext object
(a)Direct servlet manipulation : In this a Servlet can gain access rights to the currently running servlets and
can perform operations on each of then.
(b)Servlet reuse : This is a method where one servlet uses another’s servlet capability for its own purpose.
(c)Servlet collaboration : This is most widely used interservlet communication. It includes two or more
servlets sharing the state data. The Servlet collaboration can be done through the system properties list, shared
objects, and inheritance.
JSP
1. What is JSP?
Ans: JSP is totally tag-based, which means that each piece of code in JSP is enclosed within a tag. JSP tags
reduce the necessity of large amount of Java Code in JSP pages by implementing the functionality of the tags
into tag implementation classes.These tags help developers build dynamic pages, improve their code by
reducing Java code, separate the presentation logic from the business logic.
2. JSP Architectures?
Ans: JSP specifications demonstrate two approaches to build Web applications by using JSP. These
approaches are known as JSP Model 1 and Model 2 architectures.
(i)Page Translation
(ii)Compilation
(iv)Request Handling
(v)Destroing
Scriptlet tag
<%
Declarative tags
<%!
%>
Expression tag
<%=
%>
->response
->out
->page
->pageContext
->application
->session
->config
->exception
(a)page
(b)include
(c)taglib
(a)page:
The page directive tag holds the instructions used by the translator during the translation stage of the JSP life
cycle. These instructions affect the various properties associated with the whole JSP page.
(b)include:
The include directive tage is used to merge the contents of two or more files during the translation stage of the
JSP life cycle. The include directive tag adds text of the included file to the JSP page, without any processing
or modification.
(c)taglib:
The taglib directive tag is used to declare a custom tag lib in JSP page so that the tags related to that custom
tag library can be used in the same JSP page.
10.What is JavaBean?
Ans: JavaBeans are reusable software components that separate the business logic from the presentation logic.
In general, JavaBeans are simple Java classes that follow certain specifications to develop dynamic content.
11.Advantages of JavaBeans?
Ans:
(i)With the use of JavaBeans, users can menage presentation code and business logic separately.
(ii)Using JavaBeans with JSP has made object sharing between multiple Web pages simple
(iii)Using JavaBeans with JSP has simplified the process of request and response handling.
<jsp:forward>
<jsp:param>
<jsp:useBean>
<jsp:setProperty>
<jsp:getProperty>
<jsp:plugin>
<jsp:params>
<jsp:fallback>
<jsp:attribute>
<jsp:body>
<jsp:element>
<jsp:text>
14.What is the difference between include directive tag and include Action
tags?
(i)The “include” directive tag inserts the given page and includes the content in the generated Servlet page
during the translation phase of the JSP life cycle.
(ii)The “include” action tag is used to include the response generated b executing the specified JSP page or
Servlet. The response is included during the request processing phase, when the page is requested b the user.
(ii)These are able to access all the objects available in a JSP page.
(iii)These are used to modify the response generated by calling the attributes from the main page
(v)The Custom tags can be nested within each other to provide complexit in a JSP page.
->pageScope
->requestScope
->sessionScope
->applicationScope
->param
->paramValues
->header
->headerValues
->cookie
->initParam
18.Define JSTL?
Ans:JSTL stands for JSP Standard Tag Library , which is a collection of custom tag libraries, which provides
core functionality used for JSP documents. JSTL reduces the use of Scriptlets in JSP page. The use of JSTL
tags allows developers to use predefined tags instead of writing the JavaCode.
(ii)XML tags : Used for parsing,selecting, and transforming XML data in JSP page
(iii)Format tags :Used for formatting the data used in JSP page
(iv)SQL tags: Used to access the relational Database used in JSP page
JDBC
1.define JDBC Statements?
Ans: JDBC statements are used to execute SQL statements. JDBC API supports three types of JDBC statement
objects to work with SQL statements , Which are as follows:
(iii)CallableStatement – Executes parameterized SQL statement that invokes DB procedure or function and
supports IN and OUT parameters
2.Define Transaction?
Ans:Transaction is a set of statements executed on a resource or resources applying
ACID(Atomocity,Consistency,Isolation,Durability) properties.
(i)DatabaseMetaData
(ii)ParameterMetaData
(iii)ResultSetMetaData
Update Your Skills form our Experts & Enroll Now for Advanced Java Online Training
4.Define BLOB datatype?
Ans:A BLOB is built-in data type supported by the database implementing SQL-99 standards. As the name
implies, this is used to store large binary data, such as bit imagaes,audios and, multimedia clips, as the column
values in a database table.