• Post Reply Bookmark Topic Watch Topic
  • New Topic

mock question  RSS feed

 
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
 
ranger
Sheriff
Posts: 17314
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
 
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
 
The knights of nee want a shrubbery. And a tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!