Tuesday, January 16, 2007

SCWCD 1.4 Mock Questions - 2

SCWCD 1.4 Mock Exams and Priactice Questions

1.Assume that the following header is present in a request sent to a servlet:
Accept: image/gif, image/jpeg, image/bmp
What will be returned when the servlet code calls request.getHeader("Accept")?

Select 1 correct option.
A.A Header object containing, name as "Accept" and value as "image/gif".
B.A Header object containing, name as "Accept" and value as "image/gif, image/jpeg, image/bmp".
C.A String array containing "image/gif""
D.A String containing "image/gif, image/jpeg, image/bmp".
E.A String array containing "image/gif", "image/jpeg", image/bmp"

ANS : D

2. You need to send large amount of binary data from the browser to a servlet to be processed. (Say, you want to attach a file while sending email through a web based system). What HTTP method would you use?

Select 1 correct option.

A.GET
B.POST
C.HEAD
D.HIDDEN
E.PUT

ANS : B

3.Which of the following is a possible way to configure an HttpSessionAttributeListener?

Select 1 correct option.

A.By calling HttpSession.addAttributeListener(...)
B.By calling HttpSession.addHttpSessionAttributeListener(...)
C.An object of a class implementing this interface is automatically configured when it is added to the session.
D.None of these.

ANS : D

4.Servlet Container calls the init method on a servlet instance ...

Select 1 correct option.

A.For each request to the servlet
B.For each request to the servlet that causes a new session to be created.
C.For each request to the servlet that causes a new thread to be created.
D.Only once in the life time of the servlet instance
E.If the request is from the user whose session has expired.
F.Initialy when the servlet instance is create and then at request time if the request is from the user whose session has expired.

ANS : D

5.Which of the following methods may be called on a custom tag handler that implements IterationTag interface?

Select 2 correct options.

A.doStartTag
B.doBodyTag
C.doAfterBody
D.doInitBody
E.doEvalBody

ANS : A,C

6.Which of the following elements of web.xml defines a mapping between a servlet and a URL pattern?

Select 1 correct option.

A.mapping
B.servlet-url
C.url_mapping
D.url_pattern
E.servlet-mapping

ANS : E

7.Following is the code for doGet() method of TestServlet. Which of the given statements about it are correct?

public void doGet(HttpServletRequest req, HttpServletResponse res)

{

try

{

RequestDispatcher rd = this.getServletContext().getRequestDispatcher("Login.jsp"); // 1

rd.forward(req, res); // 2

}

catch(Exception e)

{

e.printStackTrace();

}

}

Select 2 correct options.
A.This will not compile.
B.This will compile but will not work as expected.
C.This code will work just fine.
D.It will compile but not work properly if //1 is replaced with: RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");
E.It will compile and will work properly if //1 is replaced with: RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");

ANS : C,E

8.Consider the web.xml snippet shown in the exhibit.
Now consider the code for a jsp file named unprotected.jsp:

<html>

<body>

<jsp:include page="/jsp/protected.jsp" />

</body>

</html>

Which of the following statements hold true when unprotected.jsp is requested by an unauthorized user?

<web-app>

...

<security-constraint>

<web-resource-collection>

<web-resource-name>test</web-resource-name>

<url-pattern>/jsp/protected.jsp</url-pattern>

</web-resource-collection>

<auth-constraint>

<role-name>manager</role-name>

</auth-constraint>

</security-constraint>

...

</web-app>

Select 1 correct option.
A.The user will be prompted to enter user name and password
B.An exception will be thrown
C.protected.jsp will be executed but it's output will not be included in the response
D.The call to include will be ignored
E.None of these

ANS : E

9.Which of the following JSP elements can have a <jsp:param ...> element in its body?

Select 1 correct option.
A.<jsp:include ...>
B.<%@ include ...>
C.<jsp:directive.include .../>
D.<%@ forward ...>
E.<jsp:action ...>

ANS : A

10.Which of the following implicit variables should be used by a jsp page
to access a resource and to forward a request to another jsp page?

Select 1 correct option.
A.pageContext and config
B.application and config
C.config and pageContext
D.application for both
E.config for both

ANS : D

11.In which of the following situations will a session be definitely invalidated?

Select 3 correct options.
A.The container is shutdown and brought up again
B.No request comes from the client for more than "session timeout" period.
C.A servlet explicitly calls invalidate() on a session object.
D.A servlet explicitly calls invalidate() on a session object.

ANS : B,C,D

12.Your jsp page uses classes from java.util package. Which of the following statement would allow you to import the package?

Select 1 correct option
A.<%@import java.util.* %>
B.<%import="java.util.*"@%>
C.<%@ page import="java.util.*"%>
D.<%@ page java="java.util.*"@%>
E.<%@ page import="java.util.*"@%>

