Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to retrieve primitive data type from getAttribute()  RSS feed

 
jignesh soni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html>
<body>
<%
String uName = (String)session.getAttribute("userName");
String lName = (String)session.getAttribute("lastName");
int age = (int)session.getAttribute("age")
%>

/*here I know, object cant be cast to primitive. How can I retrieve int value from an pbject ? */

Please reply with explanation.

Thanks
Jignesh
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Auto-boxing considerations aside, an int cannot be create as a scoped variable (attribute) so there's no need to ever retrieve it as such.

How was the scoped variable initially created? As an Integer? A String? The appropriate means to get it depends on how it was created.
 
Amit Y Desai
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session.getAttribute method returns object...so you cannot directly get primitive out of it. you can use Integer.parseInt() method to retrive integer primitive..there are other methods also for other primitive parsing..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!