Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
JSP Interview Questions & Answers
Sponsered Links
Sponsered Links

JSP Interview Questions & Answers

 What is JSP and why it used in java?
JSP is a framework which is the part of MVC model, it stand for view which show on the front end of the application, it is a normally HTML pages with Java code pieces embedded in them. JSP pages are saved to *.jsp files. A JSP compiler is used in the background to generate a Servlet from the JSP page.

Differentiate between and response.sendRedirect(url),?.

The element forwards the request object holding the client request information from one JSP file to another file. sendRedirect sends HTTP temporary redirect response to the browser, and browser creates a new request to go the redirected page.

Differentiate between custom JSP tags and beans?

Custom JSP tag is a tag you defined. To use custom JSP tags, you need to define three things: The tag handler class that specifies the tag\'s behavior The tag library descriptor file that maps the XML element names the JSP file that uses the tag library JavaBeans are Java utility classes you defined. to declare a bean and use to set value of the bean class and use to get value of the bean class.

What are comments in JSP?

  1. (%-- JSP Comment --%)
  2. (!-- HTML Comment --)
  3. (% // Java comments %)
  4. (% /* Java comments*/ %)

What is JSP technology?

JSP is a standard Java extension that is defined on top of the servlet Extensions. The goal of JSP is the simplified creation and management of dynamic Web pages.

What is JSP page?

A text-based document that contains two types of text: static template data, which can be showed in any text-based format such as HTML, SVG, WML, and XML, and JSP elements, which construct dynamic content.

Describe implicit objects?

Implicit objects are objects that are created by the web container and contain information related to a particular request, page, or application. They are:
  • request
  • response
  • pageContext
  • session
  • application
  • out
  • config
  • page
  • exception

How many JSP scripting elements and what are they?

There are three scripting language elements:
  • declarations
  • scriptlets
  • expressions

Why are JSP pages the preferred API for creating a web-based client program?

Because no plug-ins or security policy files are needed on the client systems(applet does).

Differentiate between (jsp:include page = ... ) and (%@ include file = ... )?.

(jsp:include page = ... ): This is like a function call from one jsp to another jsp. (%@ include file = ... ): . In this case in the included file changes, the changed content will not included in the output. This approach is used when the code from one jsp file required to include in multiple jsp files.

Is JSP is extensible technology?

YES. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.

Can we use the constructor, instead of init(), to initialize servlet?

Yes , of course we can use the constructor instead of init(). The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig.

How can a servlet refresh automatically if some new data has entered the database?

You can apply a client-side Refresh or Server Push.

The code in a finally clause will never fail to execute, right?

Using System.exit(1); in try block will not allow finally code to execute.

How many messaging models do JMS provide for and what are they?

JMS provide for two messaging models, 1:publish-and-subscribe and 2:point-to-point queuing.

What type of information is needed to create a TCP Socket?

The Local Systems IP Address and Port Number. And the Remote System’s IPAddress and Port Number.

What Class.forName will do while loading drivers?

It is used to create an instance of a driver and register it with the DriverManager.

How to Retrieve Warnings?

A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object.

How many types of JSP scripting elements are there and what are they?

There are three scripting language elements: declarations, scriptlets and expressions.

In the Servlet 2.4 specification SingleThreadModel has been deprecated, why?

Because it is not practical to have such model. Whether you set isThreadSafe to true or false, you should take care of concurrent client requests to the JSP page by synchronizing access to any shared objects defined at the page level.

What are stored procedures? How is it useful?

"A stored procedure is a set of statements/commands which reside in the database". The biggest advantage is of course speed. Also certain kind of data manipulations are not achieved in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful when you want to do Batch updates/exports/houseKeeping kind of stuff on the database.

How do I include static files within a JSP page?

Static resources should always be admitted using the JSP include directive. This way, the inclusion is performed just once during the translation phase. Note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.

Why does JComponent have add() and remove() methods but Component does not?

because JComponent is a subclass of Container, and can contain other components and jcomponents.

How can I implement a thread-safe JSP page?

This is done by adding the directive <%@ page isThreadSafe="false" % > within your JSP page.

If the browser has disabled cookies. How can we enable session tracking for JSP pages ?

We know that session tracking uses cookies by default to associate a session identifier with a unique user. If the browser does not support cookies, or if cookies are disabled, you can still enable session tracking using URL rewriting. URL rewriting essentially includes the session ID within the link itself as a name/value pair.

What is a output comment?

The JSP engine handles an output comment as uninterrupted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser.

What is a Hidden Comment?

A comments 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. JSP Syntax <%-- comment --%>

What is a Declaration

A declaration declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as they are separated by semicolons. <%! declarations %> <%! int i = 0; %> <%! int a, b, c; %>

What is a Scriptlet

A scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language.Within scriptlet tags, you can 1.Declare variables or methods 2.Write expressions valid in the page scripting language 3.Use any of the JSP implicit objects

What are implicit objects? List them?

Certain 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.

Difference between forward and sendRedirect?

When a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completly new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.

What are the different scope values for the ?

The four different scope values for are 1. page 2. request 3.session 4.application

Explain the life-cycle mehtods in JSP?

The JspPage interface declares only two mehtods - jspInit() and jspDestroy() that must be implemented by all JSP pages regardless of the client-server protocol. However the JSP specification has provided the HttpJspPage interfaec specifically for the JSp pages serving HTTP requests. This interface declares one method _jspService(). The jspInit()- The container calls the jspInit() to initialize the servlet instance.It is called before any other method, and is called only once for a servlet instance. The jspservice()- The container calls the _jspservice() for each request, passing it the request and the response objects. The jspDestroy()- The container calls this when it decides take the instance out of service. It is the last method called n the servlet instance.

Sponsered Links
Latest Updates
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved