• +91 9971497814
  • info@interviewmaterial.com

JSP Interview Questions Answers

Question 1 : What is JSP technology?

Answer 1 : Java Server Page 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. JSPs are secure, platform-independent, and best of all, make use of Java as a server-side scripting language.

Question 2 : What are the two kinds of comments in JSP and what's the difference between them ?

Answer 2 : <%-- JSP Comment --%> <!-- HTML Comment -->

Question 3 : What is the difference between directive include and jsp include?

Answer 3 : <%@ include> : Used to include static resources during translation time. : Used to include dynamic content or static content during runtime.

Question 4 : What is the page directive is used to prevent a JSP page from automatically creating a session?

Answer 4 : <%@ page session="false">

Question 5 : How do I mix JSP and SSI #include?

Answer 5 :  1 If you're just including raw HTML, use the #include directive as usual inside your .jsp file. But it's a little trickier if you want the server to evaluate any JSP code that's inside the included file. If your data.inc file contains jsp code you will have to use The is used for including non-JSP files. 2 If you're just including raw HTML, use the #include directive as usual inside your .jsp file. <!--#include file="data.inc"--> But it's a little trickier if you want the server to evaluate any JSP code that's inside the included file. Ronel Sumibcay (ronel@LIVESOFTWARE.COM) says: If your data.inc file contains jsp code you will have to use <%@ vinclude="data.inc" %> The <!--#include file="data.inc"--> is used for including non-JSP files.

Question 6 : Why is _jspService() method starting with an '_' while other life cycle methods do not?

Answer 6 : _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.

Question 7 : How do you connect to the database from JSP?

Answer 7 : A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets. Further then you can use the resultset object "res" to read data in the following way.

Question 8 : What is JSP page?

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

Question 9 : How do I use a scriptlet to initialize a newly instantiated bean?

Answer 9 : A jsp:useBean action may optionally have a body. If the body is specified, its contents will be automatically invoked when the specified bean is instantiated. Typically, the body will contain scriptlets or jsp:setProperty tags to initialize the newly instantiated bean, although you are not restricted to using those alone. The following example shows the "today" property of the Foo bean initialized to the current date when it is instantiated. Note that here, we make use of a JSP expression within the jsp:setProperty action. value=""/ >

Question 10 : What are stored procedures? How is it useful?

Answer 10 : A stored procedure is a set of statements/commands which reside in the database. The stored procedure is pre-compiled and saves the database the effort of parsing and compiling sql statements every time a query is run. Each database has its own stored procedure language, usually a variant of C with a SQL preproceesor. Newer versions of db’s support writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procs to implement the business logic( A lot of systems still do it). 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 db. The overhead of a JDBC Connection may be significant in these cases.

JSP Contributors

krishan

Share your email for latest updates

Name:
Email:

Our partners