Showing posts with label SCWCD Mock Exams. Show all posts
Showing posts with label SCWCD Mock Exams. Show all posts

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

SCWCD 1.4 Mock Questions - 5

SCWCD 1.4 Mock Exams and Priactice Questions

1.you are using a tag library with prefix "generator", which supports a tag named "random". This tag generates a random number and sets it to a variable named "value". Which of the following will output this value in the page?

Select 1 correct option.
A.<generator:random>value</generator:random>
B.<generator:random><%=value%></generator:random>
C.<generator:random><% int value;%> <%=value%></generator:random>
D.<generator:random><%getParameter("value")%></generator:random>
E.None of the above

ANS : B

2. Which of the following pairs of HTTP method and HttpServlet class method are a valid combination for a request and the request handler method?

Select 2 correct options.
A.GET - service()
B.POST - doPost()
C.GET - doPost()
D.GET - doGet()
E.POST - service()

ANS : B,D

3.You want to get notified whenever there is a change in the attribute list of the ServletContext of your web application. Which listener interface would you implement?

Select 1 correct option
A.ServletListener
B.ServletContextListener
C.ServletContextAttributeListener
D.HttpServletContextListener
E.HttpServletListener

ANS : C

4.A JSP page myerror.jsp has been invoked as a result of an exception from another JSP page. How can you access the Throwable object that refers to the exception in myerror.jsp?

Select 1 correct option.
A.Using the implicit variable error
B.Using the implicit variable request.error
C.Using the implicit variable exception
D.Using the implicit variable throwable
E.None of these because the class of the implicit variable is not java.lang.Throwable

ANS : C

5.Which of the following are valid return values for doStartTag() method?

Select 3 correct options.
A.BodyTag.SKIP_BODY
B.Tag.SKIP
C.Tag.EVAL_BODY_INCLUDE
D.Tag.EVAL_BODY_AGAIN
E.BodyTag.EVAL_BODY_BUFFERED

ANS : A,C,E

6.Which of the following statements are correct for a custom tag that can take any number of arbitrary attributes?

Select 2 correct options.
A.The body-content element for the tag in the TLD file must have a value of JSP.
B.The tag handler must implement the method setAttribute(String key, String value).
C.The tag element in the TLD file for the tag must have <dynamic-attributes>true</dynamic-attributes>.
D.The class implementing the tag must implement javax.servlet.jsp.tagext.DynamicAttributes interface.
E.Dynamic attributes cannot have request time expression values
F.A JSP page sets a dynamic attribute using <jsp:setDynamicAttribute> action

ANS : C,D

7.Assuming that <%@ taglib uri="/utils" prefix="util" %> occurs before the use of the custom tags of the tag library named utils, identify the possibly valid empty custom tag declarations. (Assume that transpose is a valid tag in the given tag library.)

Select 2 correct options.
A.<util:transpose/>
B.<util:transpose></util:transpose>
C.<util:transpose>200</util:transpose>
D.<taglib:util:transpose />
E.None of the above is correct as every tag has to
have a body

ANS : A,B

8.Which of the following defines the class name of a tag in a TLD?

Select 1 correct option.
A.tag-class-name
B.tag-class
C.class-name
D.class

ANS : B

9.What should be the value of <body-content> subelement of element <tag> in a TLD file if the tag should not have any contents as its body?

Select 1 correct option.
A.blank
B.empty
C.null
D.false
E.The <body-content> subelement itself should be absent

ANS : B

10.Which interface and method should be used to retrieve a servlet initialization parameter value?

Select 1 correct option.
A.ServletConfig : getParameter(String name)
B.ServletConfig : getInitParameter(String name)
C.ServletContext : getInitParameter(String name))
D.ServletConfig : getInitParameters(String name)
E.ServletConfig : getInitParameterNames(String name)

ANS : B

11. You need to put a com.enthu.User bean referred by 'userBean' variable in request scope with an ID of "user" from within a servlet. Which of the following statements accomplishes this task?

Select 1 correct option.
A.request.put("user", userBean);
B.request.add(userBean, "user");
C.request.putAttribute("user", userBean);
D.request.setAttribute("user", userBean);
E.request.setParameter(userBean, "user");
F.request.put(userBean, "user");

ANS : D

12.Consider the following code:
public class MyTagHandler extends TagSupport 

{

public int doStartTag() throws JspException

{

try

{

//insert code here

}

catch(Exception e){ }

return super.doStartTag();

}

}
Which of the following options, when inserted in the above code causes the value "hello" to be output?

Select 1 correct option.
A.JspWriter out = pageContext.getOut();
out.print("hello");
B.JspWriter out = pageContext.getWriter();
out.print("hello");
C.JspWriter out = getPageContext().getWriter();
out.print("hello");
D.JspWriter out = new JspWriter(pageContext.getWriter());
out.print("hello");
E.JspWriter out = getPageContext().getOut();
out.print("hello");

ANS : A

13.Which of the following is a correct JSP declaration for a variable of class java.util.Date?

Select 1 correct option.

A.<%! Date d = new Date() %>
B.<%@ Date d = new Date() %>
C.<%! Date d = new Date(); %>
D.<%$ Date d = new Date() %>

ANS : C

14.Which method can be invoked on a session object so that it is never invalidated by the servlet container automatically?

Select 1 correct option.
A.setTimeOut(-1)
B.setTimeOut(Integer.MAX_INT)
C.setTimeOut(0)
D.setMaxInactiveInterval(-1)
E.setMaxInactiveInterval(Integer.MAX_INT)

ANS : D

15.Which of the following elements are mandatory under the <web-app> element of a deployment descriptor?

Select 1 correct option.
A.<doctype>
B.<app-name>
C.<servlet>
D.<doc-root>
E.None of these.

ANS : E

16.Which of the following implicit variables should be used by a jsp page to access a page initialization parameter?

Select 1 correct option.
A.pageContext
B.application
C.config
D.context
E.page

ANS : C

17.You are given a tag library that has:
1. A tag named getMenu that takes an attribute 'subject' which can be a dynamic value.
2. A tag named getHeading that takes an attribute 'report'.
Which of the following are correct uses of this library?

Select 3 correct options.
A.<myTL:getMenu subject="Finance"/>
B.<myTL:getMenu subject="<myTL:getHeading report=1/>"/>
C.<myTL:getMenu subject='<myTL:getHeading report="1"/>'/>
D.<% String subject="HR";%> <myTL:getMenu subject="<%=subject%>"/>
E.<myTL:getHeading report="2"/>

ANS : A,D,E

18.You are working with a tag library which is packaged in a jar file named htmlutil.jar.
This jar file also contains a META-INF/htmlutil.tld file which has a uri element as follows:
<uri>http://www.xyzcorp.com/htmlLib</uri>
What can you do to access this library from your JSP pages
Select 1 correct option.
A.You must define the <taglib> element in the web.xml to specify
the mapping for <taglib-uri> to the location of this jar file.
B.There is no need for the <taglib> element in the web.xml, however, you need the taglib directive in the JSP pages.
C.You can directly access the tags of this library from the JSP pages without any taglib directive.
D.You do not need the taglib directive, but you do need to specify the <taglib> element in the web.xml.
E.None of these.

ANS : B

19.Which of the following are valid iteration mechanisms in jsp?
1.
<% int i = 0;
while(i<5)
{
"Hello World"
i++;
} %>

2.
<jsp:for loop='5'>
"Hello World"
</jsp:for>

3.
<% int i = 0;
for(;i<5; i++)
{ %>
"Hello World";
<% i++;
}
%>

4.
<table>
<% Iterator it = aSet.iterator();
int i = 0;
while(it.hasNext())
{
out.println("<tr><td>"+(++i)+"</td>");
out.println("<td>"+it.next()+</td></tr>");
}
%>
</table>

5.
<jsp:scriptlet>
for(int i=0; i<5; i++)
{
</jsp:scriptlet>
<jsp:text>"Hello World!"</jsp:text>
<jsp:scriptlet>
}
</jsp:scriptlet>

Select 3 correct option.

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

ANS : C,D,E

20. Your web application wants to make use of a role named 'manager', which is defined in the servlet container.
Which of the following XML fragments must occur in the deployment descriptor of your web application?
1.
<role name='manager' />
2.
<role>
<role-name>manager</role-name>
</role>
3.
<role>manager</role>
4.
<security-role>
<role-name>manager</role-name>
</security-role>

Select 1 correct option.
A.1
B.2
C.3
D.4

ANS : D

21.Consider the class shown in exhibit. Which of the following statements are correct?

public class MyHSAListener implements HttpSessionAttributeListener
{
public void attributeAdded(HttpSessionBindingEvent e){ }
public void attributeRemoved(HttpSessionBindingEvent e){ }
}

Select 1 correct option.
A.public void attributeReplaced(...){ } must be added.
B.public void attributeChanged(...){ } must be added.
C.The parameter class should be HttpSessionEvent.
D.The parameter class should be HttpSessionAttributeEvent.
E.It will compile as it is.

ANS : A

22.Identify the implicit objects available to EL expressions

Select 4 correct options.
A.request
B.sessionScope
C.paramValues
D.params
E.cookie
F.initParam

ANS : B,C,E,F

23.Which of the following statements are correct regarding tag libraries?

Select 1 correct option.
A.The tag library descriptor for a tag library must be kept in META-INF/taglib.tld, if the tag library is packaged in a jar file.
B.The tag library descriptor for a tag library may be kept in WEB-INF/taglib.tld, if the tag library is packaged in a jar file.
C.A JSP 2.0 compliant container is guaranteed to generate implicating mapping for JSTL tag libraries.
D.A JSP 2.0 compliant container will automatically generate an implicit tag library for a set of tag files.
E.The tag library descriptor for a tag library not packaged as a jar file may be kept anywhere in /tld directory of the web application's
document root

ANS : D

24.Consider the following usage of a custom tag in a JSP page:

<jsp:useBean id="student" scope = "session" class="com.xyz.Student" />
<mytaglib:studentTag student='student' />

Which of the following statements are correct?

Select 1 correct option.
A.Application objects such as com.xyz.Student, cannot be passed as attributes to custom tags.
B.The Student object will be passed to the studentTag tag handler.
C.The Student object will NOT be passed because no variable named student is defined.
D.A Student object will not be created if it is not available it the session.
E.None of these.

ANS : E

25.Assuming that the Servlet Container has just called the destroy()
method of a servlet instance, which of the following statements are
correct?

Select 2 correct options.
A.Any resources that this servlet might hold have been released.
B.The servlet container time out has exceeded for this servlet instance.
C.The init() method has been called on this instance.
D.None of the requests can EVER be serviced by this instance.
E.All threads created by this servlet are done.

ANS : C,D

26.For a tag to accept any valid jsp code as its body, what should be the
value of <body-content> for this tag's taglib descriptor?

Select 1 correct option.
A.JSP
B.jsp
C.any
D.text
E.The <body-content> subelement itself may be absent.

ANS : E

27.Which of the given options can be used in a servlet code that needs to access a binary file kept in WEB-INF/data.zip while servicing a request?
Assume that config refers to the ServletConfig object of the servlet and context refers to the ServletContext object of the servlet.

Select 1 correct option.
A.InputStream is = config.getInputStream("/WEB-INF/data.zip");
B.InputStream is = context.getInputStream("data.zip");
C.InputStream is = context.getResourceAsStream("/WEB-INF/data.zip");
D.InputStream is = context.getResourceAsStream("WEB-INF/data.zip");
E.InputStream is = config.getResourceAsStream("WEB-INF/data.zip");

ANS : C

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

29.Identify the implicit objects accessible to a jsp page that can store objects accessible across multiple requests.

Select 2 correct options.
A.page
B.request
C.session
D.application
E.pageContext

ANS:C,D

30.You are developing a jsp page named stockindices.jsp. This jsp page needs to use a HTML page named nasdaq.html in the middle of the page,
which is updated every ten minutes by some other process. Which of the following lines, when added to stockindices.jsp, ensures that
stockindices.jsp uses the latest nasdaq.html?

Select 1 correct option.
A.<%@include page='nasdaq.html' %>
B.<%@include file='nasdaq.html' %>
C.<jsp:include page='nasdaq.html' />
D.<jsp:include file='nasdaq.html' />
E.<jsp:forward page='nasdaq.html' />

ANS : D























SCWCD 1.4 Mock Questions - 4

SCWCD 1.4 Mock Exams and Priactice Questions

1. Regarding the processing of a BodyTag handler, in which of the following cases a BodyContent object will be "pushed" into the pageContext?

Select 1 correct option.
A.If the doStartTag() returns EVAL_BODY_INCLUDE
B.If the doStartTag() returns EVAL_BODY_BUFFERED
C.If the doStartTag() returns SKIP_BODY
D.If the doStartTag() DOES NOT return SKIP_BODY
E.A BodyContent object it is always created and pushed no matter what doStartTag() returns

ANS : B

2.Which of the following apply to Transfer Object design pattern?

Select 2 correct options.
A.It increases complexity by increasing the number of remote interfaces.
B. It increases network performance by introducing one coarse grained remote call for multiple finer grained network calls
C.It reduces network traffic by introducing one coarse grained remote call for multiple finer grained network calls
D.It increase server throughput by utilizing the CPU better
E.It increases design overhead due to versioning issues

ANS : B,C

3.Which of the following deployment descriptor snippets would you use to declare the use of a tag library?

1.

<tag-lib>

<uri>http://abc.net/ourlib.tld</uri>

<location>/WEB-INF/ourlib.tld</location>

</tag-lib>



2.

<taglib>

<uri>http://abc.net/ourlib.tld</uri>

<location>/WEB-INF/ourlib.tld</location>

</taglib>



3.

<taglib>

<taglib-uri>http://abc.net/ourlib.tld</taglib-uri>

<taglib-location>/WEB-INF/ourlib.tld</taglib-location>

</taglib>



4.

<taglib>

<tagliburi>http://abc.net/ourlib.tld</uri>

<tagliblocation>/WEB-INF/ourlib.tld</location>

</taglib>



5.

<taglibmap>

<uri>http://abc.net/ourlib.tld</uri>

<location>/WEB-INF/ourlib.tld</location>

</taglibmap>

Select 1 correct option.

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

ANS : C

4.Which of the following design patterns is used to separate the task of writing the GUI screens and business logic?

Select 1 correct option.
A.View Logic
B.Front Controller
C.Model View Controller
D.Business View
E.Business Delegate

ANS : B

5. For this jsp code to compile and run which of the given options should be true?
<jsp:useBean class="com.bookstore.Book" type="java.lang.Object" id="book" />

Select 1 correct option.
A.This statement is wrong as type attribute is invalid.
B.Book must have a public no args constructor
C.Book must have a public constructor but there is no requirement on arguments.
D.Book must have a public getInstance() method.
E.This statement will always throw an exception at runtime no matter what you do to Book class.

ANS : B

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

Select 1 correct option.

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

ANS : D

7.Select the tag that comes directly under the <web-app> tag of a
web.xml and that is used to specify a class whose object will be sent
notifications when changes occur to the SevletContext?

Select 1 correct option.
A.servlet-context-listener
B.listener
C.context-listener-class
D.listener-class
E.context-listener

ANS : B

8.Consider the following JSP code (See exhibit).
What will it print for the very first request to this page as well as the web application that contains this page?

<html><body>

<%

Integer count = (Integer) request.getSession(false).getAttribute("count");

if(count != null )

{

out.println(count);

}

else request.getSession(false).setAttribute("count", new Integer(1));

%>

Hello!

</body></html>

Select 1 correct option.
A.It will print Hello!
B.It will print Hello and will set the count attribute in the session.
C.It will throw a NullPointerException at request time.
D.It will not compile.

ANS : B

9. The following line of code exists in the doGet method of Servlet:
String sid = request.getParameter("jsessionid");
Which of the options will retrieve the HttpSession associated with
the request? (Assume that the session has already been created.)

Select 3 correct options.
A.HttpSession session = request.getSession();
B.HttpSession session = HttpSession.getSession(sid);
C.HttpSession session = request.getSession(sid);
D.HttpSession session = request.getSession(true);
E.HttpSession session = request.getSession(false);

ANS : A,D,E

10.Given that a tag testlib:myFirstSimpleTag extends SimpleTagSupport.
What should be done so that scriptlet code can be used in the body of this tag?

Select 1 correct option.
A.body-content should be set to JSP in the TLD for this tag.
B.scripting-enabled should be set to true in the TLD for this tag.
C.Create a classic tag adapter for this tag that has the body-content of JSP.
D.This cannot be done because it is a Simple tag.
E.None of these.

ANS : D

11.Which of the following is NOT a technique used for maintaining sessions?

Select 1 correct option.
A.HttpSession objects
B.URL rewriting
C.Cookies
D.HttpSessionActivationListener
E.Hidden form fields

ANS : D

12.Identify the method of TagSupport class that can be used by an inner tag handler to access an outer tag handler that is not enclosing it
immediately...

Select 1 correct option.
A.findAncestorWithClass
B.findAncestor
C.findAncestorClass
D.findParentWithClass
E.findParentClass

ANS : A

13.Consider the following JSP page:

<%@page isELIgnored='false'%>

<html>

<body>

<h1>

<% request.setAttribute("pageContext", "pagecontext"); %>

pageContext = ${pageContext}

</h1>

</body>

</html>

Assuming that both - scripting and EL are allowed in the page, what will it print for ${pageContext}?

Select 1 correct option.

A.It will cause a translation error
B.It will print the string "pagecontext"
C.It will print nothing
D.It will throw an exception at request time
E.None of these.

ANS : E

14.What subelement of <attribute> tag defines the name of the attribute that might be passed to the tag handler?

Select 1 correct option.
A.<attribute-name>
B.<name>
C.<attributename>
D.<param-name>
E.No subelement is needed. 'name' attribute is used in <attribute> tag to define the name.

ANS : B

15.Consider the contents of the following two jsp files:
In File: test.jsp



<html>

<body>

<% int i = 10; %>

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

Hello World : <%=i%>

</body>

</html>

In File : test2.jsp

<% i = 15; %>
What will be the output when test.jsp is requested?

Select 1 correct option.
A.Hello world : 15
B.Hello world : 10
C.It will throw an exception because i is undefined in test2.jsp
D.test.jsp will not compile because syntax of include directive is incorrect.
E.None of the above

ANS : A

16.Which of the given options are equivalent?

Select 2 correct options.
A. <% Hashtable ht = new Hashtable(); %>
B.<%= Hashtable ht = new Hashtable() %>
C.<jsp:scriptlet>Hashtable ht = new Hashtable();</jsp:scriptlet>
D.<jsp:code>Hashtable ht = new Hashtable();</jsp:code>
E.<jsp:scriptlet>Hashtable ht = new Hashtable()</jsp:scriptlet>

ANS : A,C

17.Which of the following lines of code, in the doPost() method of a
servlet, uses the URL rewriting approach to maintaining sessions?

Select 1 correct option.
A.request.useURLRewriting();
B.out.println(response.rewrite("<a href='/servlet/XServlet'>Click here</a>"));
C.out.println("<a href=' "+request.rewrite("/servlet/XServlet")+" '>Click here</a>"));
D.out.println("<a href=' "+response.encodeURL("/servlet/XServlet")+" '>Click here</a>"));
E.out.println("<a href=' "+request.encodeURL("/servlet/XServlet")+" '>Click here</a>"));

