• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

jsp:useBean problem

 
Ranch Hand
Posts: 44
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic