热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Strus常见错误及原因分析

本篇文章包含了在用Struts开发web应用时经常碰到的一些异常和错误,根据异常或错误信息本身,经常可以找到潜在的错误发生原因。下面列出了一些Stru


本篇文章包含了在用Struts开发web应用时经常碰到的一些异常和错误,根据异常或错误信息本身,经常可以找到潜在的错误发生原因。

下面列出了一些Struts的常见错误和异常,并给出了一些可能发生此类错误或异常的原因。有的后面有相关连接,你可以通过它找到更多的信息。

Cannot retrieve mapping for action



异常


javax.servlet.jsp.JspException: Cannot retrieve mapping for action /Login (/Login是你的action名字)






可能原因


action没有再struts-config.xml 中定义,或没有找到匹配的action,例如在JSP文件中使用



Cannot retrieve definition for form bean null



异常


org.apache.jasper.JasperException: Cannot retrieve definition for form bean null



可能原因

这个异常是因为Struts根据struts-config.xml中的mapping没有找到action期望的form bean。大部分的情况可能是因为在form-bean中设置的name属性和action中设置的name属性不匹配所致。换句话说,action和form都应该各自有一个name属性,并且要精确匹配,包括大小写。这个错误当没有name属性和action关联时也会发生,如果没有在action中指定name属性,那么就没有name属性和action相关联。当然当action制作某些控制时,譬如根据参数值跳转到相应的jsp页面,而不是处理表单数据,这是就不用name属性,这也是action的使用方法之一。



No action instance for path /xxxx could be created


异常


No action instance for path /xxxx could be created



可能原因


特别提示:因为有很多中情况会导致这个错误的发生,所以推荐大家调高你的web服务器的日志/调试级别,这样可以从更多的信息中看到潜在的、在试图创建action类时发生的错误,这个action类你已经在struts-config.xml中设置了关联(即添加了标签)。



在struts-config.xml中通过action标签的class属性指定的action类不能被找到有很多种原因,例如:

定位编译后的.class文件失败。Failure to place compiled .class file for the action in the classpath (在web开发中,class的的位置在r WEB-INF/classes,所以你的action class必须要在这个目录下。例如你的action类位于WEB-INF/classes/action/Login.class,那么在struts-config.xml中设置action的属性type时就是action.Login).
拼写错误,这个也时有发生,并且不易找到,特别注意第一个字母的大小写和包的名称。

在struts-config.xml中指定的action类没有继承自Stuts的Action类,或者你自定义的Action类没有继承自Struts提供的Action类。

你的action类必须继承自Struts提供的Action类。



你的classpath的问题。例如web server没有发现你的资源文件,资源文件必须在WEB-INF/classes/目录下。


Problem in struts-config.xml file with action mapping.


Problem with data-sources.xml file.



相关链接


http://www.mail-archive.com/struts-user@jakarta.apache.org/msg65874.html
Action Mapping mistake in struts-config.xml:
http://www.manning.com/ao/readforum.html?forum=siaao&readthread=177
data-sources.xml file?:
http://www.caucho.com/quercus/faq/section.xtp?section_id=30


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标记时,在FormBean中必须有一个getUsername()方法。注意字母“U”。


Related Links


Case can trip up the matching between get method's 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 file's 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 application's 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的标记就是映射.do扩展名的标记或者两者都没有在web.xml中声明。



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



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



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



相关链接


Explicitly Define
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属性。例如应该是如下形式:



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的子元素。这常常发生在你在后面使用Struts的html标记。

另外要注意可能你不经意使用的无主体的标记,如,这样web 服务器解析时就当作一个无主体的标记,随后使用的所有标记都被认为是在这个标记之外的,如又使用了

还有就是在使用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中定义)


Cannot find message resources under key org.apache.struts.action.MESSAGE



异常


Cannot find message resources under key org.apache.struts.action.MESSAGE



可能原因


很显然,这个错误是发生在使用资源文件时,而Struts没有找到资源文件。


Implicitly trying to use message resources that are not available (such as using empty html:options tag instead of specifying the options in its body -- this assumes options are specified in ApplicationResources.properties file)



XML parser issues -- too many, too few, incorrect/incompatible versions



Related Links


Provide Struts with Resource Bundle
http://threebit.net/tutorials/ejb/general/
XML Parser Issues
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg15779.html


No input attribute for mapping path /loginAction



错误


No input attribute for mapping path /xxxxAction



可能原因e


