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
Answer D is the correct choice. If the header value cannot converted to date , then an IllegalArgumentException will be thrown. Since the header value is a String, it will throw the IllegalArgumentException
Which method is used to store file in the server ?
A GET
B PUT
C POST
D HEAD
Answer
B
A PUT method is used to store a file or data in the server. The request URI identifies the location in the server to store the file
Which character is used to separate the URI and query string ?
A ?
B &
C =
D ;
Answer
A
Choice A is correct. ? is used to separate the URI and query string. & is used to separate the name value pairs from each other
Which method is called when a context is initialized ?
A contextInitialize(ServletContextEvent)
B contextInitialized(HttpServletContextEvent)
C contextInitialized(ServletContextEvent)
D contextInitialized(SevletContext)
Answer
C
The contextInitialized(ServletContextEvent) method is called when a context is initialized
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
When the user types the request URL into the browser's location field or clicks on a hyperlink, the GET method is triggered. When the user submits the form with the method attribute as "GET" or without any method attribute, then also GET will invoked
Which interface is having method getSession() ?
A ServletSession.
B ServletRequest
C HttpServletRequest
D ServletResponse
E HttpServletResponse
Answer
C
The HttpServletRequest interface contains the method getSession().
Which exception will be thrown, when a servlet is unavailable temporarily ?
A ServletException
B UnavailableException
C IOException
D UnAccessibleException
Answer
B
The UnavailableException will be thrown, when a servlet is unavailable temporarily
What method will get executed on clicking the following code.?
<form method="GET" action="/TestServlet">
<input type="text" name="name">
<input type="submit" value="Submit">
</form>
A GET
B POST
C HEAD
D PUT
Answer
A
Which of the following listeners will be called when a context is destroyed?
A HttpServletContextListner
B HttpSessionListener
C ServletContextDestroyedListener
D ServletContextListener
Answer
D
The contextDestroyed(ServletContexEvent) method of ServletContextListener is called, when a context is destroyed