引发“未指定 bean 错误”的可能原因有哪些?在Struts 1.1 中?
在 Web 应用程序中运行 Struts 1.1 时引发此错误的可能原因有哪些?我的 IDE 控制台窗口中的堆栈跟踪如下所示:
java.lang.IllegalArgumentException: No bean specified
at org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(PropertyUtils.java:837)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:934)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:223)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3245)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2003)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1909)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1359)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
What would be some of the possible causes for throwing this error running Struts 1.1 in a web app? The stacktrace from my IDE console window is shown below:
java.lang.IllegalArgumentException: No bean specified
at org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(PropertyUtils.java:837)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:934)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:223)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3245)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2003)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1909)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1359)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很可能是由 org.apache.commons.beanutils.PropertyUtils 类尝试从 null 的 bean 访问属性时引发的。您的
ActionForm
可能就是那个 bean。您是否为您的
Action
定义了ActionForm
?检查struts-config.xml
文件并查看
标记的 name 属性是否引用
。您在这里没有提供足够的信息,所以我只能猜测。您也应该发布堆栈跟踪。
编辑:您还可以检查另一件事。从堆栈跟踪来看,您的操作表单似乎没问题(如果表单为空,我认为您不会深入调用),但它可能是表单上的某些内容。
您是否使用嵌套属性或在表单上的 bean 上设置某些内容,例如:
如果在 JSP 中您在提交值时指定了
form.innerBean.someProperty
,Struts 将尝试执行此操作类似form.getInnerBean().setSomeProperty(...)
的东西。如果form.getInnerBean()
部分为 null,Struts 会在您获得 NullPointerException 之前抱怨。解决此类问题的方法是更改:
这可能
是原因吗?
This is most likely thrown by the
org.apache.commons.beanutils.PropertyUtils
class trying to access properties from a bean which is null. YourActionForm
might be that bean.Do you have an
ActionForm
defined for yourAction
? Check yourstruts-config.xml
file and see if the name attribute of the<action>
tag references a<form-bean>
.You are not providing enough information here, so I can only guess. You should post the stacktrace too.
EDIT: There is one other thing you could check for. From the stacktrace it seems your Action form is OK (I don't think you would have gotten so deep in the call if the form was null) but it might be something on the form.
Are you using nested properties or setting something on a bean on the form, a case like :
If in your JSP you specified
form.innerBean.someProperty
when you submit a value for this, Struts will try to do something like aform.getInnerBean().setSomeProperty(...)
. If the partform.getInnerBean()
is null, Struts will complain before you get NullPointerException.A solution for this kind of things is to change:
to
Might this be the cause?
嗨,我曾经遇到过同样的问题或类似的问题。就我而言,我定义了表单并初始化了他的属性。但是当我提交表单时,我遇到了同样的错误,消息说 mi 字段之一为空。
那是因为在我的 struts-config.xml 中,我曾经确实有scope =“request”的scope =“session”。这样每次提交时我都会丢失数据。
Hi I used to have same problem or similar. In my case I defined the Form and initialized his properties. but when I submit the form I had same error, the message said that one of mi fields are null.
That was because in my struts-config.xml I used to have scope="request" indeed of scope="session". That way every time I submit I lose my data.