Reputation: 11
i store price in session , how can i get it in integer formate
this code give me error:
<%=session.getAttribute("price")%> //it print my value 400
<% Integer i=(Integer)session.getAttribute("price"); %> //error
can you help me what's wrong? and how to do?
Upvotes: 0
Views: 1504
Reputation: 2953
It depends how you're setting your attribute.
If you're setting an Integer
object like below -
Integer price = new Integer(10);
session.setAttribute("price", price);
Then, you can get like - Integer price = (Integer) session.getAttribute("price")
in jsp.
But if you're setting string in session like below -
String price = "10";
session.setAttribute("price", price);
Then you have to parse to integer while getting in jsp, like -
int price = Integer.parseInt(session.getAttribute("price"))
Upvotes: 2