SCWCD-5

04/14/2008

0 Comments

 

What will be the output , when accessing the following servlet

import javax.servlet.http.*;

public class TestServlet extends HttpServlet {

}

A Blank Screen
B Runtime Error
C Compiler Error
D HTTP 405, error message.
D HTTP 404, error message.

Answer

D
HttpServlet is providing a default implementation for Http Methods, it will not give any compile time or run time error. But the default implementation will give an HTTP 405 error message (At least in BEA Web logic server).


What is the return type of request.getParameterValues()?

A String
B Vector
C String[]
D ArrayList

Answer

C
getParameterValues() returns an array o f String objects containing all of the values the given request parameter has, or null if the parameter does not exist

Which method is used to get the HTTP method of the request?

A request.getMethod();
B request.getForm()
C request.getHttpMethod()
D request.getFormMethod()

Answer

A
Return the name of the HTTP method with which the servlet request was made , such as GET, POST etc..


In order to redirect a servlet , what is the method used ?

A response.sendRedirect(java.net.URL)
B response.sendRedirect(String)
C response.sendURL(java.net.URL)
D response.sendURL(String)

Answer

B
response.sendRedirect(String) is used for redirecting response to another URL.


Which method is used for finding out what the server is receiving ?

A GET
B POST
C PUT
D TRACE

Answer

D
TRACE gives information about what the server is receiving . Used mainly for debugging only.

Which methods are used to set a header? Choose all that apply.

A response.setHeader()
B response.addHeader()
C response.addStringHeader()
D response.setDateHeader()
E response.addDateHeader()

Answer

A, B, D and E
setHeader and addHeader adds a header value. But setHeader overwrites existing value if one exist where as addHeader adds one more value for this header. The setDateHeader and addDateHeader are used fro setting date headers.

What will be the output of the following expression ?
<%= System.out.println("Hello.."); %>

A Hello..
B System.out.println("Hello..")
C Compiler Error
D java.io.PrintStream@1ccf82Hello

Answer

C
We cannot use 'void' in JSP expression. All JSP expression should return a valid type except void.


Which method is used to log messages from a servlet ?

A getServletConfig().log();
B getServletContext().log();
C getServletConfig().log(String)
D getServletContext().log(String)

Answer

B and D
The log() method is defined in ServletContext interface.


What are the mandatory sub elements of <login-config> element ?

A <auth-method>
B <form-login-config>
C <login>
D No mandatory sub element.

Answer

D
The <login-config> element does not define any mandatory sub element.

What methods are used to get the header information from the client ? Select all that apply.

A request.getHeader(String)
B request.getFormHeader(String)
C request.getIntHeader(String)
D request.getDateHeader(String)

Answer

A, C and D
(String headername) is used to get the header from the client. The getDateHeader is used for getting date headers. It will throw an IllegalArgumentException , if the header cannot be converted to a date. getIntHeader will return the value of specified header as an int. if the specified header cannot be converted to an int , it till throw a NumberFormatException.

 


Comments




Leave a Reply

    SCWCD Sets


    Archives

    May 2008
    April 2008