struts常见异常整理
2007-06-11 13:53
351 查看
struts常见异常整理
struts常见异常整理 javax.servlet.jsp.JspException: Cannot retrieve mapping for action /Login (/Login是你的action名字) 可能原因 action没有再struts-config.xml 中定义,或没有找到匹配的action,例如在JSP文件中使用 <html:form action="Login.do".将表单提交给Login.do处理,如果出现上述异常,请查看struts-config.xml中的定义部分,有时可能是打错了字符或者是某些不符合规则,可以使用strutsconsole工具来检查。 ----------------------------------------------------------------------------------------------------------------- 异常 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 可能原因 特别提示:因为有很多中情况会导致这个错误的发生,所以推荐大家调高你的web服务器的日志/调试级别,这样可以从更多的信息中看到潜在的、在试图创建action类时发生的错误,这个action类你已经在struts-config.xml中设置了关联(即添加了<action>标签)。 在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). 拼写错误,这个也时有发生,并且不易找到,特别注意第一个字母的大小写和包的名称。 ----------------------------------------------------------------------------------------------------------------- 异常 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”。 ----------------------------------------------------------------------------------------------------------------- 异常 java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm 可能原因 这个错误主要发生在在classpath中找不到相应的Java .class文件。如果这个错误发生在web应用程序的运行时,主要是因为指定的class文件不在web server的classpath中(/WEB-INF/classes 和 /WEB-INF/lib)。在上面的错误中,原因是找不到ActionForm类。 ----------------------------------------------------------------------------------------------------------------- 异常 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 mightoccur implicitly if you specify that a form-bean is this Struts ActionForm class rather than specifying a child of this classfor the form-bean. Not associating an ActionForm-descended class with an action can also lead to this error. ----------------------------------------------------------------------------------------------------------------- 异常 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文件时也可能导致这个异常。 ----------------------------------------------------------------------------------------------------------------- 异常 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"/> ----------------------------------------------------------------------------------------------------------------- 异常 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。 ----------------------------------------------------------------------------------------------------------------- 异常 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 可能原因 很显然,这个错误是发生在使用资源文件时,而Struts没有找到资源文件。 Implicitly trying to use message resources that are not available (such as using empty html:options tag instead of specifyingthe options in its body -- this assumes options are specified in ApplicationResources.properties file) XML parser issues -- too many, too few, incorrect/incompatible versions ----------------------------------------------------------------------------------------------------------------- 异常 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" 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 nodata" error message in Netscape or a completely empty (no HTML whatsoever) page rendered in Microsoft Internet Explorer.”的错误信息。 --------------------------------------------------------------------------------------------------------------------------- 异常 ServletException: BeanUtils.populate 解决方案 在用Struts上传文件时,遇到了javax.servlet.ServletException: BeanUtils.populate异常。 我的ActionServlet并没有用到BeanUtils这些工具类。后来仔细检查代码发现是在jsp文件里的form忘了加enctype="multipart/form-data" 了。所以写程序遇到错误或异常应该从多方面考虑问题存在的可能性,想到系统提示信息以外的东西。 ---------------------------------------------------------------------------------------------------------------------------- 1. 定义Action后, 如果指定了name, 那么必须要定义一个与它同名的FormBean才能进行form映射.2. 如果定义Action后, 提交页面时出现 "No input attribute for mapping path..." 错误, 则需要在其input属性中定义转向的页面.3. 如果插入新的数据时出现 "Batch update row count wrong:..." 错误, 则说明XXX.hbm.xml中指定的key的类型为原始类型(int, long),因为这种类型会自动分配值, 而这个值往往会让系统认为已经存在该记录, 正确的方法是使用java.lang.Integer或java.lang.Long对象.4. 如果插入数据时出现 "argument type mismatch" 错误, 可能是你使用了Date等特殊对象, 因为struts不能自动从String型转换成Date型,所以, 你需要在Action中手动把String型转换成Date型.5. Hibernate中, Query的iterator()比list()方法快很多.6. 如果出现 "equal symbol expected" 错误, 说明你的strtus标签中包含另一个标签或者变量, 例如: <html:select property="test" onchange="<%=test%>"/> 或者 <html:hidden property="test" value="<bean:write name="t" property="p"/>"/> 这样的情况... --------------------------------------------------------------------------------------------------------------------------- 错误:Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update原因与解决: 因为Hibernate Tools(或者Eclipse本身的Database Explorer)生成*.hbn.xml工具中包含有catalog="***"(*表示数据库名称)这样的属性,将该属性删除就可以了 --------------------------------------------------------------------------------------------------------------------------- 错误:org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations) 原因与解决: 方法1 删除Set方的cascade 方法2 解决关联关系后,再删除 方法3 在many-to-one方增加cascade 但值不能是none 最后一招: 检查一下hashCode equals是否使用了id作为唯一标示的选项了;我用uuid.hex时是没有问题的;但是用了native,就不行了,怎么办?删除啊! ---------------------------------------------------------------------------------------------------------------------------- 问题:今天用Tomcat 5.5.12,发现原来很好用的系统不能用了,反复测试发现页面中不能包含 taglib,否则会出现以下提示:HTTP Status 500 -type Exception reportMessage description The server encountered an internal error () that prevented it from fulfilling this request.exceptionorg.apache.jasper.JasperException: /index.jsp(1,1) Unable to read TLD "META-INF/tlds/struts-bean.tld" from JAR file"file:*****/WEB-INF/lib/struts.jar":原因:更新了工程用的lib文件夹下的jar,发布时也发布了servlet.jar和jsp-api.jar。解决:把jsp-api.jar删除就解决这个问题了。----------------------------------------------------------------------------------------------------------------------------- 错误: java.lang.NullPointerException 原因: 发现 dao 实例、 manage 实例等需要注入的东西没有被注入(俗称空指针异常)解决:这个时候,你应该查看日志文件;默认是应用服务器的 log 文件,比如 Tomcat 就是 [Tomcat 安装目录 ]/logs ;你会发现提示你:可能是:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sf' defined in ServletContextresource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception isorg.hibernate.HibernateException: could not configure from URL: file:src/hibernate.cfg.xmlorg.hibernate.HibernateException: could not configure from URL: file:src/hibernate.cfg.xml……………………….Caused by: java.io.FileNotFoundException: src/hibernate.cfg.xml可能是:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined inServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception isorg.hibernate.MappingException: Resource: com/mcc/coupon/model/UserRole.hbm.xml not foundorg.hibernate.MappingException: Resource: com/mcc/coupon/model/UserRole.hbm.xml not found然后你就知道原因是因为配置文件的解析出了错误,这个通过 Web 页面是看不出来的。更多的是持久化影射文件出的错误;导致了没有被解析;当然你需要的功能就无法使用了。 ---------------------------------------------------------------------------------------------------------------------------- 错误:StandardWrapperValve[action]: Servlet.service() for servlet action threw exception javax.servlet.jsp.JspException: Cannot retrieve mapping for action /settlementTypeManage 或者: type Status report message Servlet action is not available description The requested resource (Servlet action is not available) is not available. 原因: 同 上 ---------------------------------------------------------------------------------------------------------------------------- 错误StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang.ClassNotFoundException: org.apache.struts.taglib.bean.CookieTei界面错误具体描述: org.apache.jasper.JasperException: Failed to load or instantiate TagExtraInfo class: org.apache.struts.taglib.bean.CookieTei 原因与解决: <方案一>你的“html:”开头的标签没有放在一个<html:form>中 <方案二>重新启动你的应用服务器,自动就没有这个问题了 |
相关文章推荐
- Struts常见异常信息和解决方法
- Android常见异常处理整理
- struts2.1.8+hibernate2.5.6+spring3.0(ssh2三大框架)常见异常原因和解决方案(上)
- maven使用中的常见异常问题整理
- windows xp系统常见的异常故障及解决方法整理
- Struts常见异常信息和解决方法
- Struts常见异常信息和解决方法
- spring+struts+hibernate常见异常总结--邵京国
- struts2.1.8+hibernate2.5.6+spring3.0(ssh2三大框架)常见异常原因和解决方案(下)
- 整理asp.net开发中几种常见公共捕获异常方式
- struts常见的错误异常
- JAVA常见异常整理
- Struts常见异常和解决方法
- Struts常见异常信息和解决方法
- 常见的java异常整理
- Struts常见异常信息和解决方法
- Struts常见异常信息和解决方法
- struts2.1.8+hibernate2.5.6+spring3.0(ssh2三大框架)常见异常原因和解决方案
- Socket常见异常整理
- 黑马程序员--Java基础常见异常整理