struts2错误集合
1.java.lang.ClassCastException: java.lang.Integer 从session取值后转化到int
String ss=session.get("id").toString();
int id=Integer.parseInt(ss);
2.将string转化为float
float f=Float.valueOf("11");
3.将Integer转化为String
4.String转化为double
Double.parseDouble("11.1");
5.struts2 标签换行
在默认情况下,表单元素是分布在不同行的。如下代码:
<s:form action="login2">
<s:textfield label="用户名" name="username"/>
<s:password label="密码" name="password"/>
<s:submit label="提交"/>
</s:form>
我们看着以上的代码跟HTML的差不了多少,但是因为struts2表单默认将表单内的每一个元素都分在单独的一行,label属性就如同我们在HTML中在<input type="text"/>前面的文字标签一样。如果我们不想让它自动换行,那就应该写成如下格式:
<s:form action="login2" theme="simple">
<s:textfield label="用户名" name="username"/>
<s:password label="密码" name="password"/>
<s:submit label="提交"/>
</s:form>
但在设置theme="simple"后,表单元素的label属性将失效,这时我们就得在表单元素前面加入想用label显示的文字。如:
<s:form action="login2" theme="simple">
用户名:<s:textfield label="用户名" name="username"/>
密码:<s:password label="密码" name="password"/>
<s:submit label="提交"/>
</s:form>
此时显示的为将不在是label中的值,而是显示文本框前面的文字,按钮则显示它原来的默认值:sbumit。
ell-formed character data or markup.
6.No result defined for action com.upload.UploadAction and result input
form中可能缺少:method="post"
7. \upload\鏉庡紑澶峔缁欎腑鍥藉鐢熺殑绗簩灏佷俊.doc (系统找不到指定的路径。)
public String getSavePath() {
return ServletActionContext.getRequest().getRealPath(savePath);//不能写成return this.savePath;
}
8.The method getRealPath(String) from the type ServletRequest is deprecated
ServletActionContext.getRequest().getRealPath(savePath);
把页面中的编码改成GBK
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
改为:<%@ page language="java" contentType="text/html;charset=GBK"%>
9.如何使用JDK中的bin的native2ascii来进行中文转换
10.Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name mess, locale zh_CN
无法读取中文数据
11.struts2中不能用<s:hidden>标签,否则action只会返回"input"
12.Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
没有加入Struts2需要的几个包
__________________________________________________________________________________________
13.Error building results for action validateName in namespace - action
Caused by: There is no result type defined for type 'json' mapped with name 'success' - result
_________________________________________________________________________________________
14.uk.ltd.getahead.dwr.util.CommonsLoggingOutput error
严重: Found reference to variable named 'c0-e1', but no variable of that name could be found.
2009-2-5 17:32:56 uk.ltd.getahead.dwr.util.CommonsLoggingOutput info
信息: Exec[0]: validator.doPost()
2009-2-5 17:32:56 org.apache.struts2.validators.DWRValidator doPost
严重: Error while trying to validate
There is no Action mapped for action name . - [unknown location]
___________________________________________________________________________________________
15.Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean
________________________________________________________________________________________________
16.警告: No configuration found for the specified action: 'login.action' in namespace: ''. Form action defaulting to 'action'
___________________________________________________________________________________________
17.2009-2-9 12:00:55 com.opensymphony.xwork2.validator.ActionValidatorManagerFactory <clinit>
信息: Detected AnnotationActionValidatorManager, initializing it...
attribute's literal value
______________________________________________________________________________________________
18.严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException
____________________________________________________________
19.信息: building session factory
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type
Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/Type
缺少包:asm.jar
__________________________________________________________________________________________
20.信息: building session factory
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter
Caused by: java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter
缺少包:commons-collections-2.1.1.jar
_____________________________________________________________________________________
21.信息: Loading XML bean definitions from class path resource [applicationContext.xml]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException
缺少包:dom4j-1.6.1.jar
___________________________________________________________________________
22.严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
Caused by: java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
缺少包:jta.jar
___________________________________________________________________________
23.java.lang.IllegalArgumentException: sessionFactory or hibernateTemplate is required
根据提示在配置文件中为这个类添加一个property属性
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
就不会报错.但是其它的Service类并不需要这么做,让我感觉很奇怪.最终发现原来是我让CataogService extends HibernateDaoSupport .改正后运行正常,goood
牢记....
________________________________________________________________________________
24.Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
缺少包:ehcache-1.2.3.jar
________________________________________________________________________________
25.Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/cglib/core/KeyFactory
缺少包:cglib-2.1.3.jar
_______________________________________________________________________________________
26.Exception in thread "main" java.lang.NoClassDefFoundError: antlr/ANTLRException
___________________________________________________________
27.Exception starting filter struts
Action class [loginbean] not found
加入包:struts2-spring-plugin-2.0.6.jar
struts.xml文件中加入:
<constant name="objectFactory" value="spring"></constant>
______________________________________________________________________
28.log4j:WARN No appenders could be found for logger (org.apache.catalina.startup.TldConfig).
log4j:WARN Please initialize the log4j system properly.
加入文件
log4j.properties
#
# Log4J Settings for log4j 1.2.x (via jakarta-commons-logging)
#
# The five logging levels used by Log are (in order):
#
# 1. DEBUG (the least serious)
# 2. INFO
# 3. WARN
# 4. ERROR
# 5. FATAL (the most serious)
# Set root logger level to WARN and append to stdout
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%d %5p (%c:%L) - %m%n
# Print only messages of level ERROR or above in the package noModule.
log4j.logger.noModule=FATAL
# OpenSymphony Stuff
log4j.logger.com.opensymphony=INFO
log4j.logger.org.apache.struts2=INFO
# Spring Stuff
log4j.logger.org.springframework=INFO
___________________________________________________________________________
29.警告: Settings: Could not parse struts.locale setting, substituting default VM locale)
原来要解决也不难,
创建struts.properties这个文件,放在src目录下就可以了
struts.locale=en_GB
____________________________________________________
30.No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath
把hibernate里ehcache-1.2.3.jar的ehcache.xml拷贝到src目录下,hibernate3用到了ehcache
___________________________________________________________________________________
31. Missing classdef for creator 'script'. Failed to load uk.ltd.getahead.dwr.create.ScriptedCreator. Cause: org/apache/bsf/BSFException
缺少包:bsf.jar
_____________________________________________________
32.No result defined for action com.action.LoginAction and result input - action - file:/E:/struts2Workspace/login/WebRoot/WEB-INF/classes/struts.xml:11:55
当使用struts2的配置文件验证时,若表单验证不通过,系统将默认返回"input",这时要在struts.xml中配置这个result
<result name="input">/login.jsp</result>
_________________________________________________________________________
33.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap
Caused by:
java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap
缺少包:commons-collections-2.1.1.jar
_______________________________________________________________________________________
34.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
Caused by:
java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
缺少包:ehcache-1.2.3.jar
___________________________________________________________________________________
35.No result defined for action com.action.ValidateNameAction and result input - action
_____________________________________________-
36.java.sql.SQLException: Positioned Update not supported.
分析---------------------------------------------------
在我的ValidateNameAction中一共有3个properties,其中有个bean是userManager而且是在spring framework中已经实例化了的,问题就出在它身上了。于是在struts.xml中加入该bean的exclude,再测试,成功了!
发送action的request后,服务返回JSON数据。
解决-----------------------------------------------------
<package name="demo" namespace="/" extends="json-default">
<action name="roomStatus" method="roomStatus">
<result type="json">
<param name="excludeProperties">
userManager
</param>
</result>
</action>
</package>
_________________________________________________________________________________________________
37.java.lang.OutOfMemoryError: PermGen space及其解决方法
PermGen space的全称是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决方法也一定是加大内存。说说为什么会内存益出:这一部分用于存放Class和Meta的信息,Class在被 Load的时候被放入PermGen space区域,它和和存放Instance的Heap区域不同,GC(Garbage Collection)不会在主程序运行期对PermGen space进行清理,所以如果你的APP会LOAD很多CLASS的话,就很可能出现PermGen space错误。这种错误常见在web服务器对JSP进行pre compile的时候。
内存溢出。
如果你的应用中有很多CLASS的话,就很可能出现PermGen space错误,
这种错误常见在web服务器对JSP进行pre compile的时候。如果你的WEB APP下使用了大量的第三方jar, 其大小超过了jvm默认的大小(4M)
那么就会产生此错误信息了。
解决方法: 手动设置MaxPermSize大小
修改TOMCAT_HOME/bin/catalina.sh
在“echo "Using CATALINA_BASE: $CATALINA_BASE"”上面加入以下行:
JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m
____________________________________________________________________________________________________---
38.struts2 中execute方法不执行问题
为一个action比如是LoginAction增加一个验证文件LoginAction-validation.xml,如果验证文件中要验证的字段多于登陆到LoginAction的页面上的字段,那么系统就会返回INPUT,而不会执行execute方法
________________________________________________________________________________________________________
39.java.lang.OutOfMemoryError: PermGen space
补充一下Windows下的做法:
设置环境变量JAVA_OPTS=-Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m
即可,java.lang.OutOfMemoryError: PermGen space的问题以前经常遇到,现在可以对付了
________________________________________________________________________________________________________
40.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/dom4j/io/SAXReader
Caused by: java.lang.NoClassDefFoundError: org/dom4j/io/SAXReader
解决的方法:加入包dom4j-1.6.1.jar 谢谢分享!!
我的异常网推荐解决方案:org.springframework.beans.factory.BeanCreationException:,http://www.myexception.cn/j2ee/10759.html