Consider the following code snippet of servlet code:
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String value = getValue ();
if (value == null) response.sendError (HttpServletResponse.SC_NOT_FOUND, "Failed");
response.sendRedirect ("test.jsp");
}
If the getValue () method returns null , which of the following statements are true?
A The code will work without any errors or exceptions B An IllegalStateException will be thrown
C An IOException will be thrown
D A NullPointerException will be thrown
Answer
B
Which of the following statements is true regarding MyServlet?
import javax.servlet.*;
import javax.servlet.http.*:
import java.io.*;
public class MyServlet extends HttpServlet implements SingleThreadModel
{
String myName;
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
response.setContentType("text/plain");
PrintWriter out = res.getWriter();
myName = req.getParameter("name");
sayHello(out);
out.close();
}
public void sayHello(PrintWriter out) {
out.println("Hello " + myName);
}
}
A MyServlet is thread safe
B MyServlet is not thread safe because myName is an instance variable
C MyServlet is not thread safe because MyServlet implements SingleThreadModel.
D None of the above
Answer
A
Which of the following combinations regarding Design Patterns are correct?
A Business Delegate - Reduces the coupling between presentation-tier clients and business services.
B Data Access Object - Allows for Multiple Views using the same model
C MVC - Enables easier migration to different persistence storage implementations.
D Value Object - Reduces Network Traffic
Answer
A and D
Which of these is true about deployment descriptors. Select one correct answer.
A The order of elements in deployment descriptor is important. The elements must follow a specific order.
B The elements of deployment descriptor are not case insensitive
C The servlet-mapping element, if defined, must be included within the servlet element.
D The web-app element must include the servlet element
Answer
A
Which of these is a correct fragment within the web-app element of deployment descriptor. Select the two correct answer.
A
B
C
D
Answer
A and D
Which of these is a correct example of specifying a listener element resented by MyClass class. Assume myServlet element is defined correctly. Select one correct answer.
A
B
C
D <>
Answer
B
In a JSP custom tag , which method would you use to access JSP implicit variable that references application scope ?
A PageContext.getOut()
B jspFactory.getPageContext()
C TagSupport.getValue(String)
D pageContext.getServletContext()
Answer
D
Which method is used to retrieve objects from session?
A getAttribute method of javax.servlet.ServletSession.
B getAtrribute method of javax.servlet.HttpSession
C getAttribute method of javax.servlet.http.Session
D getAttribute method of javax.servlet.http.HttpSession
E getAttribute method of javax.servlet.HttpSession
Answer
D
A GET
B PUT
C POST
D HEAD
Answer
B
When a user clicks on a link in a page, which method will get invoked ?
A POST
B PUT
C GET
D HEAD
Answer
C
What method will get executed on clicking the following code.?
A GET
B POST
C HEAD
D PUT
Answer
A
Which character is used to separate the URI and query string ?
A ?
B &
C =
D ;
Answer
A
What will be the output of the following code? Assume that all the variables are declared properly
String str= request.getDateHeader("Accept-Language");
out.println(str);
A Compiler error
B An IO Exception is thrown
C Null
D An IllegalArgumentException thrown
Answer
D
To send binary output to response, which method of HttpServletResponse is used to get the Writer/ Stream object ?
A getStream
B getWriter
C getBinaryOutputStream
D getOutputStream
E getBinaryStream
Answer
D
which of the following JSP implicit object will not be available to the JSP page ? Select two
A session
B request
C application
D exception
Answer
A and D