ANS : C

13.Consider the following contents for two JSP files:
In file companyhome.jsp:

<html><body>

Welcome to ABC Corp!

<%@ page errorPage="simpleerrorhandler.jsp" %>

<%@ include file="companynews.jsp" %>

</body></html>



In file companynews.jsp:

<%@ page errorPage="advancederrorhandler.jsp" %>

<h3>Todays News</h3>


Which of the following statements are correct?
Select 1 correct option
A.When companyhome.jsp is requested, the output will contain "welcome..." as well as "Todays News"
B.companyhome.jsp will not compile
C.companynews.jsp will not compile
D.Both the files will compile but will throw an exception at runtime.
E.None of these

ANS : B

14.Which method of RegisterServlet will be called when the user clicks on
"Submit" button for the following form. Assume that RegisterServlet
<html>

<body>

<form action="/myapp/RegisterServlet">

<input type="text" name="method" value="POST">

<input type="text" name="name">

<input type="password" name="password">

<input type="submit" value="POST">

</form>

</body>

</html>
Select 1 correct option.
A.servicePost(HttpRequest, HttpResponse);
B.doPOST(HttpRequest, HttpResponse);
C.post(HttpRequest, HttpResponse);
D.doPost(HttpRequest, HttpResponse);
E.None of the above.

ANS : E

15.You are building the server side of an application and you are finalizing the interfaces that you will provide to the client side.
But you have not yet decided whether the business rules will be fully implemented as stored procedures or in the java code. Which design
pattern you should use to mitigate this concern?

Select 1 correct option.
A.Model View Controller
B.Data Access Object
C.Business Delegate
D.Facade
E.Transfer Object

ANS : C

16.Which of the following XML frgaments correctly define the <login-config> element of web.xml?

(See Exhibit.)

1.

<login-config>

<auth-method>CLIENT-CERT</auth-method>

<realm-name>test</realm-name>

</login-config>



2.

<login-config>

<auth-method>CLIENT-CERT</auth-method>

<realm-name>test</realm-name>

<form-login-config>

<form-login-page>/jsp/login.jsp</form-login-page>

<form-error-page>/jsp/error.jsp</form-error-page>

</form-login-config>

</login-config>



3.

<login-config>

<auth-method>FORM</auth-method>

<realm-name>test</realm-name>

<form-login-config>

<form-login-page>/jsp/login.jsp</form-login-page>

<form-error-page>/jsp/error.jsp</form-error-page>

</form-login-config>

</login-config>



4.

<login-config>

<auth-method>FORM</auth-method>

<realm-name>test</realm-name>

</login-config>



5.

<login-config>

<auth-method>SECURE</auth-method>

<realm-name>test</realm-name>

</login-config>

Select 3 correct options.
A.1
B.2
C.3
D.4
E.5

ANS : A,B,C

17.What are the following deployment descriptor elements used for?

<login-config>

<security-constraint>

<security-role>

Select 1 correct option.
A.Authorization
B.Authentication
C.Privacy
D.Authentication and Authorization
E.Data integrity.

ANS : D

18.You want to do some calculations within the object whenever it is added to the session. What would you do to accomplish this?

Select 1 correct option
A.Make the class of the object implement HttpSessionBindingListener
B.Configure a HttpSessionAttributeListener in deployment descriptor
C.Make the class of the object implement HttpSessionListener
D.Configure a HttpSessionActivationListener in deployment descriptor
E.Only way is to configure a HttpSessionAttributeListener in the deployment descriptor

ANS : A

19.GET method is not suitable for which of the following operations?

Select 2 correct option.
A.Retrieving an image
B.Retrieving a zip file
C.Submitting a form not containing login or other critcal information
D.Submitting a login form
E.Updating a database

ANS : D,E

20.In the case of JSP pages, what is the type of the implicit variable 'out'?

Select 1 correct option.
A.OutputStream
B.PrintStream
C.PrintWriter
D.JspWriter
E.DataOutputStream

ANS : D

21. Match the following.

Comment
directive
declaration
scriptlet
Custom tag
expression

<tags:simple name='bob' />
<%=request.getParameter("name")%>
<%request.getParameter("name");%>
<jsp:directive.include file='hello.jsp' />
<%-- String x = "123" --%>
<%!String x = "123"; %>

ANS :
comment <%-- String x = "123" --%>
directive <jsp:directive.include file='hello.jsp' />
declaration <%!String x = "123"; %>
scriptlet <%request.getParameter("name");%>
custom tag <tags:simple name='bob' />
expression <%=request.getParameter("name")%>


22.Consider the following tag occuring in a JSP page:
<%@page import="java.util.*"%>
Which of the following is the XML equivalent of the above tag?
Select 1 correct option.
A.<directive.page import="java.util.*"/>
B.<page import="java.util.*"/>
C.<%jsp:directive.page import="java.util.*"%>
D.<jsp:page import="java.util.*"/>
E.<jsp:directive.page import="java.util.*"/>

ANS : E

23.Your servlet may throw IOException while processing a request. You want to define an error page in your deployment descriptor so that whenever
IOException is thrown, this page is serviced to the browser. Which of the following XML fragments correctly specify the mapping:

1.

<error-page>

<exception>java.io.IOException</exception>

<location>/html/Test.html</location>

</error-page>



2.

<error-page>

<exception-class>java.io.IOException</exception-class>

<location>/html/Test.html</location>

</error-page>



3.

<error-page>

<exception-type>java.io.IOException</exception-type>

<page-location>/html/Test.html</page-location>

</error-page>



4.

<error-page>

<exception-type>java.io.IOException</exception-type>

<location>/Enthuse/html/Test.html</location>

</error-page>



5.

<exception>

<exception-type>java.io.IOException</exception-type>

<location>/Enthuse/html/Test.html</location>

</exception>

A.1
B.2
C.3
D.4
E.5

ANS : D

24.How can you ensure the continuity of the session while using HttpServletResponse.sendRedirect() method when cookies are not
supported by the client?

Select 1 correct option
A.By using hidden parameters.
B.By enconding the redirect path with HttpServletResponse.encodeRedirectURL() method.
C.By using HttpSession.encodeURL() method.
D.By using HttpServletRequest.encodeURL() method.
E.By using HttpServletResponse.encodeURL() method

ANS : B

25.Which of the following XML fragments correctly defines a role named "manager" in web.xml?
1.

<security-role>manager</security-role>

2.

<security-role rolename=manager></security-role>

3.

<security>

<role-name>manager</role-name>

</security>

4.

<security-role>

<role-name>manager</role-name>

</security-role>

Select 1 correct option.

A.1
B.2
C.3
D.4


ANS : D

26.Which of the following methods of HttpServletRequest can be used to retrieve the parameter values sent from the browser?

Select 2 correct options
A.getParameter(String name);
B.getParameter(String name, String defaultValue);
C.getParameterNames();
D.getParameterValues(String name);
E.getParameters(String name);

ANS : A,D

27.Consider the code for the web.xml for a web application (See exhibit).
Assume that a request: http://localhost:8080/test/aaa/abc.a is sent to this web application named test.
Which of the following statements are correct?

<?xml version="1.0" encoding="ISO-8859-1"?>

<!-- Assume that DOCTYPE is valid -->

<!DOCTYPE web-app

PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.4//EN"

"http://java.sun.com/dtd/web-app_2_4.dtd">

<web-app>

<servlet>

<servlet-name>TestServlet</servlet-name>

<jsp-file>/requestinfo.jsp</jsp-file>

</servlet>

<servlet-mapping>

<servlet-name>TestServlet</servlet-name>

<url-pattern>*.a</url-pattern>

</servlet-mapping>

</web-app>

Select 1 correct option.
A.Path Info of the request will be /aaa/abc.a
B.RequestPath of this request will be /test//aaa/abc.a
C.ContextPath of this request will be /test/aaa
D.This request will be serviced by requestinfo.jsp
E.None of these.

ANS : D

28.You are using a tag library with prefix "sequenceengine" which supports a tag named "fib". This tag expects a parameter named "limit" of type
int. Which of the following is a correct use of this tag?

Select 1 correct option.
A.<sequenceengine:fib>20</sequenceengine:fib>
B.<fib:sequenceengine>20</fib:sequenceengine>
C.<sequenceengine:fib attribute-name="limit" attribute-value="20"></sequenceengine:fib>
D.<sequenceengine:fib limit="20"></sequenceengine:fib>
E.<fib:sequenceengine limit="20"></fib:sequenceengine>

ANS : D

29.How can you redirect the request from a servlet to another resource if the servlet encounters an exception?

Select 2 correct options
A.This cannot be done unless the exception is caught in the servlet.
B.By specifying a mapping between exception class and the resource in web.xml
C.This can be done only if the exception is a subclass of javax.servlet.ServletException
D.This can be done even if the exact class of the exception is not known at compile time

ANS : B,D

30.Which of the given options correctly declare a useBean tag?

Select 3 correct options
A.<jsp:useBean id="user" class="myco.util.User" />
B.<jsp:useBean id="user" type="myco.interfaces.IUser" />
C.<jsp:useBean name="user" class="myco.util.User" />
D.<jsp:useBean id="user" beanName="myco.User" class="myco.util.User" />
E.<jsp:useBean id="user" beanName="myco.User" type="myco.interfaces.IUser" />

ANS : A,B,E
















No comments: