• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean problem

 
Nelo Angelo
Ranch Hand
Posts: 44
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently referring the Head First Servlets and JSP book.
I tried to execute my own example but am not getting the correct results.

=======
PURPOSE
=======

Entering name and number from the html page.
Displaying the entered values through JSP without using scripting

======
Error:
======
Name is displayed correctly but number always comes out as "0"


The codes are as follows:


beanForm.html



beanModel.java



beanController.java



web.xml


beanView.jsp


Is there something wrong with the bean? Or some issue with conversion
 
binu narayanan
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nelo,

you have in beanModel int num where as in the usebean the property name is "number" kindly have a check on that
 
Stefan Evans
Bartender
Posts: 1780
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Nelo Angelo
Ranch Hand
Posts: 44
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic