• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting Error in code

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting the inputs "distance" and "service " from a previous html page and passing the values here to calculate "estimateamt" and pass the calculated "estimateamt" to a jsp page "service2.jsp" using session attribute



@@@@@@@@@@@@ this is the end of the servlet .Now the service.jsp is given below


Now when i run the servlet i am getting the Estimated amount as "0" always.which is the initial amount assigned..what is the mistake i did

 
Ranch Hand
Posts: 32
MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two things here:

1. First while saving the amount into the session you have to convert the amount into the string.
For example


This means what ever data type you are placing into the session the same data type needs to be used while retreiving from the session object.
Error occured since you placed the estimate amount as Long value into the session and you are trying to retrieve in the jsp page as string.

2. In the Jsp page you don't have to get the session object from the HttpRequest object as shown below:


Instead you can directly refer the HttpSession object in the jsp using the implict object

 
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

What is see in your jsp is the following :


String dist=(String)sess.getAttribute("distance");
String transport=(String)sess.getAttribute("service");
String amt=(String)sess.getAttribute("estimateamt");



First of all, your primitives "long" are put into session, trough autoboxing.

Further, you want to get them out. (code above)
You need to cast them back to long.
You cannot cast a primitive long to String
use String.valueOf(value) instead to get your string.


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kopparapu v kiran kumar wrote:1. First while saving the amount into the session you have to convert the amount into the string.
For example


Not so. Any type of object can be stored in the session. There is no need for conversion to string.
 
gokulnaath venkatesan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kopparapu v kiran kumar wrote:Two things here:

1. First while saving the amount into the session you have to convert the amount into the string.
For example


This means what ever data type you are placing into the session the same data type needs to be used while retreiving from the session object.
Error occured since you placed the estimate amount as Long value into the session and you are trying to retrieve in the jsp page as string.

2. In the Jsp page you don't have to get the session object from the HttpRequest object as shown below:


Instead you can directly refer the HttpSession object in the jsp using the implict object




thanks ..problem solved with your first solution by adding String.valueOf();

Now the problem is every time i am getting the amount as 0.it is not displaying the calculated amount.it is always displaying the initial assigned amount 0...can you help it out?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is a numeric value why are you casting it to a string in the first place?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ashish Hg,
Your post was moved to a new topic.
Please start new questions in new topics.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic