Professional Documents
Culture Documents
com
tutorial4us.com
A Perfect Place for All Tutorials Resources
www.tutorial4us.com
A Perfect Place for All Tutorials Resources
www.tutorial4us.com
www.tutorial4us.com
Load the RDBMS specific JDBC driver because this driver actually
communicates with the database (Incase of JDBC 4.0 this is automatically
loaded).
Open the connection to database which is then used to send SQL statements
and get results back.
www.tutorial4us.com
The JDBC API uses a driver manager and database-specific drivers to provide
transparent connectivity to heterogeneous databases. The JDBC driver manager
ensures that the correct driver is used to access each data source. The driver
manager is capable of supporting multiple concurrent drivers connected to multiple
heterogeneous databases. The location of the driver manager with respect to the
JDBC drivers and the Java application is shown in Figure 1.
www.tutorial4us.com
www.tutorial4us.com
www.tutorial4us.com
www.tutorial4us.com
10.What is Statement ?
Statement acts like a vehicle through which SQL commands can be sent. Through
the connection object we create statement kind of objects.
Through the connection object we create statement kind of objects.
Statement stmt
= conn.createStatement();
webMethods Questions
www.tutorial4us.com
SCBCD Certification
11.What is
PreparedStatement?
PreparedStatement
A PreparedStatement is a precompiled
database.
www.tutorial4us.com
www.tutorial4us.com
CallableStatement stproc_stmt =
conn.prepareCall("{call procname(?,?,?)}");
www.tutorial4us.com
www.tutorial4us.com
No. You can open only one Statement object per connection when you are using
the JDBC-ODBC Bridge.
Note: Preferred by 9 out of 10 Java developers: Type IV. Click here to learn more
about JDBC drivers.
TRANSACTION_NONE
TRANSACTION_READ_COMMITTED
TRANSACTION_READ_UNCOMMITTED
TRANSACTION_REPEATABLE_READ
TRANSACTION_SERIALIZABLE
20.What is resultset ?
The ResultSet represents set of rows retrieved due to query execution.
www.tutorial4us.com
ResultSet rs = stmt.executeQuery(sqlQuery);
resultsets?
The values are defined in the
class java.sql.Connection and
are:
TYPE_FORWARD_ONLY
SCWCD Certification
TYPE_SCROLL_SENSITIVE
A sensitive resultset does NOT
www.tutorial4us.com
22.What is rowset?
A RowSet is an object that encapsulates a set of rows from either Java Database
Connectivity (JDBC) result sets or tabular data sources like a file or spreadsheet.
RowSets support component-based development models like JavaBeans, with a
standard set of properties and an event notification mechanism.
www.tutorial4us.com
26.What is a DataSource?
A DataSource object is the representation of a data source in the Java programming
language. In basic terms,
Data Source may point to RDBMS, file System , any DBMS etc..
www.tutorial4us.com
www.tutorial4us.com
www.tutorial4us.com
Managing state information on top of the stateless HTTP, e.g. for an online
shopping cart system which manages shopping carts for many concurrent
customers and maps every request to the right customer.
www.tutorial4us.com
A Servlet does not run in a separate process. This removes the overhead of
creating a new process for each request.
There is only a single instance which answers all requests concurrently. This
saves memory and allows a Servlet to easily manage persistent data.
Servlet class loading : For each servlet defined in the deployment descriptor
of the Web application, the servlet container locates and loads a class of the
type of the servlet. This can happen when the servlet engine itself is started,
or later when a client request is actually delegated to the servlet.
www.tutorial4us.com
Request handling (call the service method) : After the servlet is initialized,
the container may keep it ready for handling client requests. When client
requests arrive, they are delegated to the servlet through the service()
method, passing the request and response objects as parameters. In the case
of HTTP requests, the request and response objects are implementations of
HttpServletRequest and HttpServletResponse respectively. In the
HttpServlet class, the service() method invokes a different handler method
for each type of HTTP request, doGet() method for GET requests, doPost()
method for POST requests, and so on.
Removal from service (call the destroy method) : A servlet container may
decide to remove a servlet from service for various reasons, such as to
conserve memory resources. To do this, the servlet container calls the
destroy() method on the servlet. Once the destroy() method has been called,
the servlet may not service any more client requests. Now the servlet
instance is eligible for garbage collection
The life cycle of a servlet is controlled by the container in which the servlet
has been deployed.
www.tutorial4us.com
www.tutorial4us.com
There is only a single instance which answers all requests concurrently. This
saves memory and allows a Servlet to easily manage persistent data.
www.tutorial4us.com
Note: Most Servlets, however, extend one of the standard implementations of that
interface, namely javax.servlet.GenericServlet and
javax.servlet.http.HttpServlet.
class?
GenericServlet is an abstract
class that implements the Servlet
interface and the ServletConfig
interface. In addition to the
methods declared in these two
Webservices Questions
iBatis Tutorial
www.tutorial4us.com
HttpServlet
An abstract class that simplifies writing
HTTP servlets. It extends the
GenericServlet base class and provides
an framework for handling the HTTP
protocol.
protocol.
HTTPS protocol.
www.tutorial4us.com
doGet()
doPost()
In doPost(), on the other hand will
(typically) send the information
through a socket back to the webserver
and it won't show up in the URL bar.
You can send much more information
to the server this way - and it's not
www.tutorial4us.com
It disallows bookmarks.
www.tutorial4us.com
If data is sensitive
17.How do I support both GET and POST from the same Servlet?
The easy way is, just support POST, then have your doGet method call your
doPost method:
www.tutorial4us.com
We never override the service method, since the HTTP Servlets have already taken
care of it . The default service function invokes the doXXX() method
corresponding to the method of the HTTP request.For example, if the HTTP
request method is GET, doGet() method is called by default. A servlet should
override the doXXX() method for the HTTP methods that servlet supports.
Because HTTP service method check the request method and calls the appropriate
handler method, it is not necessary to override the service method itself. Only
override the appropriate doXXX() method.
www.tutorial4us.com
A servlet context object contains the information about the Web application of
which the servlet is a part. It also provides access to the resources common to all
the servlets in the application. Each Web application in a container has a single
servlet context associated with it.
21.What are the differences between the ServletConfig interface and the
ServletContext interface?
ServletConfig
ServletContext
web.xml file.
www.tutorial4us.com
forward()
sendRedirect()
A redirect is a two step process, where
the servlet.
request.
www.tutorial4us.com
include()
The RequestDispatcher include()
method inserts the the contents of the
specified resource directly in the flow of
the servlet response, as if it were part of
the calling servlet.
forward()
by many servlets.
www.tutorial4us.com
and
HttpServletResponseWrappe
r classes are designed to make it
WebSphere Certification
Hibernate Vs iBatis
www.tutorial4us.com
www.tutorial4us.com
ServletRequest.getRequestDispatcher
ServletContext.getRequestDispatcher
(String path)
(String path)
The getRequestDispatcher(String
path) method of
The getRequestDispatcher(String
javax.servlet.ServletRequest
path) method of
javax.servlet.ServletContext
root.
28.What is preinitialization of a
servlet?
A container does not initialize the servlets as soon as it starts up, it initializes a
servlet when it receives a request for that servlet first time. This is called lazy
loading. The servlet specification defines the element, which can be specified in
the deployment descriptor to make the servlet container load and initialize the
www.tutorial4us.com
servlet as soon as it starts up. The process of loading a servlet before any request
comes in is called preloading or preinitializing a servlet.
Note: The container loads the servlets in the order specified in the <load-onstartup> element.
www.tutorial4us.com
30.What is session?
A session refers to all the requests that a single client might make to a server in the
course of viewing any pages associated with a given application. Sessions are
specific to both the individual user and the application. As a result, every user of an
application has a separate session and has access to a separate set of session
variables.
www.tutorial4us.com
Typical example: Putting things one at a time into a shopping cart, then checking
out--each page request must somehow be associated with previous requests.
Hidden Form Fields : Similar to URL rewriting. The server embeds new
hidden fields in every dynamically generated form page for the client. When
the client submits the form to the server the hidden fields identify the client.
www.tutorial4us.com
Secure Socket Layer (SSL) Sessions : Web browsers that support Secure
Socket Layer communication can use SSL's support via HTTPS for
generating a unique session key as part of the encrypted conversation.
To get all of the cookies associated with a single HTTP request, use the
getCookies() method of class HttpServletRequest
www.tutorial4us.com
Cookies are usually persistent, so for low-security sites, user data that needs
to be stored long-term (such as a user ID, historical information, etc.) can be
maintained easily with no server interaction.
For small- and medium-sized session data, the entire session data (instead of
just the session ID) can be kept in the cookie.
disadvantages of storing
session state in cookies?
XML Questions
XML Certification
difficult to implement
than some other
approaches.
All data for a session are kept on the client. Corruption, expiration or
purging of cookie files can all result in incomplete, inconsistent, or missing
information.
Cookies may not be available for many reasons: the user may have disabled
them, the browser version may not support them, the browser may be behind
a firewall that filters cookies, and so on. Servlets and JSP pages that rely
exclusively on cookies for client-side session state will not operate properly
for all clients. Using cookies, and then switching to an alternate client-side
session state strategy in cases where cookies aren't available, complicates
development and maintenance.
www.tutorial4us.com
Cookie-based solutions work only for HTTP clients. This is because cookies
are a feature of the HTTP protocol. Notice that the while package
javax.servlet.http supports session management (via class
HttpSession), package javax.servlet has no such support.
passes the URL to encodeURL(), which encodes session ID in the URL if the
browser isn't accepting cookies, or if the session tracking is turned off.
E.g., http://abc/path/index.jsp;jsessionid=123465hfhs
Advantages
URL rewriting works just about everywhere, especially when cookies are
turned off.
www.tutorial4us.com
confuse the server by interacting with the same session through two
instances.
Entirely static pages cannot be used with URL rewriting, since every link
must be dynamically written with the session state. It is possible to combine
static and dynamic content, using (for example) templating or server-side
includes. This limitation is also a barrier to integrating legacy web pages
with newer, servlet-based pages.
DisAdvantages
Every URL on a page which needs the session information must be rewritten
each time a page is served. Not only is this expensive computationally, but it
can greatly increase communication overhead.
URL rewriting limits the client's interaction with the server to HTTP GETs,
which can result in awkward restrictions on the page.
If a client workstation crashes, all of the URLs (and therefore all of the data
for that session) are lost.
www.tutorial4us.com
<session-config>
<session-timeout>10</session-timeout>
</session-config>
This will set the time for session timeout to be ten minutes.
Setting timeout programmatically: This will set the timeout for a specific
session. The syntax for setting the timeout programmatically is as follows:
public void setMaxInactiveInterval(int interval)
40.A client sends requests to two different web components. Both of the
components access the session. Will they end up using the same session object or
different session ?
Creates only one session i.e., they end up with using same session .
www.tutorial4us.com
Sessions is specific to the client but not the web components. And there is a 1-1
mapping between client and a session.
www.tutorial4us.com
Security checks
Data compression
Response compression
It intercepts the request from a client before it reaches the servlet and
modifies the request if required.
It intercepts the response from the servlet back to the client and modifies the
request if required.
There can be many filters forming a chain, in which case the output of one
filter becomes an input to the next filter. Hence, various modifications can
be performed on a single request and response.
www.tutorial4us.com
www.tutorial4us.com
www.tutorial4us.com
the JSP functionality can be achieved on the client, using JavaScript. The power of
JSP is that it is server-based and provides a framework for Web application
development.
Translation
Compilation
jspInit() invocation
_jspService() invocation
jspDestroy() invocation
www.tutorial4us.com
resources such as database and network connections, and to allow a JSP page to
read persistent configuration data.
www.tutorial4us.com
7.How can I override the jspInit() and jspDestroy() methods within a JSP
page?
The jspInit() and jspDestroy() methods are each executed just once during the
lifecycle of a JSP page and are typically declared as JSP declarations:
<%!
public void jspInit() {
. . .
}
%>
<%!
public void jspDestroy() {
. . .
}
%>
request
response
pageContext
session
www.tutorial4us.com
application
out
config
page
exception
The implicit objects are parsed by the container and inserted into the generated
servlet code. They are available only within the jspService method and not in any
declaration.
Check more about implicit objects
9.What are the different types of JSP tags?
The different types of JSP tags are as follows:
www.tutorial4us.com
JSP directives are messages for the JSP engine. i.e., JSP directives serve as a
message from a JSP page to the JSP container and control the processing of
the entire page
They are used to set global values such as a class declaration, method
implementation, output content type, etc.
www.tutorial4us.com
A page directive is to inform the JSP engine about the headers or facilities
that page should get from the environment.
Typically, the page directive is found at the top of almost all of our JSP
pages.
There can be any number of page directives within a JSP page (although the
attribute value pair must be unique).
www.tutorial4us.com
This enables a user to reuse the code without duplicating it, and includes the
contents of the specified file at the translation time.
This directive has only one attribute called file that specifies the name of
the file to be included.
The JSP standard actions affect the overall runtime behavior of a JSP page
and also the response sent back to the client.
They can be used to include a file at the request time, to find or instantiate a
JavaBean, to forward a request to a new page, to generate a browser-specific
code, etc.
www.tutorial4us.com
page scope:: It specifies that the object will be available for the entire JSP
page but not outside the page.
www.tutorial4us.com
request scope: It specifies that the object will be associated with a particular
request and exist as long as the request exists.
session scope: It specifies that the object will be available throughout the
session with a particular client.
The execution of the current page is stopped and control is transferred to the
forwarded page.
Here, targetPage can be a JSP page, an HTML page, or a servlet within the
same context.
www.tutorial4us.com
The <jsp:include> standard action enables the current JSP page to include a static
or a dynamic resource at runtime. In contrast to the include directive, the include
action is used for resources that change frequently. The resource to be included
must be in the same context.The syntax of the <jsp:include> standard action is as
follows:
<jsp:include page="targetPage" flush="true"/>
Include directive
Include action
The include action, includes the
response generated by executing the
specified page (a JSP page or a servlet)
during the request processing phase
when the page is requested by a user.
www.tutorial4us.com
www.tutorial4us.com
In this case, the jsp:setProperty is executed regardless of whether a new bean was
instantiated or an existing bean was found.
Here, the jsp:setProperty is executed only if a new object was instantiated, not if an
existing one was found.
Here, name is the id of the bean from which the property was set. The property
attribute is the property to get. A user must create or locate a bean using the
<jsp:useBean> action before using the <jsp:getProperty> action.
www.tutorial4us.com
27.What is a scriptlet?
www.tutorial4us.com
A scriptlet contains Java code that is executed every time a JSP is invoked. When a
JSP is translated to a servlet, the scriptlet code goes into the service() method.
Hence, methods and variables written in scriptlets are local to the service()
method. A scriptlet is written between the <% and %> tags and is executed by the
container at request processing time.
expression is written between the <%= and %> tags. It is not required to end the
expression with a semicolon, as it implicitly adds a semicolon to all the
expressions within the expression tags.
www.tutorial4us.com