5

I am getting this error and I can not figure out where the problem might be. The "userid" column is in the database and is in the bean. Does anyone have any idea?

org.apache.jasper.JasperException: An exception occurred processing JSP page /user.jsp     at line 24  

21:   
22:     <form method="POST" action="AdminServlet" name="frmAddUser">  
23:         User ID : <input type="text" readonly="readonly" name="userid"  
24:             value="<c:out value="${user.userid}" />" />   
Username : <input  
25:             type="text" name="firstName"  
26:             value="<c:out value="${user.firstName}" />" />   
LastName : <input  
27:             type="text" name="lastName"  

root cause   

javax.el.PropertyNotFoundException: Property 'userid' not found on type java.lang.String 

Thank you.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Han
  • 592
  • 2
  • 6
  • 9
  • Where did you set the User Parameter on you JSP? Can you include the Code? – Stefan Dec 10 '12 at 19:25
  • 1
    `user` is not an object but just a `String` – madth3 Dec 10 '12 at 19:28
  • do you need to see the user bean? – Han Dec 10 '12 at 19:30
  • @ZenunKastrioti Just show where `user` is defined and what it's supposed to be (so yeah, I guess the bean) – Ian Dec 10 '12 at 19:33
  • I am not able to post here all the code however: – Han Dec 10 '12 at 19:43
  • public class User { private int userid; private String firstName; private String lastName; private Date dob; private String email; private boolean admin; private String password; public int getUserid() { return userid; } public void setUserid(int userid) { this.userid = userid; } ........ – Han Dec 10 '12 at 19:43

3 Answers3

4

The exception is basicaly telling you that ${user} is an ordinary java.lang.String. According to the javadoc, it has indeed no getUserid() method representing an userid property.

Make sure that you're setting a concrete User instance in the desired scope instead of a plain vanilla String. As you haven't shown anywhere in the question how you're preparing the scoped variable, it isn't possible to give a targeted answer on that, but it should at least look something like this:

User user = userService.find(id);
request.setAttribute("user", user); // and thus not e.g. setAttribute("user", "user") or something.
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

One of the following should be the case, according to me

  • The userid data-type is not matching with the one corresponding in the bean. It might be integer in db.

  • The property is not defined in the bean class. The name might be different, and you must be inferring it to be userid.

mtk
  • 13,221
  • 16
  • 72
  • 112
0

Are you doing a <c:set var="user">${user}</c:set> anywhere on the jsp?

According to Response 1 on another question, JSP does an implicit conversion to a string when you set the var in the JSP.

Community
  • 1
  • 1