Select chapter



basics (7.papers)
constructors (1.papers)
packages (1.papers)
inheritance (7.papers)
misc (3.papers)
exceptions (5.papers)
threads (4.papers)
overloading (1.papers)
jsp (3.papers)
servlets (9.papers)
jdbc (2.papers)
util (1.papers)
xml (2.papers)
IO stream (3.papers)
Hide

Sponsored Links


  

java interview questions and answers

Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
6
What is true about the servlet? 
@WebServlet("/T") 
public class Test extends HttpServlet {
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
 {  response.setContentType("text/html"); 
    HttpSession session = request.getSession();
    session.setAttribute("name", "Test");
    session.invalidate();
   System.out.print(session.getAttribute("name")) ;
   }
}
  1. When the folowing servlet is requested "Test" is printed on the server console
  2. When the folowing servlet is requested "Test" is printed on the page
  3. When the folowing servlet is requested a runtime error with HTTP Status 500 is printed on the page
  4. When the folowing servlet is requested "null" is printed on the server console
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
10
Given: 
<web-app> 
  <servlet>
    <servlet-name>main</servlet-name>
    <servlet-class>MainServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>main</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>
Which of the following is true?
  1. url-pattern entry is invalid, the web application will not deploy
  2. servlet-mapping element should be inside servlet element
  3. all calls to this web application will take you to MainServlet
  4. all calls to the servlet in this web application will take you to MainServlet
Show Answer
Share Facebook gmail Twitter
11
Following is part of element declaration inside web.xml. How can the value of flower be obtained in doGet() method of a servlet?
<context-param> 
 <param-name>flower</param-name>
 <param-value>rose</param-value>
</context-param>
  1. getServletContext().getInitParameter("flower");
  2. getServletContext().getParameter("flower");
  3. getServletContext().getContextParameter("flower");
  4. getServletContext().getAttribute("flower");
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
14
How should the "out" variable be initialized if binary data like image has to be sent as response from a servlet? Asuume that response is HttpServletResponse object
  1. PrintWriter out = response.getPrintWriter();
  2. PrintWriter out = response.getWriter();
  3. FileOutputStream out = response.getServletOutputStream();
  4. ServletOutputStream out = response.getOutputStream();
Show Answer
Share Facebook gmail Twitter
15
A servlet and servlet mapping URL is provided in the web.xml but the servlet class does not exist. In such case what will happen when you request for the servlet? 
  1. HTTP Status 500 is printed on the page
  2. HTTP Status 404 is printed on the page
  3. HTTP Status 200 is printed on the page
  4. None of theabove
Show Answer
Share Facebook gmail Twitter
16
The Servlet Container has just called the destroy() method of a servlet instance, which of the following cannot be the reason why this was called? 
  1. The servlet has thrown a runtime exception
  2. The time out specified by the servlet container for this servlet instanc has exceeded.
  3. The server has shut down
  4. The application has been stopped
Show Answer
Share Facebook gmail Twitter
17
HttpSession session = request.getSession(false); 
Which of the following listeners is notified when this statement is invoked?
  1. HttpSessionBindingListener
  2. HttpSessionAttributeListener
  3. HttpSessionListener
  4. No Listener notified
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
Which of the following method is used to retrieve the value associated to the parameter defined in the init-param tag?
  1. getParameter(String name)
  2. getInitParameter(String name)
  3. getParameters()
  4. getInitParameterValue(String name)
Show Answer
Share Facebook gmail Twitter
Read more papers :