1. How would you retrieve the value of a header named "User-Agent¨?

a. String header =request.getRequestHeader("User-Agent¨);
b. String header = request.getHeader("User-Agent¨);
c. String header = request.getÌntHeader("User-Agent¨);
d. String header = request.getAttribute("User-Agent¨)

2. The method getWriter() of HttpServletResponse returns an object of type ____________

a. HttpServletResponse
b. ServletOutputStream
c. ServletÌnputStream
d. PrintWriter

3. Which of the following methods are not implemented by the RequestDispatcher interface?
a. dispatch()
b. redirect()
c. forward()
d. include()

4. What is the return type of getAttribute() method of HttpServletRequest?
a. Object
b. String
c. Attribute
d. None of the above

5. Which statements about session timeouts are true? (Choose all that apply.)
a. Session timeout declarations made in the DD (web.xml) can specify time in seconds.
b. Session timeout declarations made in the DD (web.xml) can specify time in minutes.
c. Session timeout declarations made programmatically can specify time only in seconds.
d. Session timeout declarations made programmatically can specify time either in minutes or
seconds.

6. Ìf there are more than one text box with the same name in a form, then how will you retrieve the
first value of the text box? (choose all possible options)
a. request.getParameter("textBoxName¨);
b. request.getParameterValues("textBoxName¨)[0];
c. request.getHeader("textBoxName¨);
d. request.getAttribute("textBoxName¨);

7. Consider the following servlet code segment:

HttpSession session = request.getSession(true);
session.setAttribute("name¨, "Cognizant¨);
session.setMaxÌnactiveÌnterval(0);
if (session.isNew()) {
System.out.println(session.getAttribute("name¨);
} else { System.out.println(session.isNew());
}
What is the output of the above code segment ?

a. Displays "Cognizant¨ always
b. Displays "false¨ always
c. Depends on whether the session is newly created or not
d. None of the above

8. Which of the following are valid inorder to set the session timeout period as 2 minutes?
a. <session-timeout>2</session-timeout>
b. <session-timeout>120</session-timeout>
c. session.setMaxÌnactiveÌnterval(2);
d. session.setMaxÌnactiveÌnterval(120);

9. How will you send a cookie as response? Which sets a cookie "name" with the value
"Cognizant" in a Servlet
a. response.setCookie("name¨, "Cognizant¨);
b. response.sendCookie("name¨,¨Cognizant¨);
c. response.addCookie(new Cookie("name¨, "Cognizant¨));
d. response.setCookie(new Cookie("name¨, "Cognizant¨));


10. Which of the following are used to retrieve the value associated to the parameter name
provided within the <init-param> tag?
a. getServletContext().getÌnitParameter(paramName);
b. getServletConfig().getÌnitParameter(paramName);
c. getServletContext().getParameter(paramName);
d. getServletConfig().getParameter(paramName);


11. Which of the following are true?
a. ServletConfig is one per servlet
b. ServletConfig is one per web application
c. ServletContext is one per servlet
d. ServletContext is one per application


12. Which of the following are true?
a. Context initialization parameters can be declared using <init-param>
b. <servlet-mapping> is a sub-element of <servlet>
c. <load-on-startup> is a sub-element of <servlet>
d. <servlet-name> is a sub-element of both <servlet> and <servlet-mapping>


13. Which of the following can store attributes?
a. ServletResponse
b. HttpServletRequest
c. ServletContext
d. HttpSession


14. Which HTTP methods are used to show the client what the server is receiving?
a. GET
b. PUT
c. TRACE
d. OPTÌONS


15. When declaring a listener in the DD, Which sub-elements of the <listener> element are
required? (Choose all that apply.)
a. <listener-name>
b. <listener-type>
c. <listener-class>
d. <listener-classname>


16. Given that request is an HttpServletRequest, which snippets create a session if one doesn't
exist? (Choose all that apply.)
a. request.getSession();
b. request.getSession(true);
c. request.getSession(false);
d. request.geNewtSession();


17. Ìf a servlet is invoked using the forward() or include() method of RequestDispatcher, which
methods of the servlet's request object can access that request attributes set by the container?
(Choose all that apply.)
a. getCookies()
b. getAttribute()
c. getRequestPath()
d. getRequestAttribute()


18. You need to store a java long primitive attribute, called customerOÌD, into the session scope.
Which two code snippets all you to insert this value into the session? (Choose two.)
a.
long customerOÌD=45L;
session.setAttribute("customerOÌD",new Long(customerOÌD));
b.
long customerOÌD=45L;
session.setAttribute("customerOÌD",customerOÌD);
c.
long customerOÌD=45L;
session.setNumericAttribute("customerOÌD",new Long(customerOÌD));
d.
long customerOÌD=45L;
session.setLongAttribute("customerOÌD",customerOÌD);


19.
<%! int a=6; %>
<% int a=5; %>
<% int b=3; %>
Result is <%= a*b %>
What is the result of the above code segment?

a. Compilation error
b. Will display 18
c. Will display 15
d. None of the above


20. Which of the following are valid?
a. <% = 2*3 %>
b. <%= (8*3) %>
c. <%= 3>5 %>
d. <%= int a=3; %>

21. Which of the following attributes of page directive are invalid?
a. isELÌgnored
b. session
c. language
d. isScriptingEnabled


22. Which of the following is used to import a class in a JSP file?

a. <% page import = " java.util.List¨ %>
b. <%@ import file="java.util.List¨ %>
c. <%@ import java.util.List %>
d. None of the above


23. Which of the following describes the JSP life cycle process best?
a. JSP page is translated to a servlet, servlet is loaded into memory, code is compiled, instance
is created
b. JSP page is translated to a servlet, code is compiled, servlet is loaded into memory, instance
is created.
c. JSP is compiled, JSP page is translated to a servlet, code is loaded, instance is created.
d. JSP is loaded into memory, Code is compiled, instance is created.


24. Which of the following are JSP implicit objects?
a. pageContext
b. application
c. requestScope
d. exception

25. Which of the following are valid?
a. <jsp:include page="Header.jsp¨/>
b. <jsp:include file="Header.jsp¨/>
c. <%@include file="Header.jsp¨%>
d. <%@include page="Header.jsp¨%>

26. Assume a class named Employee which has a property called "empÌd¨ which is of type int.
"employee¨ is an attribute instance of Employee. Which of the following are legal ways of
setting the empÌd field to Also assume that there is a parameter called "empÌd¨ with the value
10 available to the jsp as a request parameter?
a. <jsp:setProperty name="employee¨ property="empÌd¨/>
b. <jsp:setProperty property="empÌd¨ value="10¨/>
c. <jsp:setProperty name="employee¨ property="*¨/>
d. <jsp:setProperty name="employee¨ property="empÌd¨ param="empÌd¨/>

27. How will you retrieve the first value of request parameter "fname¨? (Choose all options that
apply)
a. ${param.fname}
b. ${requestParams.fname}
c. ${requestScope.fname}
d. ${paramValues.fname[0]}


28. How will you access a servlet context initialization parameter named "company-name¨?
a. ${init.company-name}
b. ${init['company-name']}
c. ${initParam["company-name¨]}
d. ${contextParam.company-name}

29. Consider the following servlet code segment:

Map map = new HashMap();
map.put("a¨, "1¨);
map.put("b¨, "2¨);
map.put("c¨, "3¨);
map.put("d¨, "4¨);
request.setAttribute("map¨, map);
String[] names = {"a¨, "b¨, "c¨, "d¨};
request.setAttribute("names¨ , names);

What does ${map[names[0]]} return?

a. a
b. Nothing will be displayed
c. 1
d. None of the above

30. Which of the following EL implicit objects is not a Map?
a. requestScope
b. initParam
c. headerValues
d. pageContext


31.
<pref:tag1>
<%= result %>
</pref:tag1>

Which of the following are valid for the <body-content> tag of tag1?

a. JSP
b. empty
c. scriptless
d. tag dependant


32. Using c to represent the JSTL library, which of the following produces the same result as <%=
var %>? (Select one)
a. <c:var out=${var}>
b. <c:out value=${var}>
c. <c:out var="var">
d. <c:expr value=var>

33. Which attribute of <c:if> specifies the conditional expression? (Select one).
a. cond
b. check
c. expr
d. test


34. Which JSTL code snippet can be used to perform URL rewriting?
a. <a href='<c:url url="cognizant.jsp"/>'/>
b. <a href='<c:link url="cognizant.jsp"/>'/>
c. <a href='<c:url value="cognizant.jsp"/>'/>
d. <a href='<c:link value="cognizant.jsp"/>'/>

35. Which is the most efficient way of ensuring thread safety for session attributes which are being
set and accessed in a servlet?
a. Synchronize on the doGet() or doPost() method of the servlet
b. Make the Servlet implement SingleThread Model
c. Synchronize on the HttpSession object
d. Display a message on every web page instructing the user not to open a new browser
window.


36. Which of the following are true?
a. Making a servlet extend ThreadSafeServlet can ensure thread safety for all attributes et in
the servlet
b. Local variables are thread safe
c. Servlet class instance variables are thread safe
d. Context attributes can be set in the deployment descriptor


37. Which of the following listeners are invoked when a session is created?
a. HttpSessionBindingListener
b. HttpListener
c. HttpSessionListener
d. HttpSessionAttributeListener


38. Select the one design patterns which is a Presentation Tier pattern
a. Service Locator
b. DAO
c. Front Controller
d. Session façade


39. You need to restrict the number of active database connections at a time to 1. Which is the best
design pattern to apply?
a. DAO
b. Front Controller
c. Ìntercepting Filter
d. Singleton


40. Ìdentify model component in an MVC pattern
a. JSP
b. Data Bean
c. ActionServlet
d. Browser


41. Using multiple JSP components to construct your view is an example of
a. ViewHelper Pattern
b. Service Locator
c. Pattern Proxy Pattern
d. Composite View Pattern


42. How many times is the init() method called during the life of the servlet ?
a. Only once
b. Once for every request
c. None if the init() method is over-ridden
d. None


43. Ìn Expression Language ${8 / 0} ÷ displays Ìnfinity (state true/false)
a. True
b. False


44. POST method is considered to be idempotent method (state true/false)
c. True
d. False


45. You need to identify the browser type from which client request is forwarded and perform action
before further processing takes place in business logic. Which is the best way to achieve this?
a. Use a filter class (Ìntercepting filter pattern)
b. Use multiple if-else conditions in your business logic
c. Use Business Delegate pattern
d. Use composite view pattern

0    .8 43..80 .-4.-4.98904:95:94190.8 .  85.70.  808843 9204:9..8 -  85.  0503/843090790808843830.41901443.4/0802039  .0..823:908 .8 1.70.90/47349 /  4304190.< .39 ./347/0794809908088439204:95074/.

808843 9204:9 -  808843 9204:9 .

41901443.0943909 0939!.808843 9204:9 ..2 -  807.41901443..20 43. .20 574.90/94905.2.  $07.0943184305070-.20  43.7.:0 43.70/:8339 5..09431 09!.209073.09 -  $07.41901443.20  43.7.09439098430507807.20  43./ 43 89.09 2.39  ..70:80/9470970.39  /  70854380 809440 30440 3.  4.55.8:- 00203941807..09 .20  -  09$07.39  -  70854380 803/440 3.20907 5.  $07.09 .090.7.09.5538..03907.3.20907 5.393.7.      44:803/..4403..20  /  09$07.03907.  70854380 809440 3.884.8:- 00203941-49807.9.9435.2..3-0/0.79:58.7..20990.3/807.29.:0.  09$07.553     .094318430507807.440.  808843 809.20  ..09 3.20907 5.943 .41901443.  $07.7.3.389470.7097:0 ..8:- 00203941807.7./0/939039 5.9.   /  808843 809.208.7.//440 30440 3.20      .09 2.09#0854380 -  995$07.0943909 09!.09431 0939!..09#06:089 .55.7097:0 ..39      .  4390939.2.09 /  $07.20907 5.$07.09 /  807.7.209078.870854380.943     .2..997-:908 .7.7.8098.  70854380 .7.  09$07.09439098430507.

.88 /  890307 .0/.20     .450  .9  /  09#06:089997-:90      4:300/9489470.  706:089 09$08843 1.55  ..20 -  890307 950 .  09#06:089!.039.:894207   ...9.:/0 2094/41#06:08985.997-:908809-90.90.  706:089 09$08843   -  706:089 09$08843 97:0   .07870..307 4480.0.:894207  808843 809997-:90 .09 8706:0894-0.0.0889.883.0983.  % -  !&% .70:80/948490..  $07.990807.3 .3995$07.07 .9706:089.807..  %# /  !% $     03/0.   43.9..997-:90 .:894207  3043 .:894207  394908088438.:039490808843 448094  .94.8355098.890307390 .09#06:089 .4/08355098..9.8088431430/4083 9 089 4480.9.9.039..40/:8390147..439.9.9.55  .73.  094408  -  09997-:90  .  890307 .3.:894207  808843 809997-:90 .:894207   -  43.:894207  .%%!2094/8.  .80   /  706:089 009$08843      1.55  .435729. 2094/84190807.9.0943909 /  995$08843     .  890307 3..4:943807998.9706:0898.70.70 706:70/ 4480.8:- 00203984190890307002039.7/ 473.

0897.0897.:894207  3043 .4/08. :9 89 /  4304190.90/ -  $!5..:894207   /  43.0 8./0/39420247 389. :9 89  -  2547910 .75933. .  425.08.997-:90 .:894207  . 39- #08:98.70.088-089 .4250/ 389.  $!8.3.94307747  -  /85.7-0890$!10.08.419014438:80/9425479.41901443.0.38.-4.0     .4/08..90/  .  /  4304190..4/0802039  .41901443.38...  83470/ -  808843 ..3.70.09 807.0     .-4./0/39420247 .0.883.0984.  25479.:894207  808843 80943997-:90 .0574. 39.90/  .3:.70.0 /  8$..3.90/94.9890708:94190. :9 89  .  $!5.    .09 .  /85.3./ .4250/ 389.0897./ .90/  /  $!84.90/94.4250/ 807.90/94.4250/ $!5.807...38.41901443/08.-0/     .9.703.:894207  808843 809:207.807..09 .43.   /  39./0/39420247 4/08. - .70.807.4/084./0/ 389..025479 .     -      .-4.  5.0/70.0 8.70.0984.$!10  .:894207        39.997-:908415.  .

:/05../07 85 .70.  5.    .  853.450 /  0.05943    .98 ./ .0 0.943 .55.043909 -  .70$!25.  706:089$.41901443..94-0.41901443.

:/010 0./07 85 . -  853.

.8..990708.:0  .5...8.706:0895.04125400 .  3.5745079.  85809!7450793..997-:90389.3.88:209.0/ 025/ .883.84195039  025400 8./07 85     88:20.0 0. ..0/ 025/ 990..-0949085...20/25400.20 025400 5745079 025/ .841 8099390025/10/9484.7..700.:/05.41901443.:/010 0.20907 .3.20907./07 85  /  3.7.

:0  .. -  85809!7450795745079 025/ .

20 025400 5745079 .  85809!7450793. .

2 025/ .7.20 025400 5745079 025/ 5. /  85809!7450793.

 5.  / < 706:089 809997-:90 3...7.7.20< .5 5:9 . .208 .3 3.4/0802039  .3 3.20< -  39 .  .20< /  5.5  $973(3.4594389.3 3.5 5:9 /    706:089 809997-:90 2.8.20907 13.208  3.5  2.  39 .09.530.20 (< /  .20/ .425.5 5:9 .209073.55  .5 5:9 .9435.   2.20 (<     44:.7.7.3 3..2 .7.088.7.43909!.  39!.208   .20 (<  .9/4082.    2.:041706:0895.208 ((<709:73  .28 13. .3 3.0901789.52.2'.425.53.20< -  706:089!..:08 13.5 2.7.  706:089$.2 .  .20  .    2.425.807.09.9 .425.    44:70970.4390939.20  4480.425.450 13.2 13.20<    438/07901443807.

043909      57019.  0. 708:9 .988349.-  493-0/85.0    .7.94-0.   /  4304190.0/ .2 ..  706:089$.450 -  39!.-4.4190144325.5 .:08 /  5./07'.

.3-0:80/945071472&#70793 ./14790-4/ .43/  -  ..9470570803990$%-7...:0.39     &83.4390399.057.9430  .0.9430  .39 85.41901443574/:.4/0835509.  .8 ..74:9.57019..7.7    .7< .70.4:9...419.  ./0503/.$%.  8..:0.. .997-:9041.7< -  ..20708:9.7 /  .10890.  .  .7 $00.05708843 $00.  .41901443..7 ..  $! -  0259 .08908.1850.43.  .  057 /  9089     .43/943.759088 /  9.4:9.701 .:7:7.

 .

43.3:7. -  .39 85.701 .

 .

 .:7..39 85.:0.43.701 .  .

 .

:0.39 85.. /  .43.3.701 .

 .

74304390/409 47/4!489 2094/4190807./4/0 .997-:908.09 .    ..807.8902489011.090$07.30-74807 3/4  .0430.09 -  .2088.70-03 809.03897:.9 /  85.  $3.0880/3..  $3.092502039$30%70.039./8.9390:807349944503.109147808843.070-5.74304390995$088434-0.3/...41038:73970.

09.25041 .3-0809390/0542039/08.-08.7.109147.  995$088433/3890307 -  995890307 .    ..  74394397407 /  $088431.  '00507!.3.92094 ..990430/0835./0     4:300/9470897.997-:908093 90807.  $!  -  ..  $07.  $07.8088438.807.09.9.  .94:7.419014438903078.0.9438.3  .70.04./$.10 .99073 /  4254890'0!.  995$08843890307 /  995$08843997-:90890307     $00..943%075..43897:.  ..8.  !.0593907 /  $30943     /039124/0.-.7..99073 -  $07.947 -    .  343.943$07..99073 .3920889039 2094/.80.07 7//03 /  430 .  3907.99073     42.09  /  74807     &832:950$!.90/ .42543039894..-08.0 -  3.425430393.9./8..9903:2-0741.  43019039 2094/84.703.40/03./8..3038:70970.3.41901443..4330.88389.3'5..990738.08.04.55 .0/.70970.0.9.75947     .07706:089 .09 -  4.890-089 /0835.30.997-:908.01470.99073 .9907394.090903/%70...09 .9.!708039.10$07.99073 !74!.947 ./8.10 /  43909.7097:0 .     -  74394397407  .70970.0//:7390104190807.

0.3:.    35708843.

9097:0.83139 89. < /85.

80     ! $%2094/8.438/070/94-0/025490392094/ 89.80  .  %7:0 -  .1.9097:0.

1.098 .3/5071472..890-089.  &80.  %7:0 /  .08839.905.05.94.7/0/.43/943834:7-:830884.0.88 3907.80     4:300/94/039190-748079501742.  &80:8308800.03-:830884..99073  -  &802:9501 080.99073 /  &80.99073   ... .039706:0898147..4254890.085. .80  .1907.059319075.943 -014701:7907574.

Sign up to vote on this title
UsefulNot useful