Академический Документы
Профессиональный Документы
Культура Документы
0 Mock Exams
by www.javabeat.net
a. While using HTTP POST method, the requested target resource must be an active
resource like Servlets or JSP.
b. HTTP POST method is a less secure method as data is directly available in the URL
portion of the client's request.
c. There is no limit in the amount of data being sent from the client to server in the
case of HTTP's GET method.
d. Only the Response Header will be sent to the client in the case of HTTP's HEAD
request.
2) Which of the following actions will trigger Http Request on the client side?
3) How to make a POST request when a user clicks the hyperlink in some HTML
page?
4) What method can be used to retrieve all the parameter names being sent as
part of the request by the client?
5) Which of the following statements are true about Java Servlets Technology?
a. HttpServletRequest.getWriter();
b. HttpServlerResponse.getCharacterWriter();
c. HttpServetRequest.getOutputStream()
d. HttpServletResonse.getWriter();
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
response.setContentType("text/html");
out.close();
}
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MultiPurposeServlet extends HttpServlet {
a. The Client Application calls the Servlet's load() method to load the Servlet.
b. The service() method will be called first followed by init() and destroy().
c. A new Servlet instance will be created by the Servlet Container upon client's
request.
d. If a client has done with a particular Servlet, then it should call the destroy method
to remove its instance from the Server address space.
e. None of the above.
10) What might be the output of the following program if a HTTP GET Request is
made on the Servlet object?
package scwcd14.chap01;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public ServletLifeCycleTest(){
System.out.println("ctor");
}
11) Which of the following methods can be used to return the supported HTTP
methods on a Web Server?
a. GET
b. PUT
c. POST
d. HEAD
e. OPTIONS
f. TRACE
12) Which of the following symbols is used to identifying the beginning of the
query string and the consecutive name-value pairs in a request?
a. ? and &
b. & and =
c. ? and =
d. % and &
a. TRACE
b. PUT
c. GET
d. OPTIONS
e. DELETE
14) Which of the following statements are true about HTTP methods?
a. Book marking a page cannot be done in the case of HTTP's GET request.
b. To obtain information from a database, use HTTP's POST method.
c. POST method can be submitted from with a form.
d. HEAD method can be used to retrieve only the response body.
e. None of the above.
15) Which of the following methods defines the correct signature of the doGet()
method?
a. HttpSession
b. HttpServletRequest
c. HttpServletResponse
d. ServletContext
18) What will be the value of the context path, Servlet path and the path info
elements, if the request path is music/Play/album1234?name='xyz' (assuming
that the context of the Web Application is 'music')?
CallingServlet
public void doGet(….)
{
PrintWriter out = respone.getWriter();
RequestDisparcher dispatcher =
request.getRequestDispatcher("/CalledServlet");
dispatcher.forward(req, res);
out.flush();
out.close();
}
CalledServlet
public void doGet(…)
{
PrintWriter out = respone.getWriter();
}
a. The output will be 'Output from Calling Servlet' followed by 'Output from Called
Servlet'.
b. The output will be 'Output from Called Servlet' followed by 'Output from Calling
Servlet'.
c. The program will throw IllegalStateException at run-time.
d. The program will output 'Output from Called Servlet'.
e. None of the above.
a. HttpServletRequest
b. HttpServletResponse
c. HttpSession
d. HttpServletConfig
e. ServletConfig
21) Which of the following statements are true about Error Handling?
a. An incorrectly formatted request message from client to server will result in HTTP
400 – Bad Request error message.
b. A response status code of 200 means that the request has been processed
successfully.
c. A response status code of 401 means that the request needs authentication.
d. All the above.
22) Which of the following statements are correct regarding Request types?
a. The doGet() method is generally used for retrieving information from the server.
b. POST request can send unlimited amount of data from client to server.
c. Data is given more protection in GET method rather than POST method.
d. All the above.
23) Which of the following statements are true about the OPTIONS method type?
a. The OPTIONS method can be used to identify the list of supported HTTP methods on
the Server.
b. The OPTIONS method can be used to identify the optional HTTP methods available
on the Server.
c. The response header as a result of making OPTIONS request will contain the header
attribute 'Allow' whose value contains the supported method types.
d. All the above.
24) Assume that you have an input control by name 'countries' that allows you to
select a list of country names. Which of the following code can be placed in the
Servlet to get the list of selected country names?
25) Pick out the following methods which are used to provide binary as well as
character stream for transferring data from Server to client?
26) Which of the following methods is used to get a list of attributes that were
previously set on the Request object?
a. List HttpServletRequest.getAttributeNames()
b. Enumeration HttpServletRequest.getAttributes()
c. Enumeration HttpServletRequest.getAttributeNames()
d. None of the above.
27) Pick out the context path, Servlet path and path information from the request
path '/books/Find/abcd?query=Java' (assuming that the context is 'books')?
28) An image file representing a company's logo has to be uploaded to the server.
Which of the following HTTP methods can be used in this situation?
a. doGet()
b. doPost()
c. doTrace()
d. doPut()
29) The body of the response will be blank if a HEAD request is made to server. Is
this statement correct?
a. Yes
b. No
a. Milliseconds
b. Seconds
c. Minutes
d. None of the above.
Answers
1) a and d.
Option b is incorrect as HTTP GET method is less secure because the Request information
will be available as part of the URL. Only a limited set of information can be passed through
HTTP's GET method, so option b is incorrect.
2) a, b, c and d.
There is a possibility of a Request being triggered for all the operations defined.
3) c.
There is no way to trigger a HTTP POST method while clicking a hyperlink, so option c is
correct.
4) a.
Using HttpServletRequest and by calling the method getParamterNames(), all the parameter
names can be retrieved.
5) a and b.
Option c is incorrect as the Java Servlets Specification doesn't provide support for handling
XML-based requests. While a Servlet instance is created upon first client's request or even
before that differs from Servlet Container's implementation.
6) d.
A Response object is needed for sending the response to the Client Application. For sending
character-based response, the method getWriter() has to be called on the
HttpServletResponse object. So option d is correct.
7) b.
The content type of the response should be called well before writing the response. So,
calling the method setContentType() doesn't have any effect as the response is committed
even before that. So option b is correct.
8) d.
It is possible to produce only one type of output (either character-based or binary-based),
so a run-time IllegalStateException will be thrown by the Servlet Container.
9) e.
None of the above statements are true.
10) b.
When a Servlet Container creates a new instance of the Servlet, the Servlet's constructor
will be invoked. After that the method init() will be invoked automatically by the Servlet
Container. Since the method is HTTP GET method, the doGet() will called and finally
followed by the destroy() method.
11) e
OPTIONS method is used to retrieve the supported methods for a Web Server.
12) a
Option a is correct. An example query string might be http://someServer.org?a=b&c=d
13) c
Option c is correct. These fields are normally used as part of conditional GET requests.
14) c
Option a is incorrect as book-marking a page can be achieved through HTTP GET method.
POST method is generally used to post information, and hence option b is incorrect. Option
d is incorrect because HEAD method can be used to retrieve the header values that are
associated with a response and not the body of the response.
15) e
None of the above. The doGet() method will take HttpServletRequest and
HttpServletResponse as arguments. So none of the four options are correct. The correct
method signature of the doGet() method in a class that extends HttpServlet may take any
of the following forms.
public void doGet(HttpServletRequest, HttpServletResponse)
Or
public void doGet(HttpServletRequest, HttpServletResponse) throws IOException,
ServletException.
16) a
Option a is correct. If we would have used request.getHeaders(""), then option b is correct.
17) b
Option b is correct. The method getRequestedSessionId() is available in the interface
HttpServletRequest
18) d
Option d is correct.
19) d
Option d is correct. Since the Servlet 'CallingServlet' has forwarded its control to the
'CalledServlet', any response that has been written already by the CallingServlet will be
simply ignored by the target Servlet.
20) a and e
Both the interfaces HttpServletRequest and ServletConfig defines the method
getServletContext().
21) d.
All the above options are correct.
22) a and b.
Options a and b are correct. Option c is incorrect since the request data is passed on
through the body in POST method and hence data protection is more in POST method rather
than in GET method.
23) a and c.
Options a and c are correct.
24) a.
Option a is correct. When a parameter corresponds to multiple values, then a call to
getParameterValues() by passing in the parameter name will return a string array
containing all the parameter values.
25) b.
Option b is correct. The methods getOutputStream() and getPrintWriter() defined on the
HttpResponse object can be used to send binary and character data to the clients.
26) c.
Option c is correct. The method getAttributeNames() defined on the HttpServletRequest
object is used to retrieve the attribute names which will be returned to the caller as an
Enumeration.
27) a.
Option a is correct. The context path, Servlet path and the path information are '/books',
'/Find' and '/abcd' respectively.
28) d.
Option d is correct since uploading a file on the server is more like publishing some
resource, for which case doPut() is the ideal method.
29) a.
Option a is correct. A HEAD request contains response in the form of headers only. There
will be no response body.
30) c.
The value specified for the 'session-timeout' tag is identified in minutes in the Deployment
Descriptor.
References
Group :: http://tech.groups.yahoo.com/group/JavaBeat_SCWCD/
Forums :: http://forums.javabeat.net/index.php?board=3.0
Books :: http://www.javabeat.net/cert/scwcd-books/