ANS : D

18.Which of the following classes/interfaces provide methods to write messages to a log file?

Select 2 correct options
A.GenericServlet
B.ServletRequest
C.HttpServletRequest
D.ServletContext
E.Only GenericServlet

ANS : A,D

19.What are the implications of using the HTTP GET method for a form submission?

Select 3 correct options.
A.You cannot pass binary data to the server.
B.You cannot send unlimited (or a lot of) data to the server
C.You cannot send unlimited (or a lot of) data to the server
D.You can only reply with the HEADER information in the response
E.The parameters will be appended to the URL as a query string.

ANS : A,B,E

20.Which method would you use to acquire the stream to write binary data in response to a request to a servlet?

Select 1 correct option.
A.getOutputStream() of ServletResponse interface.
B.getOutputStream() of HttpServletResponse interface.
C.getFileOutputStream() of HttpServletResponse interface.
D.getWriter() of HttpServletResponse interface.
E.getWriter() of ServletResponse interface.

ANS : A

21.Which of the following are valid JSP scriptlets?

Select 2 correct options.
A.<% String uid = LoginHelper.login(request) %>
B.<% String uid = LoginHelper.login(request); %>
C.<%! String uid = LoginHelper.login(request) %>
D.<%@ String uid = LoginHelper.login(request) %>
E.<% for(int i=0; i< 10; i++) { out.println(i); } %>

