aspose file tools*
The moose likes JSP and the fly likes jsp:useBean problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:useBean problem" Watch "jsp:useBean problem" New topic
Author

jsp:useBean problem

Nelo Angelo
Ranch Hand

Joined: Jul 25, 2011
Posts: 44

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


I love java but she hates me... :'(
binu narayanan
Ranch Hand

Joined: Jul 24, 2009
Posts: 60
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

Joined: Jul 06, 2005
Posts: 1026
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

Joined: Jul 25, 2011
Posts: 44

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:useBean problem