Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the syntax error in given below line

 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anybody tell me what is the syntax error in given below line .


${price[sessionitem[0]] + price[sessionitem[1]]}
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without more information, it's not possible to guarantee that your line of EL would fail.
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${price[sessionitem[0]] + price[sessionitem[1]]}

In this above statement ,sessionitem is an attribute of session object which contain the names of the item which is set by the user.
And price is a map of session scope which contain the cost of that item.

${price[sessionitem[0]]}-----> gives me the price of that item.This statement is right,as i have checked it.

But i want to calculate the total price of the items which user selected by this statement then it shows error: ${price[sessionitem[0]] + price[sessionitem[1]]}
I am using the Addition operator which may be implemented wrong.
[ March 18, 2008: Message edited by: pradeep singh ]
 
swapna rao
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pradeep,
what is the data type of the value you have stored in map object price.It might be because of the Typecast problem. What error you are getting in JSP.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you try this-

${price[sessionitem[0]]} + ${price[sessionitem[1]]}
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you try this-

${price[sessionitem[0]]} + ${price[sessionitem[1]]}
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pradeep singh:
And price is a map of session scope which contain the cost of that item.

What type is the cost? BigDecimal? String? Float?

If it's String, what does it look like: "23.00" "$23.00" "23 dollars"?
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!