• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object type casting?  RSS feed

 
Nikki Agr
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I have a JSP page that is trying to access a requestScope variable.. When I try ${requestScope.answer} it gives me the object reference instead of the value. Sorry I'm new at this and I'm thinking its Java casting issue, any suggestions on how I can fix this would be appreciated!

Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66153
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What type of object does answer represent?
 
Nikki Agr
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the MVC paradigm, my View JSP takes a number from the user, forwards it to a Controller which parses it to an Integer and then pokes it into a certain java class that computes the resolution of that integer. I set that computed answer as an attribute:



where Resolver is the constructor.

Now when I try to access this attribute answer in the View by using ${requestScope.answer} it shows me something as model.Resolver@1716fa0 (where class Resolver is in the model package).

I'm not sure if this info is enough, as you can tell, I'm lost...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66153
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is exactly what is to be expected if Resolver doesn't have a toString method that overrides the default. What did you expect to happen?

And more importantly, what is it you want to happen?

What is the purpose of Resolver?
[ November 09, 2008: Message edited by: Bear Bibeault ]
 
Nikki Agr
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose the number entered is 10, then the resolution is 5 2. So somehow I need to cast that object reference to some other data type.. When I try to parse it to String or Integer, it says it cannot do so.
 
Nikki Agr
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Bear, thanks for helping me out, I think I figured out the solution. You may close this topic. Have a nice day!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!