引发“未指定 bean 错误”的可能原因有哪些?在Struts 1.1 中?

发布于 2024-08-31 14:18:45 字数 1954 浏览 5 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花期渐远 2024-09-07 14:18:45

这很可能是由 org.apache.commons.beanutils.PropertyUtils 类尝试从 null 的 bean 访问属性时引发的。您的 ActionForm 可能就是那个 bean。

您是否为您的 Action 定义了 ActionForm?检查 struts-config.xml 文件并查看 标记的 name 属性是否引用

您在这里没有提供足够的信息,所以我只能猜测。您也应该发布堆栈跟踪。

编辑:您还可以检查另一件事。从堆栈跟踪来看,您的操作表单似乎没问题(如果表单为空,我认为您不会深入调用),但它可能是表单上的某些内容。

您是否使用嵌套属性或在表单上的 bean 上设置某些内容,例如:

public class MyAction extends ActionForm {
  private SomeBean innerBean;
  ...
  public SomeBean getInnerBean() { 
    return this.innerBean; 
  }
}

如果在 JSP 中您在提交值时指定了 form.innerBean.someProperty,Struts 将尝试执行此操作类似 form.getInnerBean().setSomeProperty(...) 的东西。如果 form.getInnerBean() 部分为 null,Struts 会在您获得 NullPointerException 之前抱怨。

解决此类问题的方法是更改​​:

public class MyAction extends ActionForm {
  private SomeBean innerBean;
  ...
}

这可能

public class MyAction extends ActionForm {
  private SomeBean innerBean = new SomeBean();
  ...
}

是原因吗?

This is most likely thrown by the org.apache.commons.beanutils.PropertyUtils class trying to access properties from a bean which is null. Your ActionForm might be that bean.

Do you have an ActionForm defined for your Action? Check your struts-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 :

public class MyAction extends ActionForm {
  private SomeBean innerBean;
  ...
  public SomeBean getInnerBean() { 
    return this.innerBean; 
  }
}

If in your JSP you specified form.innerBean.someProperty when you submit a value for this, Struts will try to do something like a form.getInnerBean().setSomeProperty(...). If the part form.getInnerBean() is null, Struts will complain before you get NullPointerException.

A solution for this kind of things is to change:

public class MyAction extends ActionForm {
  private SomeBean innerBean;
  ...
}

to

public class MyAction extends ActionForm {
  private SomeBean innerBean = new SomeBean();
  ...
}

Might this be the cause?

妄断弥空 2024-09-07 14:18:45

嗨,我曾经遇到过同样的问题或类似的问题。就我而言,我定义了表单并初始化了他的属性。但是当我提交表单时,我遇到了同样的错误,消息说 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文