You're using UserId
which is the name of the field (and which violates Java naming conventions, by the way - as does dbConnect
as a class name).
The JSP wants to use properties - getters and setters. The method you're trying to get it to call is getUserId
, but the property name (in JavaBeans terms) is just userId
. Therefore if you change your code to:
<c:out value="${account.userId}" />
it should work. You should also change your class to use a field called just userId
, or even id
(given that it's already a user - that part is implicit).
It would be worth reviewing JSP/JSTL/JavaBeans tutorials - you'll notice that they all use property names starting with a lower case letter, e.g. ${foo.age}
to call the getAge()
method.
From the documentation for PropertyDescriptor constructor (which is also present in the JavaBeans specification):
Constructs a PropertyDescriptor for a property that follows the standard Java convention by having getFoo and setFoo accessor methods. Thus if the argument name is "fred", it will assume that the writer method is "setFred" and the reader method is "getFred" (or "isFred" for a boolean property). Note that the property name should start with a lower case character, which will be capitalized in the method names.
(Emphasis mine.)
It's not clear whether there's any method name that would let ${account.UserId}
work - if there isn't, then I'd argue that the error message could be a lot clearer. (Or it could just be a bit more forgiving.)
Additional points:
- It's not clear why your class is called
Users
when it appears to represent a single user - It's not clear that it should extend a class which has anything to do with database connections - a user is not a database connection, after all. I suspect you should be trying harder to make each class only responsible for one concept.