首页 > 应用软件 > 软件教程 > 编程开发 > 正文

java 常见的异常大集合(3)
2011-08-02 11:02      我要评论()
字号:T|T

 

异常

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>中       <方案二>重新启动你的应用服务器,自动就没有这个问题了

----------------------------------------------------------------------------------------------------------------------------

java.lang.IllegalStateException: getOutputStream() has already been called for this respons

原因:是web容器生成的servlet代码中有out.write(""),这个和JSP中1.调用的response.getOutputStream()产生冲突.即Servlet规范说明,不能既调用response.getOutputStream(),又调用response.getWriter(),无论先调用哪一个,在调用第二个时候应会抛出IllegalStateException,因为在jsp中,out变量实际上是通过response.getWriter得到的,你的程序中既用了response.getOutputStream,又用了out变量,故出现以上错误。

2.由于jsp container在处理完成请求后会调用releasePageContet方法释放所用的PageContext object,并且同时调用getWriter方法,由于getWriter方法与在jsp页面中使用流相关的getOutputStream方法冲突, 所以会造成这种异常

解决方案:

// 输出图象到页面

ImageIO.write(image, "JPEG", response.getOutputStream());

增加2句话;

out.clear();

//意义是:清空缓存的内容

out = pageContext.pushBody();

//返回一个新的BodyContent(代表一个HTML页面的BODY部分内容)

//保存JspWriter实例的对象out

//更新PageContext的out属性的内容

----------------------------------------------------------------------------------------------------------------------------

bad number

原因: 项目的版本和JDK的版本不兼容

解决: windows-preferences-server-Integrated Sandbox-Myeclise  tomcat 6-选择和项目版本一致的JDK

----------------------------------------------------------------------------------------------------------------------------

Connection reset by peer: socket write error问题的原因

这个问题一般是客户端在连接还没有完全建立的时候就取消连接,比如用户按了浏览器上面的“停止”按钮,一般来说没有什么问题。但是如果频繁出现,就表示很多客户端连接到Apache服务器的响应时间太长了,可能是网络的问题或者服务器性能问题

可能你的网络连接存在一些问题,你的数据传输的时候,可能由于时间等待的太久,但是server段设置的连接检验时间限制一定,那么就可能出现这种情况的!

不过更常见的原因是:

1:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉;

2:客户关掉了浏览器,而服务器还在给客户端发送数据;

3:浏览器端按了Stop;

4:服务器给客户端响应结果给防火墙拦截了。

新闻热线:010-68947455

关键词: 大集 常见

责任编辑:lujq

我要评论

已有位网友参与评论

本类最热

科技视界

网站地图

牛华网

华军下载 | 牛华网 | 盒子 | pcsoft | 论坛

实用工具

关于我们 | 新闻投稿 | 软件发布 | 版权声明 | 意见建议 | 网站地图 | 友情连接 | RSS订阅 | 总编信箱 | 诚聘英才 | 联系我们

苏ICP备11016551号-2  苏公网安备 32132202000111号 本站特聘法律顾问:于国富律师

Copyright (C) 1997-2012 newhua.com 牛华网 版权所有