ANS : B,E

22.Which of the following implicit variables should be used by a 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

23.Consider the following tag declaration in a TLD file:

<tag>

<name>simpleInterest</name>

<tag-class>SimpleInterestTag</tag-class>

//1

</tag>

SimpleInterestTag calculates simple interest for any amount and requires two attributes 'amount' and 'rate'.
Which of the following sub elements would you need to add inside

Select 1 correct option.
A.Two separate <attribute> elements.
B.One <amount> element and one <rate> element
C.One <attribute> element with sub-elements
D.One <attribute-list> element with sub-elements

ANS : A

24.Which of the statements regarding the following code are correct?

public void doPost(HttpServletRequest req, HttpServletResponse res)

throws IOException, ServletException

{

res.getWriter().print("Hello ");

RequestDispatcher rd = getServletContext().getRequestDispatcher("/test.jsp");

rd.include(req, res);

res.getWriter().print("World");

}

Select 1 correct option.
A.Only "Hello" will be a part of the output.
B.Only "World" will be a part of the output
C."Hello" and "World" both will be a part of the output.
D.Neither will be a part of the output

ANS : C

25.Given that a servlet has been mapped to /report/* .
Identity the various components of the URI: /myapp/report/daily/tradesummary as seen by the servlet
Drag and Drop the selected item to the following .

Context Path
Servlet Path
Path Info

select item :
1./myapp
2./myapp/report
3./myapp/report/daily
4./report
5./report/daily
6./report/daily/tradesummary
7./daily
8./daily/tradesummary

ANS :

Context Path -1
Servlet Path -4
Path Info -8

26.Which method is invoked when a ServletContext is initialized?

Select 1 correct option.
A.contextInitialized() on a ServletContextListener Object.by the servlet.
B.contextCreated() on a ServletContextListener Object.
C.contextStateChanged() on a ServletContextListener Object.
D.init() on a ServletContextListener Object
E.initialized() on a ServletContextListener Object.

ANS : A

27. Consider the following JSP page code:

<html>

<body>

<%! int MIN; %>

Value of MIN is: <% = MIN %>

</body>

</html>

What output will it generate for the browser?

Select 1 correct option.
A.Value of MIN is: Undefined.
B.Value of MIN is: 0
C.It will not compile
D.It'll print an arbittrary value for MIN.
E.None of the above

ANS : C

28.Consider the following code in hello.jsp:
<html>

<body>

<h1>Hello EL</h1>

${param.command}

</body>

</html>

Which of the following tags when added to web.xml ensures that the text ${param.command} is printed exactly as it is in the output?

Select 1 correct option.

A.<jsp-config>

<jsp-property-group>

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

<elignored>true</elignored>

</jsp-property-group>

</jsp-config>

B.<jsp-config>

<jsp-property-group>

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

<isELIgnored>true</isELIgnored>

</jsp-property-group>

</jsp-config>

C.<jsp-config>

<jsp-property-group>

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

<el-ignored>true</el-ignored>

</jsp-property-group>

</jsp-config>

D.<jsp-config>

<jsp-property-group>

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

<ignore-el>true</ignore-el>

</jsp-property-group>

</jsp-config>

ANS : C

For a tag in a tag library descriptor, an attribute is defined as follows:

<attribute>

<name>age</name>

<required>true</required>

</attribute>

Assume that the tag is being referred to as calc:insurance.
Which of the given options could be a valid use of the tag?

Select 2 correct options.
A.<calc:insurance age="25"></calc:insurance>
B.<calc:insurance age="<%=request.getParameter("age")%>"></calc:insurance>
C.<calc:insurance></calc:insurance>
D.<calc:insurance><age>25</age></calc:insurance>
E.<calc:insurance age="30"><age>25</age></calc:insurance>

ANS : A,E

30. Consider the code for doGet method of a servlet (See exhibit). Which of
the given LOCs can be inserted at //1 to log the message as well as the exception's stack trace?

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException

{

String userId = null;

try

{

userId = loginUser(req);

}

catch(Exception e)

{

// 1 : log "Unknown User" and the exception to the log file.

}

if(userId != null)

{

//do something.

}

}

Select 1 correct option.
A.req.log(e, "Unknown User");
B.this.log(e, "Unknown User");
C.this.getServletContext().log("Unknown User", e);
D.this.getServletContext().log(e, "Unknown User");
E.The stack trace of the exception cannot be logged using log(...) methods.

ANS : C














SCWCD 1.4 Mock Questions - 3

SCWCD 1.4 Mock Exams and Priactice Questions

1.Consider the following web.xml code snippet:

<servlet>

<servlet-name>BankServlet</servlet-name>

<servlet-class>com.abc.bankapp.BankServlet</servlet-class>

<security-role-ref>

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

<role-link>supervisor</role-link>

</security-role-ref>

</servlet>

Which of the following statements are correct?

Select 1 correct option.
A.The servlet code should use "manager" as a parameter in request.isUserInRole() method.
B.The servlet code can use "manager" or "supervisor" as a parameter in request.isUserInRole() method.
C.The servlet code should use"supervisor" as a parameter in request.isUserInRole() method.
D.The role of "manager" must be defined in the servlet container.
E.None of these.

ANS : A

2.You are designing a complex webapp that uses multi tier architecture. The application must provide interfaces for HTML as well as XML and
should be maintainable.Which design pattern would you use?

Select 1 correct option.
A.Data Access Object
B.Business Deligate
C.MVC
D.Remote Method Invocation
E.Transfer Object

ANS : C

3.Which of the following directives are applicable ONLY for tag files?

Select 3 correct options.
A.attribute
B.variable
C.page
D.include
E.import
F.tag

ANS : A,B,F

4.Which of the following are correct about FORM based authentication mechanism?

Select 3 correct options.
A.HTML FORM is used to capture the username and password of the user.
B.Password is transmitted as plain text.
C.Password is transmitted in an encrypted form.
D.Password is transmitted either in encrypted text or in plain text depending on the browser.
E.This mechanism can be used over HTTPS.

ANS :A,B,E

5.Which pattern allows you to replace the presentation logic without much impact on the data representation?

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

ANS : A

6.Identify the elements that help describe the attribute characteristics of a JSP custom tag in a TLD file.

Select 3 correct options.
A.value
B.name
C.description
D.rtexprvalue
E.class

ANS : B,C,D

7.Select the correct return types for ServletContext.getResource() and ServletContext.getResourceAsStream() methods.

Select 1 correct option.
A.java.io.Resource and java.io.InputStream
B.java.io.Resource and java.io.BufferedInputStream
C.java.net.URL and java.io.InputStream
D.java.io.File and java.io.InputStream
E.java.net.URL and java.io.FileInputStream

ANS :C

8.Consider the following jsp code:

<html>

<body>

<% String a = "aaa"; %>

<%! String a = "AAA"; %>

<% String b = "bbb"; %>

<%! String b = "BBB"; %>

<% out.println(a+b); %>

</body>

</html>

What will be the output?

Select 1 correct option.
A.aaabbb
B.aaaBBB
C.AAAbbb
D.AAABBB
E.Compilation error!

ANS :A

9.Which of the following are valid values for the <transport-guarantee> element?

Select 3 correct options.
A.CONFIDENTIAL
B.INTEGRAL
C.SECURE
D.ENCRYPTED
E.NONE

ANS : A,B,E

10.Write the parent element of <session-timeout> element.
ANS : session-config

11.Consider the tag handler class shown in exhibit.
What will be printed when the above tag is used as follows in a jsp page:

Hello <mylib:mytag> World!</mylib:mytag>

public class MyTag extends TagSupport

{

public int doAfterBody()

{

try

{

pageContext.getOut().println("In doAfterBody()");

}

catch(Exception e)

{

}

return SKIP_BODY;

}

}

Select 1 correct option.
A.Hello
B.Hello World!
C.Hello In doAfterBody() World!
D.Hello In doAfterBody()
E.None of the above.

ANS : A

12.Which of the following HTTP protocol methods is eligible to produce unintended side effects upon multiple identical invocations beyond
those caused by single invocation?

Select 1 correct option.
A.GET
B.POST
C.HEAD
D.PUT
E.OPTIONS

ANS : B

13.Which method of ServletResponse would you use to set its content type?

Select 1 correct option.
A.setParameter
B.setHeader
C.setAttribute
D.setContentType
E.None of the above.

ANS :D

14.<jsp:useBean id="mybean" beanName="my.app.MyBean" class="my.app.MyBean" /> is a valid useBean declaration.
Options.
A.True
B.False

ANS :B

15.Which of the following lines can be used to retrieve a servlet initialization parameter "dbname" from the init() method of a servlet?
public void init()

{

String dbname = //1 : Insert line here

}
Select 2 correct options.
A.getServletConfig().getParameter("dbname");
B.getServletConfig().getInitParameter("dbname");
C.getServletContext().getInitParameter("dbname");
D.getInitParameter("dbname");
E.getInitParameterValue("dbname");

ANS :B,D

16.Consider the following description of a tag in a TLD:
<tag>

<name>SmilyTag</name>

<tag-class>com.enthuware.ctags.SmilyTag</tag-class>

<description>

Replaces emoticons such as :), :D, and :( with images.

</description>

<body-content>tagdependent</body-content>

<attribute>

<name>name</name>

<required>false</required>

<rtexprvalue>true</rtexprvalue>

</attribute>

</tag>
Which of the following statements regarding the above tag are correct?

Select 2 correct options.
A.It is an empty tag.
B.It may be used as an empty tag.
C.It must have a body
D.It must implement BodyTag interface.
E.It may take an attribute named 'name'. But if present, its value must be dynamic.

ANS : B,D

17.Which of the following jsp fragments will print all the parameters and their values present in a request?

1.

<% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

Object obj = enum.nextElement();

out.println(request.getParameter(obj));

} %>



2.

<% Enumeration enum = request.getParameters();

while(enum.hasMoreElements()) {

String obj = (String) enum.nextElement();

out.println(request.getParameter(obj));

} %>



3.

<% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

String obj = (String) enum.nextElement();

out.println(request.getParameter(obj));

} %>



4.

<% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

Object obj = enum.nextElement(); %>

<%=request.getParameter(obj); %>

<% } %>



5.

<% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

String obj = (String) enum.nextElement(); %>

<%=request.getParameter(obj)%>

<% } %>

Select 2 correct options.

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

ANS : C,E

18.Which of the following statements are valid JSP directive?
Select 2 correct options.
A.<%! int k = 10 %>
B.<% int k = 10; %>
C.<%=somevariable%>
D.<%@ taglib uri="http://www.abc.com/tags/util" prefix="util" %>
E.<%@ page language="java" import="com.abc.*"%>

ANS : D,E

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

20.Which of the following are valid implicit variables in a JSP page?

Select 2 correct options.
A.error
B.page
C.this
D.root
E.context

ANS :B,C

21.A Tag Handler implements BodyTag interface. How many times its doAfterBody method may be called?

Select 1 correct option.
A.BodyTag does not support doAfterBody.
B.0
C.1
D.0 or 1
E.Any number of times.

ANS : E

22.Given: You have configured a listener class (see exhibit) in web.xml of a web application.
Now, consider the following code for the doGet() method of a servlet for the same web application.

public void doGet(HttpServletRequest req, HttpServletResponse res)

{

System.out.println(this.getServletContext().getAttribute("key"); //2

}
Which option can be inserted at //1 in the listener code so that servlet code at //2 prints 100?

import javax.servlet.*;

public class MyListener implements ServletContextListener

{

public void contextInitialized(ServletContextEvent sce)

{

Integer key = new Integer(100);

// 1 Insert code here.

}

public void contextDestroyed(ServletContextEvent sce)

{

}

}
Select 1 correct option.

A.this.setAttribute("key", key);
B.this.getServletContext().setAttribute("key", key);
C.this.getContext().setAttribute("key", key);
D.sce.getContext().setAttribute("key", key);
E.sce.getServletContext().setAttribute("key", key);

ANS : E

23.Which of the following interfaces declares the methods jspInit() and jspDestroy()?

Select 1 correct option.
A.javax.servlet.jsp.JSP
B.javax.servlet.jsp.JspServlet
C.javax.servlet.jsp.JspPage
D.javax.servlet.jsp.HttpJspPage
E.javax.servlet.jsp.HttpJspServlet

ANS :C

24.Which of the following statements are correct JSP directives?

Select 2 correct options.
A.<%@ page %>
B.<%! taglib uri="http://www.abc.com/tags/util" prefix="util" %>
C.<% include file="/copyright.html"%>
D.<%@ taglib uri="http://www.abc.com/tags/util" prefix="util" %>
E.<%$ page language="java" import="com.abc.*"%>

ANS :A.D

25.Which of the following classes hides the implementation details and provides a standard API to the services provided by the servlet
container to a jsp page?

Select 1 correct option.
A.HttpSession
B.Servlet
C.JspPage
D.ServletContext
E.PageContext

ANS : E

26.Which of the following are true regarding the parameters defined using the <context-param> element of a deployment descriptor?

Select 2 correct options.
A.They are thread safe.
B.They are accessible from multiple threads simultaneously and from any servlet of the web application.
C.They can be modified using the setAttribute() method.
D.They can be modified using the setParameter() method.
E.They can be modified using the setInitParameter() method.

ANS : A,B

27.How can you explicitly expunge the session object?

Select 1 correct option.
A.You cannot. It can only be expunged automatically after session timeout expires.
B.By calling invalidate() on session object.
C.By calling expunge() on session object.
D.By calling delete() on session object
E.By calling finalize() on session object.

ANS : B

28.You have declared a useBean tag as:
<jsp:useBean id="man" class="animal.Human" scope="application"/>
In which type of object will this bean be kept?

Select 1 correct option.
A.Servlet
B.HttpSession
C.ServletContext
D.ServletConfig
E.ApplicationContext

ANS : C

29.Which of the following is a sensible way of sending an error page to the client in case of a business exception that extends from
java.lang.Exception?

Select 2 correct options.
A.Catch the exception and use RequestDispatcher to forward the request to the error page.
B.Don't catch the exception and define the 'exception to error-page' mapping in web.xml
C.Catch the exception, wrap it into ServletException and define the 'business exception to error-page' mapping in web.xml
D.Catch the exception, wrap it into ServletException, and define the 'ServletException to error-page' mapping in web.xml
E.Don't do anything, the servlet container will automatically send a default error page

ANS : A,C

30.Business delegate pattern should be used to enable communication between the JSP code and the enterprise javabeans.
Options.
A.True
B.False

ANS : A












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