• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getParameterNames

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)%>
<% } %>





Options

Select 2 correct options.

1

2

3

4

5
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you try them yourself and find out?
 
muthu moorthy
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because of main reason, no set up to try in this pc where i work and so expecting Experts to have a look ?

Thank you
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With all due respect, the experts expect that you'll make a reasonable effort to find the answer on your own. When you get stuck they can help you resolve your problem.

You need to get access to a machine with a servlet container. A big part of learning is experimentation.
[ January 10, 2007: Message edited by: Scott Johnson ]
 
muthu moorthy
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, great, thank you Scott.
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1 and 3 ! are correct
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Niranjan,

watch out the first option, getParameter method parameter type. :roll:
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd say 3 and 5. Anyone to justify this??

1 is ruled out as getParameter takes a String and not an Object!

2 is ruled out because getParameters(); is simply not there!

4 is ruled out because of the same reason that we have for option 1.

So, we are left with 3 and 5 which is obviously the answer to the question.
[ January 10, 2007: Message edited by: Jothi Shankar Kumar Sankararaj ]
 
Elan Ram
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jothi,
you are correct. Only 3 & 5 contain valid methods. Other options are not.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Muthu, can you please say from where did you get this question? I doubt that the real exam will have such kind of direct questions! Any SCWCD's here to confirm this?
 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I doubt that the real exam will have such kind of direct questions!


There's nothing wrong with this question....you can easily expect questions like these on the real exam
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sayak. So I have to be through with the API to be bold enough to face questions like these!
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Infact I got 2 questions that talk on API in the exam. So read API. SCJP was not more into the APIs.

Here, it is always good to know, what lies where ... for exam purpose and also for your knowledge.

The class and interface organizations in the javax.servlet. <all> packages, teach you good design.

See the way they have designed Tags .... Its good ... JSP 2.0 has introuduced the JspTag marker interface. And the way they use TagAdapter class to get hold of incompatible tag hierarchies is simply amazing !!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic