Tuesday, January 16, 2007

SCWCD 1.4 Mock Questions - 6

SCWCD 1.4 Mock Exams and Priactice Questions

1. A web.xml for a web application contains the following:

<login-config>

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

<realm-name>sales</realm-name>

<form-login-config>

<form-login-page>/formlogin.html</form-login-page>

<form-error-page>/formerror.html</form-error-page>

</form-login-config>

</login-config>

What should formlogin.html contain?

Select 1 correct option.
A. A base 64 encoded username and password
B. A header that prompts the browser to pop up the username/password dialog
C. A form that POSTs to j_security_check url
D. Any html page that does not require the user to login
E. Code to redirect the user to the login page
ANS : C
 2. Which of the following are valid values for the <auth-method> element of the deployment descriptor? 

Select 2 correct options.

A. DIGEST
B. CLIENT-CERT
C. SECURE
D. NONE

ANS : A,B

3.You want to add third party classes bundled as a JAR file and a couple of your own classes to a web application. Which directories would you place them in?

Select 1 correct option.
A. AR file in WEB-INF/lib and class files in WEB-INF/classes
B. JAR file in WEB-INF/classes/lib and class files in WEB-INF/classes
C. both in WEB-INF/classes
D. both in WEB-INF
E. JAR file in WEB-INF/jars and class files in WEB-INF/classes
ANS : A

4.Write the name of the deployment descriptor tag that allows you to write a description for a <context-param> element. Please do not add angle brackets.

ANS : description or <description>

5. Which of the following statements are correct?

Select 3 correct options.
A. Authorization means determining whether one has access to a particular resource or not

B. Authentication means determining whether one has access to a particular resource or not
C. Authentication means proving whether one is what one claims to be
D. Data Integrity means that the data is not modified in transit between the sender and the receiver
E. Data Integrity means that the data cannot be viewed by anybody other than it's intended recipient

ANS :A,C,D

6. Your web application named "FWorks" uses SpecialMath.class. This is an unbundled class and is not contained in any jar file.
Where will you keep this class file?

Select 1 correct option.
A. FWorks/WEB-INF

B. FWorks/WEB-INF/classes
C. FWorks/WEB-INF/lib/classes
D. FWorks/classes
E. FWorks/WEB-INF/lib

ANS : B

7. Which jsp tag can be used to retrieve a property of a bean?

Select 1 correct option.
A. jsp:useBean

B. jsp:useBean.property
C. jsp:useBean.getProperty
D. jsp:getProperty
E. jsp:property

ANS : D

8. Associate the events with appropriate listener interface:

Drag and drop the matching listener.
i. session is activated or passivated
ii. session is timed out
iii. an attribute is replaced in the session
iv. a session is created

Select items
A.HttpSessionListener
B.HttpSessionBindingListener
C.HttpSessionActivationListener
D.None of these

ANS :
i. session is activated or passivated -C
ii. session is timed out -A,B
iii. an attribute is replaced in the session - D
iv. a session is created - A


9. Given the code of doGet() method of a servlet (see exhibit).
The data should be sent to the client only if loginUser() returns a non null userid. Otherwise a status of SC_FORBIDDEN should be sent.
What can be placed at //1 to fulfill this requirement?
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException

{

String userId = loginUser(req); //this method takes the credentials from the request and logs in the user.

if(userId == null)

{

// 1 Should send SC_FORBIDDEN

}

else

{

PrintWriter out = response.getWriter();

generateAndPublishData(out); //this method writes appropriate date to out.

}

}

Select 3 correct options
A. req.getRequestDispatcher("errorpage.jsp").dispatch(req, res, HttpServletResponse.SC_FORBIDDEN);
B. throw new ServletException(HttpServletResponse.SC_FORBIDDEN);
C. res.setStatus(HttpServletResponse.SC_FORBIDDEN);
D. res.sendError(HttpServletResponse.SC_FORBIDDEN, "You are not authorized.");
E. res.sendError(HttpServletResponse.SC_FORBIDDEN);

ANS : C,D,E

10. Which of the following elements of web.xml affect the whole web application instead of a specific servlet?

Select 1 correct option
A.content-type
B.init-param
C.listener
D.application
E.app-config

ANS : C

11.Which of the following statements regarding <jsp:useBean> action are correct?

Select 2 correct options.
A.It must have an 'id' attribute.
B.If 'beanName' attribute is present, 'type' must also be present.
C.It must have a 'scope' attribute.
D.If 'class' attribute is present, 'type' must also be present.

ANS: A,B

12. Identify the implicit objects available to EL expressions.

Select 4 correct options
A.requestScope
B.application
C.header
D.page
E.pageScope
F.pageContext
ANS : A,C,E,F

13. Populate the blanks with appropriate examples given in the options.

comment
directive
declaration
scriptlet
custom tag
expression

select the items
A. <tags:simple name='bob' />
B.<%=request.getParameter("name")%>
C.<%request.getParameter("name");%>
D.<jsp:directive.include file='hello.jsp' />
E.<%-- String x = "123" --%>
F.<%!String x = "123"; %>

ANS:
comment -E
directive - D
declaration -F
scriptlet -C
custom tag -A
expression - B

14. 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>

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

ANS : 4

15. Which of the following statements is correct regarding HttpSessionBindingListener interface?

Select 1 correct option.
A.The valueBound() method is called BEFORE the object becomes accessible through HttpSession.getAttribute()
B.The valueUnbound() method is called BEFORE the object is removed from the HttpSession
C.The valueReplaced() method is called BEFORE the object is replaced with another object in the session
D.None of these

