Time remaining
:
:
Test Status
SERVLETRANDOMTEST
Ques 1 :
You are creating a servlet that generates stock market graphs. You want to provide the web browser with precise information about the amount of data being sent in the response stream.
Which HttpServletResponse methods will you use to provide this information?
(A) response.setLength(numberOfBytes);
(B) response.setContentLength(numberOfBytes);
(C) response.setHeader("Length", numberOfBytes);
(D) response.setIntHeader("Length", numberOfBytes);
Ques 2 :
Your web page includes a Java SE v1.5 applet with the following declaration:
<object classid='clsid:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA' width='200' height='200'>
<param name='code' value='Applet.class' />
</object>
Which HTTP method is used to retrieve the applet code?
(A) POST
(B) GET
(C) PUT
(D) RETRIEVE
Ques 3 :
Which three are valid URL mappings to a servlet in a web deployment
descriptor? (Choose three.)
A. */* B. *.do
C. MyServlet D. /MyServlet
E. /MyServlet/* F. MyServlet/*.jsp
(A) A,D,B
(B) A,B,F
(C) B,D,E
(D) D,E,F
Ques 4 :
In which file do we define a servlet mapping?
(A) servlet.mappings
(B) servlet.xml
(C) web.xml
(D) Simple.java
Ques 5 :
The major difference between servlet and CGI is
(A) Servlets executes slower compared to CGI
(B) Servlets are thread based and CGI is process based
(C) Servlet has no platform specific API, where as CGI has
(D) All of the above
Ques 6 :
A servlet class thatâ??s used in a web application extends the
(A) HttpServlet class
(B) GenericServlet class
(C) both A and B
(D) only A
Ques 7 :
What's the difference between servlets and applets?
1.Servlets executes on Servers, where as Applets executes on Browser
2.Servlets have no GUI, where as an Applet has GUI
3.Servlets creates static web pages, where as Applets creates dynamic web pages
4.Servlets can handle only a single request, where as Applet can handle multiple requests
(A) 1,2 are correct
(B) 1,2,3 are correct
(C) 1,3 are correct
(D) 1,2,3,4 are correct
Ques 8 :
You need to create a servlet filter that stores all request headers to a
database for all requests to the web application's home page "/index.jsp". Which HttpServletRequest method allows you to retrieve all of the request headers?
(A) java.util.Iterator getRequestHeaders()
(B) java.util.Enumeration getHeaderNames()
(C) java.util.Iterator getHeaderNames()
(D) String[] getRequestHeaders()
Ques 9 :
For an HttpServletResponse response, which two create a custom header?(Choose two.)
A. response.setHeader("X-MyHeader", "34");
B. response.addHeader("X-MyHeader", "34");
C. response.setHeader(new HttpHeader("X-MyHeader", "34"));
D. response.addHeader(new HttpHeader("X-MyHeader", "34"));
E. response.addHeader(new ServletHeader("X-MyHeader", "34"));
F. response.setHeader(new ServletHeader("X-MyHeader", "34"));
(A) A,B
(B) B,C
(C) C,D
(D) B,D
Ques 10 :
what is servlet ?
(A) a
(B) b
(C) c
(D) d
Ques 11 :
Given a header in an HTTP request: X-Retries: 4
Which two retrieve the value of the header from a given HttpServletRequest request?
A. request.getHeader("X-Retries")
B. request.getIntHeader("X-Retries")
C. request.getRequestHeader("X-Retries")
D. request.getHeaders("X-Retries").get(0)
E. request.getRequestHeaders("X-Retries").get(0)
(A) A,B,E
(B) D,E
(C) A,B
(D) B,C,
Ques 12 :
Given an HttpServletRequest request and HttpServletResponse response,
which sets a cookie "username" with the value "joe" in a servlet?
(A) request.addCookie(new Cookie("username", "joe"));
(B) response.addCookie(new Cookie("username", "joe"));
(C) response.addCookie("username", "joe");
(D) request.addCookie("username", "joe");
Ques 13 :
Given an HttpSession session, a ServletRequest request, and a ServletContext context, which retrieves a URL to /WEB-INF/myconfig.xml within a web application?
(A) request.getResource("/WEB-INF/myconfig.xml")
(B) session.getResource("/WEB-INF/myconfig.xml")
(C) getClass().getResource("/WEB-INF/myconfig.xml")
(D) context.getResource("/WEB-INF/myconfig.xml")
Ques 14 :
Name the method defined in the HttpServletResponse class that may be used to set the content type. Select the one correct answer.
(A) setContent
(B) setType
(C) setContentType
(D) setResponseContentType
Ques 15 :
For a given ServletResponse response, which retrieve an object for
writing text data?
(A) response.getOutputWriter()
(B) response.getWriter()
(C) response.getWriter().getOutputStream()
(D) response.getWriter(Writer.OUTPUT_TEXT)
Ques 16 :
Given the following servlet mapping definition for the web application named 'secureapp',
<servlet>
<servlet-name>ProcessLoginData</servlet-name>
<servlet-class>DoLogin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ProcessLoginData</servlet-name>
<url-pattern>do/Login</url-pattern>
</servlet-mapping>
which of the following URLs will correctly request the Servlet?
(A) http://www.mywebapp.com/secureapp/do/Login?name="bob"
(B) http://www.mywebapp.com/secureapp/doLogin?name="bob"
(C) http://www.mywebapp.com/Login?name="bob"
(D) http://www.mywebapp.com/secureapp/Login?name="bob"
Ques 17 :
Which about WAR files are true?
(A) WAR files must be located in the web application library directory.
(B) WAR files must contain the web application deployment descriptor.
(C) WAR files must be created by using archive tools designed specifically for that purpose.
(D) The web container must serve the content of any META-INF directory located in a WAR file.
Ques 18 :
Which two actions protect a resource file from direct HTTP access within a web application? (Choose two.)
A. placing it in the /secure directory
B. placing it in the /WEB-INF directory
C. placing it in the /META-INF/secure directory
D. creating a
element within the deployment descriptor
E. creating a
element within the deployment descriptor
(A) A,C
(B) D,E
(C) B, C
(D) B,D
Ques 19 :
Given:
1. public void service(ServletRequest request,
2. ServletResponse response) {
3. ServletInputStream sis =
4. // insert code here
5. }
Which retrieves the binary input stream on line 4 ?
(A) request.getReader();
(B) request.getWriter();
(C) request.getResourceAsStream();
(D) request.getInputStream();
Ques 20 :
The method getWriter returns an object of type PrintWriter. This class has println methods to generate output. Which of these classes define the getWriter method? Select the one correct answer.
(A) HttpServletRequest
(B) ServletConfig
(C) HttpServletResponse
(D) ServletContext
Submit Answer
Don't Refresh the Page !! ...