This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

mock question  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File1.jsp contains the following lines:
HttpSession tmpSession = pageContext.getSession();
tmpSession.setAttribute("attr","example value");
And file2.jsp contains the following line
<%=session.getAttribute("attr")%>
Assuming that the surrounding code is ok, what will be the output of file2.jsp after file1.jsp has been visited?
A null
B example value
C compile error
D blank
the answer is B bu I think it will be none of the above. We have to typecast it to string to get the answer B.
Please clarify
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have again another jsp Expression. Expression return as Strings, so why would you need to cast it?
Mark
 
James Kwan
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like session.getAttribute() returns an object. You probably don't need to cast since it will invoke the ToString() method.
-James
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!