在类型 java.lang.String 上找不到属性“someproperty" [英] Property 'someproperty' not found on type java.lang.String

查看:35
本文介绍了在类型 java.lang.String 上找不到属性“someproperty"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误,我无法弄清楚问题出在哪里.userid"列在数据库和bean 中.有谁有想法吗?

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 

谢谢.

推荐答案

异常基本上是告诉你 ${user} 是一个普通的 java.lang.String.根据javadoc,它确实没有getUserid() 方法表示一个 userid 属性.

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.

确保您在所需范围内设置了具体的 User 实例,而不是普通的 String.由于您没有在问题中的任何地方展示您如何准备作用域变量,因此无法对此给出有针对性的答案,但它至少应该看起来像这样:

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.

这篇关于在类型 java.lang.String 上找不到属性“someproperty"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