No input attribute in action mapping in struts-config.xml file for the action with the name specified in the error message. An input attribute is not required if form validation is not performed (either because the validate attribute is set to false or because the validation method in the relevant form class is not implemented. The input attribute specifies the page leading to this action because that page is used to display error messages from the form validation.



Related Links




Strange Output Characters



错误


Strange and seemingly random characters in HTML and on screen, but not in original JSP or servlet.



可能原因


混和使用Struts的html:form标记和标准的HTML标记不正确。



使用的编码样式在本页中不支持。



"Document contained no data" or no data rendered on page



错误


"Document contained no data" in Netscape



No data rendered (completely empty) page in Microsoft Internet Explorer



可能原因


使用一个Action的派生类而没有实现perform()方法或execute()方法。在Struts1.0中实现的是perform()方法,在Struts1.1中实现的是execute()方法,但Struts1.1向后兼容perform()方法。

但你使用Struts1.1创建一个Action的派生类,并且实现了execute()方法,而你在Struts1.0中运行的话,就会得到"Document contained no data" error message in Netscape or a completely empty (no HTML whatsoever) page rendered in Microsoft Internet Explorer.”的错误信息。



推荐阅读
  • 如何搭建Java开发环境并开发WinCE项目
    本文介绍了如何搭建Java开发环境并开发WinCE项目,包括搭建开发环境的步骤和获取SDK的几种方式。同时还解答了一些关于WinCE开发的常见问题。通过阅读本文,您将了解如何使用Java进行嵌入式开发,并能够顺利开发WinCE应用程序。 ... [详细]
  • Java在运行已编译完成的类时,是通过java虚拟机来装载和执行的,java虚拟机通过操作系统命令JAVA_HOMEbinjava–option来启 ... [详细]
  • 本文介绍了使用AJAX的POST请求实现数据修改功能的方法。通过ajax-post技术,可以实现在输入某个id后,通过ajax技术调用post.jsp修改具有该id记录的姓名的值。文章还提到了AJAX的概念和作用,以及使用async参数和open()方法的注意事项。同时强调了不推荐使用async=false的情况,并解释了JavaScript等待服务器响应的机制。 ... [详细]
  • 原文地址:https:www.cnblogs.combaoyipSpringBoot_YML.html1.在springboot中,有两种配置文件,一种 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 如何用UE4制作2D游戏文档——计算篇
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了如何用UE4制作2D游戏文档——计算篇相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 本文介绍了Hyperledger Fabric外部链码构建与运行的相关知识,包括在Hyperledger Fabric 2.0版本之前链码构建和运行的困难性,外部构建模式的实现原理以及外部构建和运行API的使用方法。通过本文的介绍,读者可以了解到如何利用外部构建和运行的方式来实现链码的构建和运行,并且不再受限于特定的语言和部署环境。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 本文介绍了高校天文共享平台的开发过程中的思考和规划。该平台旨在为高校学生提供天象预报、科普知识、观测活动、图片分享等功能。文章分析了项目的技术栈选择、网站前端布局、业务流程、数据库结构等方面,并总结了项目存在的问题,如前后端未分离、代码混乱等。作者表示希望通过记录和规划,能够理清思路,进一步完善该平台。 ... [详细]
  • PHP中的单例模式与静态变量的区别及使用方法
    本文介绍了PHP中的单例模式与静态变量的区别及使用方法。在PHP中,静态变量的存活周期仅仅是每次PHP的会话周期,与Java、C++不同。静态变量在PHP中的作用域仅限于当前文件内,在函数或类中可以传递变量。本文还通过示例代码解释了静态变量在函数和类中的使用方法,并说明了静态变量的生命周期与结构体的生命周期相关联。同时,本文还介绍了静态变量在类中的使用方法,并通过示例代码展示了如何在类中使用静态变量。 ... [详细]
  • 本文介绍了RPC框架Thrift的安装环境变量配置与第一个实例,讲解了RPC的概念以及如何解决跨语言、c++客户端、web服务端、远程调用等需求。Thrift开发方便上手快,性能和稳定性也不错,适合初学者学习和使用。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
  • imx6ull开发板驱动MT7601U无线网卡的方法和步骤详解
    本文详细介绍了在imx6ull开发板上驱动MT7601U无线网卡的方法和步骤。首先介绍了开发环境和硬件平台,然后说明了MT7601U驱动已经集成在linux内核的linux-4.x.x/drivers/net/wireless/mediatek/mt7601u文件中。接着介绍了移植mt7601u驱动的过程,包括编译内核和配置设备驱动。最后,列举了关键词和相关信息供读者参考。 ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
author-avatar
ytm5295526049760
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有