Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Doubts in Mock exam HFSJ  RSS feed

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1:Which are true? (Choose all that apply.)
A. When a web application is preparing to shutdown, the order of listener notification is not guaranteed.
B. When listener-friendly events occur, listener invocation order is not predictable.
C. The container registers listeners based on declarations in the deployment descriptor.
D. Only the container can invalidate a session.

Answer is Given as C.Is that an errata.


2:Which statements about RequestDispatcher are true (where applicable, assume the RequestDispatcher was not obtained via a call to getNamedDispatcher())? (Choose all that apply.)
A. A RequestDispatcher can be used to forward a request to another servlet.
B. The only method in the RequestDispatcher interface is forward().
C. Parameters specified in the query string used to create a RequestDispatcher are not forwarded by the forward() method.
D. The servlet to which a request is forwarded may access the original query string by calling getQueryString() on the HttpServletRequest.
E. The servlet to which a request is forwarded may access the original query string by calling getAttribute(“javax.servlet.forward.query_string”) on the ServletRequest.

Answer was given as A,E.
Any error why is D not correct??


3:Given this code from an otherwise valid HttpServlet that has also been
registered as a ServletRequestAttributeListener:
10. public void doGet(HttpServletRequest req,
HttpServletResponse res)
11. throws IOException, ServletException {
12. req.setAttribute(“a”, “b”);
13. req.setAttribute(“a”, “c”);
14. req.removeAttribute(“a”);
15. }
16. public void attributeAdded(ServletRequestAttributeEvent ev) {
17. System.out.print(“ A:” + ev.getName() + “->” + ev.getValue());
18. }
19. public void attributeRemoved(ServletRequestAttributeEvent ev) {
20. System.out.print(“ M:” + ev.getName() + “->” + ev.getValue());
21. }
22. public void attributeReplaced(ServletRequestAttributeEvent ev) {
23. System.out.print(“ P:” + ev.getName() + “->” + ev.getValue());
24. }
What logging output is generated?
A. A:a->b P:a->b
B. A:a->b M:a->c
C. A:a->b P:a->b M:a->c
D. A:a->b P:a->b P:a->null
E. A:a->b M:a->b A:a->c M:a->c
F. A:a->b M:a->b A:a->c P:a->null

Can any one give me correct explanatuion for this??

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

2:Which statements about RequestDispatcher are true (where applicable, assume the RequestDispatcher was not obtained via a call to getNamedDispatcher())? (Choose all that apply.)
A. A RequestDispatcher can be used to forward a request to another servlet.
B. The only method in the RequestDispatcher interface is forward().
C. Parameters specified in the query string used to create a RequestDispatcher are not forwarded by the forward() method.
D. The servlet to which a request is forwarded may access the original query string by calling getQueryString() on the HttpServletRequest.
E. The servlet to which a request is forwarded may access the original query string by calling getAttribute(“javax.servlet.forward.query_string”) on the ServletRequest.

Answer was given as A,E.
Any error why is D not correct??




In the case of requestDispatcher.forward() call container sets some attributes prior to forwarding a request to another servlet.
The following request attributes must be set:

javax.servlet.forward.request_uri
javax.servlet.forward.context_path
javax.servlet.forward.servlet_path
javax.servlet.forward.path_info
javax.servlet.forward.query_string

so in the case of forward you actualy overriding the actual parameters. to access the original you have to pass the above parameter as a argument to getAttribute() method.. like getAttribute(“javax.servlet.forward.query_string”) . so the E is the correct one.

D happens in the case of requestDispatcher.include()

 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can you please elaborate on this.
what i remember is we dont actually set any of those parameters while using forward rite??
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you don't need to set these attributes. The container does it automaticaly. So relex.

please check this thread for further details.

http://www.coderanch.com/t/429886/Web-Component-Certification-SCWCD/certification/getQueryString
 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi poonam,
thanks for the reply.correct me if iam wrong.

for forward method you override the attribute so getQueryString will not give the added values.. so use getAttribute(javax.servlet.forward.query_string)

for include you dont set anuthing so we can use getQueryString??
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Given this code from an otherwise valid HttpServlet that has also been
registered as a ServletRequestAttributeListener:
10. public void doGet(HttpServletRequest req,
HttpServletResponse res)
11. throws IOException, ServletException {
12. req.setAttribute(“a”, “b”);
13. req.setAttribute(“a”, “c”);
14. req.removeAttribute(“a”);
15. }
16. public void attributeAdded(ServletRequestAttributeEvent ev) {
17. System.out.print(“ A:” + ev.getName() + “->” + ev.getValue());
18. }
19. public void attributeRemoved(ServletRequestAttributeEvent ev) {
20. System.out.print(“ M:” + ev.getName() + “->” + ev.getValue());
21. }
22. public void attributeReplaced(ServletRequestAttributeEvent ev) {
23. System.out.print(“ P:” + ev.getName() + “->” + ev.getValue());
24. }
What logging output is generated?
A. A:a->b P:a->b
B. A:a->b M:a->c
C. A:a->b P:a->b M:a->c
D. A:a->b P:a->b P:a->null
E. A:a->b M:a->b A:a->c M:a->c
F. A:a->b M:a->b A:a->c P:a->null



I think C should be the correct answer A:a->b P:a->b M:a->c

1. when the servlet called first req.setAttribute(“a”, “b”) its trigger the public void attributeAdded(ServletRequestAttributeEvent ev)
result is A:a->b

2. when it encounters second call of req.setAttribute(“a”, “c”) it make the call to public void attributeReplaced(ServletRequestAttributeEvent ev)
because it make the existing value being replaced by the current one. Moreover ServletRequestAttributeEvent.getValue() method returns the old value not the new one. old value of attribute a is b so the result is P:a->b

3.finaly it called req.removeAttribute(“a”), so public void attributeRemoved(ServletRequestAttributeEvent ev) method would be called and the M:a->c comes as a result.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!