热门文章 | 热门软件| 热门源码 | 热门电影 | 知识库 | 联系我们
软件 源码 教程 影视 健康 招聘
  HTML | JavaScript | ASP | PHP | JSP | NET | VB | VC | VF | Windows | Linux | Mysql | Mssql | Oracle | Struts 
当前位置: 创世纪计算机资源网 -> 文章频道 ->struts 
站内搜索:
Strus常见错误及原因分析(二)(2)
作者:佚名 来源:不详 整理日期:2007-3-7

No getter method for property XXXX of bean org.apache.struts.taglib.html.BEAN

异常
javax.servlet.jsp.JspException: No getter method for property username of bean org.apache.struts.taglib.html.BEAN

可能原因
没有位form bean中的某个变量定义getter 方法

这个错误主要发生在表单提交的FormBean中,用struts标记<html:text property=”username”>时,在FormBean中必须有一个getUsername()方法。注意字母“U”。

Related Links
Case can trip up the matching between get methods name and name specified in Struts tag
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=58&t=000163



java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm

错误
java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm

可能原因
这个错误主要发生在在classpath中找不到相应的Java .class文件。如果这个错误发生在web应用程序的运行时,主要是因为指定的class文件不在web server的classpath中(/WEB-INF/classes 和 /WEB-INF/lib)。

在上面的错误中,原因是找不到ActionForm类。

This error is sometimes seen when one or more ActionForm.class instances are actually in the classpath. This most often occurs when ActionForm.class is made available correctly by placing struts.jar in the /WEB-INF/lib directory. When this library has been correctly placed and it is verified that ActionForm.class actually is present in the struts.jar file, the problem is either that more than one copy of ActionForm.class is in the classpath or (more likely) that duplicate versions of class files other than ActionForm are in the same classpath, causing confusion. This is especially true if a class that extends ActionForm is made available twice, such as in an .ear file that encompasses a .war file as well as in the .war files own classpath (/WEB-INF/classes). This problem can be resolved by guaranteeing that there are no redundant classes, especially those related to Struts (directly from Struts or extensions of Struts), in the web applications view.

相关连接
EJB and Web Shared Links:
http://forum.java.sun.com/thread.jsp?forum=26&thread=413060&tstart=0&trange=15
Keep Action and ActionForm (and their children) as non-overlapping unit(s) of an application
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg47466.html
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg47467.html



Exception creating bean of class org.apache.struts.action.ActionForm: {1}

异常
javax.servlet.jsp.JspException: Exception creating bean of class org.apache.struts.action.ActionForm: {1}

可能原因
Instantiating Struts-provided ActionForm class directly instead of instantiating a class derived off ActionForm. This might occur implicitly if you specify that a form-bean is this Struts ActionForm class rather than specifying a child of this class for the form-bean.

Not associating an ActionForm-descended class with an action can also lead to this error.

Related Links


Cannot find ActionMappings or ActionFormBeans collection

Exception
javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection

可能原因
不是标识Struts actionServlet的<servlet>标记就是映射.do扩展名的<sevlet-mapping>标记或者两者都没有在web.xml中声明。

在struts-config.xml中的打字或者拼写错误也可导致这个异常的发生。例如缺少一个标记的关闭符号/>。最好使用struts console工具检查一下。

另外,load-on-startup必须在web.xml中声明,这要么是一个空标记,要么指定一个数值,这个数值用来表servlet运行的优先级,数值越大优先级越低。

还有一个和使用load-on-startup有关的是使用Struts预编译JSP文件时也可能导致这个异常。

相关链接
Explicitly Define <load-on-startup>
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=50&t=001055
http://threebit.net/tutorials/ejb/general/


NullPointerException at ... RequestUtils.forwardURL

异常
java.lang.NullPointerException at org.apache.struts.util.RequestUtils.forwardURL(RequestUtils.java:1223)

可能原因
在struts-config.xml中的forward元素缺少path属性。例如应该是如下形式:
<forward name="userhome" path="/user/userhome.jsp"/>


Cannot find bean org.apache.struts.taglib.html.BEAN in any scope

Exception
javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope


Probable Causes
试图在Struts的form标记外使用form的子元素。这常常发生在你在</html:form>后面使用Struts的html标记。

另外要注意可能你不经意使用的无主体的标记,如<html:form … />,这样web 服务器解析时就当作一个无主体的标记,随后使用的所有<html>标记都被认为是在这个标记之外的,如又使用了<html:text property=”id”>

还有就是在使用taglib引入HTML标记库时,你使用的prefix的值不是html。

相关连接
Using form subelements outside of a form tag
http://forum.java.sun.com/thread.jsp?thread=337537&forum=4&message=1384153



Missing message for key xx.xx.xx

Exception
javax.servlet.jsp.JspException: Missing message for key xx.xx.xx

Probable Causes
这个key的值对没有在资源文件ApplicationResources.properties中定义。如果你使用eclipse时经常碰到这样的情况,当项目重新编译时,eclipse会自动将classes目录下的资源文件删除。

资源文件ApplicationResources.properties 不在classpath中 应将资源文件放到 WEB-INF/classes 目录下,当然要在struts-config.xml中定义)


[1]  [2]  [3]  
相关文章