Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

mock question

 
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
Posts: 17346
11
Mac IntelliJ IDE 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
 
I'm still in control here. LOOK at this tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic