Currently referring the Head First Servlets and JSP book.
I tried to execute my own example but am not getting the correct results.
Entering name and number from the html page.
Displaying the entered values through JSP without using scripting
Name is displayed correctly but number always comes out as "0"
The codes are as follows:
Is there something wrong with the bean? Or some issue with conversion
I love java but she hates me... :'(
Joined: Jul 24, 2009
you have in beanModel int num where as in the usebean the property name is "number" kindly have a check on that
Joined: Jul 06, 2005
I saw nothing wrong at first glance.
I copied and pasted your code into my Eclipse, and tested with Tomcat 7.
It worked fine for me (as long as I enter a valid number in the number field that is)
For debugging I would suggest inspecting the request parameter values coming into your servlet - via logging statements or maybe debugging through it.
Check out what the value of the request parameter "number" actually is.
@binu: yes the class attribute 'num' is differently named to the bean property 'number'. However properties of a bean are declared by getter/setter methods, and those are getNumber/setNumber, therefore the bean property is properly 'number'. I do agree this can potentially be confusing, but its completely above board.
My other feedback is along the general code style line
- java class names should start with a capital letter. ie BeanController not beanController.
Thanks for the replies, the problem is now solved. Didn't quite get where the error had occured, I just re-wrote(or is it called re-coded ) the whole app and it ran fine. Maybe I should take the advice of my teachers and switch over to an IDE.