• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Marcus Green question

 
Aditya Singh
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
54
Marks: 1 What will happen when you attempt to compile and run a JSP page with the following code?

<%
request.setAttribute("username","marcus");
String sAttribute = request.getAttribute("username");
sAttribute += request.getAttribute("marcus");
out.print(sAttribute);
%>

Choose one answer.
a. Compile time error
b. Compilation and output of marcus
c. Compilation and output of marcusnull
d. Compilation and output of marcususername
Incorrect
Marks for this submission: 0/1.

Answer given is 'a' .. Is it correct?
I Marked 'c'.
 
Hema Chon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer should be "A". The reason being, the return type of a getAttribute method is of type "Object". You need to cast it to "String" to get this to work.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, remember parameter returns String but attribute returns Object!
 
Aditya Singh
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya thts right, My mistake.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya whenever you have a doubt like this you shoul you should compile and run the code. I trained to be a teacher and taught adults for several years and the most useful thing I learnt was that people learn best from doing not reading. So to really get the ideas about the SCWCD into your head, write lots and lots of small programs. Good luck and best wishes with your studies and please feel free to ask questions like this as it can often help others learn.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic