• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock question

 
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: 17278
6
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic