Pr.Pg Next Pg

Servlet Interview Questions and Answers Part 7

 

61.Explain the servlet context.

  • The servlet context is coined as an object.

  • It is contained information about the Web application and the container.

  • With a context, a servlet can be used for logging events, to obtain URL references to resources, and for setting and storing attributes for the other servlets within the context.

 

62. Explain servlet.

  • A servlet is simply a java program .

  • It runs for an action.

  • It runs inside a web container.

  • The servlet is used in various implementation project.

 

63.What is the procedure for initializing a servlet ?

  • To initialize a servlet init() is used.

  • init() initializes a java program.

  • A constructor can also be used to initialize a servlet.

  • Tell the new features added in ServletRequest interface i.e. Servlet 2.4

  • Following methods had been added to the ServletRequest 2.4 version:

  • public int getRemotePort()

  • public java.lang.String getLocalName()

  • public java.lang.String getLocalAddr()

  • public int getLocalPort()

 

64.How many JSP scripting elements are there and what are those?

  • We can name three scripting language elements:

scriptlets

  • JSP Scriplet is a jsp tag which is used for enclosing a java code in the JSP pages.

  • Scriplet begins with <% tag and ends with %> tag.

Declarations

  • Declarations are also a kind of tag.

  • It is used mainly for allocating variables.

expressions.

  • The Expression is a tag used for inserting Java values directly into the output.

  • The Syntax is

  • given as: <%= expression %>

 

65.How can we include static files in the JSP page?

  • Static resources can be included in the JSP.

  • It can be included with an include directive.

  • By this way, the inclusion is being performed for once.

  • The inclusion performs during the translation phase.

 

66.How can we implement a JSP page?

  • It's possible to make our JSPs thread-safe.

  • So we can do it by adding the directives.

  • The directive we have to add is :

  • <%@ page isThreadSafe="false" % >

 

67Explains the differences between context.getRequestDispatcher() and request.getRequestDispatcher() ? [Very Important]

  • To create the relative path for the resource we use request.getRequestDispatcher(path) .

  • To create the absolute path of the resource we use resourcecontext.getRequestDispatcher(path).

 

68.Define the lifecycle for executing a JSP page.

  • While executing the JSP page the JSP engine works in the following 7 phases :

  • Page translation: -page parsing .

  • Page compilation into a class file

  • Page loading by the class file loading.

  • Creating an instance of servlet.

  • jspInit() method is being called

  • _jspService is being called for handling the service calls

  • _jspDestroy is being called for destroying it when the servlet not required.

 

69.Define context initialization parameters.

  • Context initialization parameters are specified in the web.xml files,

  • These are basically initialization parameters.

  • This happens for the whole application.

 

70. What is an Expression?

  • Expressions are used as place holders for the language expressions.

  • These are evaluated each time, the page is being accessed.

  • This includes in the service method of the newly generated servlet.


Pr.Pg border                                              Next Pg

Warning: include_once(bottompad.php) [function.include-once]: failed to open stream: No such file or directory in D:\INETPUB\VHOSTS\cbtsam.com\httpdocs\servlet-tutorials\servlet-tutorials-servlets-interview-part-7.php on line 341

Warning: include_once() [function.include]: Failed opening 'bottompad.php' for inclusion (include_path='.;C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\pear;./includes;./pear') in D:\INETPUB\VHOSTS\cbtsam.com\httpdocs\servlet-tutorials\servlet-tutorials-servlets-interview-part-7.php on line 341

Warning: include_once(rightpad.php) [function.include-once]: failed to open stream: No such file or directory in D:\INETPUB\VHOSTS\cbtsam.com\httpdocs\servlet-tutorials\servlet-tutorials-servlets-interview-part-7.php on line 347

Warning: include_once() [function.include]: Failed opening 'rightpad.php' for inclusion (include_path='.;C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP5\pear;./includes;./pear') in D:\INETPUB\VHOSTS\cbtsam.com\httpdocs\servlet-tutorials\servlet-tutorials-servlets-interview-part-7.php on line 347