ANS : A

16. Consider the following HTML code. Which method of MyFirstServlet will be invoked when you click on the url shown by the page?

<html>

<body>

<a href="/myapp/servlet/MyFirstServlet">Make me say Hello World!</a>

</body>

<html>

Select 1 correct option.
A.doGet
B.doGET
C.post
D.doPost
E.doPOST

ANS : A

17. Your jsp page connects to the database and retrieves the data. It also formats the data and displays it to the client. Any of these operations
can throw exceptions but you do not want to catch them all in this page and so you have written another jsp page that is meant to handle any
kind of exceptions. How would you associate that error page named "error.jsp" with this page?
Select 2 correct options.
A.Add <%@errorPage="error.jsp"%> in this page
B.Add <%@page errorPage="error.jsp"%> in this page
C.Add <%@page isErrorPage="true"%> in error.jsp
D.Add <%@isErrorPage="true"%> in error.jsp

ANS: B,C

18. You have to send a gif image to the client as a response to a request. How will you acquire the 'out' variable to do this?

Select 1 correct option.
A.PrintWriter out = response.getPrintWriter();
B.PrintWriter out = response.getWriter();
C.FileOutputStream out = response.getServletOutputStream();
D.ServletOutputStream out = response.getOutputStream();
F.ServletOutputStream out = response.getServletOutputStream("image/gif");

ANS : D

19. Which of the given statements are correct regarding the following JSP page code?

<jsp:useBean id="mystring" class="java.lang.String" />

<jsp:setProperty name="mystring" property="*" />

<%=mystring%>

Assume that the request for this page contains a parameter mystring=hello.

Select 1 correct option.
A.It will print ""
B.It will print "hello"
C.It will not compile
D.It will throw exception at runtime

ANS : A

20. Select the correct sequence of actions that a servlet container performs before servicing any request.

A.Instantiate listeners defined in the deployment descriptor
B.Initialize filters defined in the deployment descriptor
C.Initialize servlets that are set to load on startup
D.Call the contextInitialized method on the listeners implementing ServletContextListener interface

ANS: A,D,B,C

21.Which of the following is a valid life cycle event listener interface but is NOT configured in the web.xml?

Select 1 correct option.
A.HttpSessionListener
B.SessionActivationListener
C.HttpSessionBindingListener
D.ContextAttributeListener
E.SessionAttributeListener

ANS : C

22. How can you retrieve the data sent by the FORM displayed by following HTML page code?

<html>

<body>

<form action="/myapp/SaveServlet" method="POST">

<input type="file" name="name">

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

</form>

</body>

</html>

Select 2 correct options.
A.
request.getParameter("name");
B.request.getAttribute("name");
C.request.getInputStream();
D.request.getReader();
E.request.getFileInputStream();

ANS: C,D
.
23. Consider the code for a java bean (See exhibit):

Also consider the following code for ticketview.jsp:
<html>

<head></head>

<body>

<jsp:useBean id="ticket" class="TicketBean"/>

<jsp:setProperty name="ticket" property="*"/>

Name : <%=ticket.getName()%>

Price : <%=ticket.getPrice()%>

</body>

<html>

Which of the following lines will be in the output of the jsp page, if it is accessed through URL:

http://servername/ticketview.jsp?name=AAA


public class TicketBean

{

int price;

String name;

// assume usual getters and setters.

}
Select 2 correct options.
A.Name : AAA
B.Price : 0
C.An exception stack trace.
D.Only this will be present:- Name : AAA
E.Translation error

ANS : A,B


24. Identify two statements that are doing the same task.

Select 2 correct options.
A.<%= ticket.price %>
B.<%= ticket.getPrice() %>
C.<jsp:getProperty name="ticket" property="price" />
D.<% ticket.getPrice() %>
E.<%= ticket.getPrice(); %>

ANS : B,C

25. A business group needs certain data report from the database in XML format. For this purpose, a developer creates a servlet that pulls the
data from the DB, converts it into an XML report and sends it to the browser. To ensure security, the servlet also encrypts the reports.
A few months later, the developer is asked to create several such servlets for different kind of reports. The developer was about to copy
paste all the original servlet code for each servlet but he realized that he need not replicate the code for encryption if he uses .........pattern.

Select 1 correct option.
A.Session Facade
B.Service Locator
C.Intercepting Filter
D.Business Delegate

ANS : C

26. Which of the following methods will be invoked if the doStartTag() method of a tag returns Tag.SKIP_BODY?
Select 1 correct option.
A.doAfterBody()
B.doBody()
C.skipBody()
D.doEndTag()
E.None of these

ANS :D

27.Which of the following elements is required for a valid <taglib> tag in web.xml?

Select 1 correct option.
A.<uri>
B.<tag-uri>
C.<uri-name>
D.<uri-location>
E.<taglib-uri>

ANS: E

28. Which of the following properties are governed by a sub element of
<user-data-constraint> element of the deployment descriptor?

Select 2 correct options.
A.data integrity
B.authorization
C.authentication
D.confidentiality
E.login type
ANS :A,D
29. Which of the following user actions would cause the browser to issue a HTTP GET request to the web server?

Select 3 correct options.
A.Mouse click on a hyperlink.
B.User types into the address location of the browser and presses enter.
C.User presses the "Submit" button of a FORM that does not have the method attribute.
D.User presses the "Submit" button of any FORM
E.None of the above

ANS : A,B,C

30. 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

No comments: