JSP-Servlet Interview Questions You'll Most Likely Be Asked
JSP-Servlet Interview Questions You'll Most Likely Be Asked
Questions
Review these typical interview questions and think about how you
would answer them. Read the answers listed; you will find best
possible answers along with strategies and suggestions.
This page is intentionally left blank.
Chapter 1
Servlet
code for a page and is based on Java. Servlets are java programs
that are written and compiled in a proper Java environment. You
can write dynamic HTML content in Servlets. JSP is a view
whereas Servlets are controllers. JSP ultimately compiles into a
servlet before it runs and hence, is a little slower compared to the
Servlets. -side data
o
the information requested. Implicit output would be the request
headers and status codes sent by the server.
main advantage of jsp pages is that they are much simpler to code
and implement. The HTML tags will be a real pain to write using
the java println statement. Instead, the required minimal scripts
are included between the HTML tags, making the jsp pages easier
to maintain. When using JSP, you can get the user interface coded
separately and just include the required java elements within the
scripting tags.
13: What are the objects a servlet would receive during client
interaction?
Answer:
A servlet would receive two objects during client interaction. They
are:
a) ServletRequest interface
b) ServletRespose interface
15: How would you get the real path of the current servlet?
Answer:
We can retrieve the current real path using getRealPath()
method:
System.out.println(request.getRealPath(request.getServletPath());
21: What would happen if I want to use the Servlet 2.1 API
instead of Servlet2.0 API?
Answer:
If we use Servlet 2.1 API instead of Servlet2.0 API, servlet to
servlet communication will not work as the communication using
servletcontext methods like getServlet() and getServlets() have
been deprecated. It will return null.
35: How would you retrieve the name and version number of
servlet or JSP engine?
Answer:
The name and version number of JSP engine or servlet is retrieved
as below:
a) In servlet:
String info=
getServletConfig().getServletContext().getServerInfo();
b) In JSP:
//About application server
<%= application.getServerInfo() %>
// About JSP engine
<%=JspFactory.getDefaultFactory().getEngineInfo()getSpec
ificationVersion()%>