org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException异常解决

自己在用ajax调用Action,返回时json时,出现了一下异常:

org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
	org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:246)
	org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
	org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
	org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
	org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
	org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
	org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:196)
	org.apache.struts2.json.JSONResult.execute(JSONResult.java:170)

解决办法:

1、因为要对Action中Service层的对象进行注入,加入了对应的get()/set()方法,返回的json的对象会将这个get()中的属性值返回,所以去掉service的get()方法。

2、在Action中除了属性的get()方法外,最好不要定义get开头的Action方法。

org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException:

04-17

困扰了很久的问题 请大虾指点下 什么原因rnHTTP Status 500 -rnrntype Exception reportrnrnmessagernrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrnexceptionrnrnorg.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetExceptionrn org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:243)rn org.apache.struts2.json.JSONWriter.process(JSONWriter.java:165)rn org.apache.struts2.json.JSONWriter.value(JSONWriter.java:131)rn org.apache.struts2.json.JSONWriter.write(JSONWriter.java:99)rn org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:112)rn org.apache.struts2.json.JSONResult.execute(JSONResult.java:198)rn com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:362)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)rn com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)rn org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)rn org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)rn org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)rn org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)rn org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)rn org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rnrnroot causern

java.lang.reflect.InvocationTargetException???

12-07

[color=#FF0000]使用hibernate4+oracle11g学习hibernate一对多关联关系,程序运行出现异常。不知道怎么解决,请大家帮忙?[/color]rn[b]下面是hibernate配置文件:[/b]rn[code=java]rnrnrnrn rn oracle.jdbc.driver.OracleDriverrn jdbc:oracle:thin:@localhost:1521:orclrn adminrn adminrnrn truernrn rn rn rn[/code]rn[b]下面是hibernate工具类:[/b]rn[code=java]package com.pb.hibernate.util;rnrnimport org.hibernate.HibernateException;rnimport org.hibernate.SessionFactory;rnimport org.hibernate.cfg.Configuration;rnimport org.hibernate.service.ServiceRegistry;rnimport org.hibernate.service.ServiceRegistryBuilder;rnrnpublic class HibernateUtil rn private static SessionFactory sessionFactory;rn private static ServiceRegistry serviceRegistry;rn public static SessionFactory congigureSessionFactory() throws HibernateException rn Configuration configuration = new Configuration().configure();rn serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();rn sessionFactory = configuration.buildSessionFactory(serviceRegistry);rn return sessionFactory;rn rn[/code]rn[b]下面是Grade持久化类:[/b]rn[code=java]package com.pb.hibernate.po;rnrnimport java.util.HashSet;rnimport java.util.Set;rnrnpublic class Grade rn private int gid;rn private String gname;rn private String gdesc;rn private Set students = new HashSet();rnrn public int getGid() rn return gid;rn rnrn public void setGid(int gid) rn this.gid = gid;rn rnrn public String getGname() rn return gname;rn rnrn public void setGname(String gname) rn this.gname = gname;rn rnrn public String getGdesc() rn return gdesc;rn rnrn public void setGdesc(String gdesc) rn this.gdesc = gdesc;rn rnrn public Set getStudents() rn return students;rn rnrn public void setStudents(Set students) rn this.students = students;rn rnrnrn[/code]rn[b]下面是Grade映射文件:[/b]rn[code=java]rnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn[/code]rn[b]下面是Student持久化类:[/b]rn[code=java]package com.pb.hibernate.po;rnrnpublic class Student rn private int sid;rn private String sanme;rn private String sex;rnrn public int getSid() rn return sid;rn rnrn public void setSid(int sid) rn this.sid = sid;rn rnrn public String getSanme() rn return sanme;rn rnrn public void setSanme(String sanme) rn this.sanme = sanme;rn rnrn public String getSex() rn return sex;rn rnrn public void setSex(String sex) rn this.sex = sex;rn rnrn[/code]rn[b]下面是Student映射文件:[/b]rn[code=java]rnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn[/code]rn[b]测试类:[/b]rn[code=java]package com.pb.hibernate.po;rnrnimport org.hibernate.Session;rnimport org.hibernate.Transaction;rnrnimport com.pb.hibernate.util.HibernateUtil;rnrnpublic class Test rnrn public static void main(String[] args) rn save();rn rnrn public static void save() rn Grade g = new Grade();rn g.setGid(110701);rn g.setGname("计应一班");rn g.setGdesc("计算机专业应用一班");rnrn Student stu1 = new Student();rn stu1.setSid(11070101);rn stu1.setSanme("张华");rn stu1.setSex("男");rnrn Student stu2 = new Student();rn stu2.setSid(11070125);rn stu2.setSanme("刘萍");rn stu2.setSex("女");rnrn g.getStudents().add(stu1);rn g.getStudents().add(stu1);rnrn Session session = HibernateUtil.congigureSessionFactory().openSession();rn Transaction tr = session.beginTransaction();rn session.save(g);rn session.save(stu1);rn session.save(stu2);rn tr.commit();rn session.close();rn rn[/code]rn运行异常情况:rn2014-12-7 12:46:48 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreationrnINFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetExceptionrn2014-12-7 12:46:48 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateServicernINFO: HHH000399: Using default transaction strategy (direct JDBC transactions)rn2014-12-7 12:46:48 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory rnINFO: HHH000397: Using ASTQueryTranslatorFactoryrnException in thread "main" org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersisterrn at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)rn at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)rn at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:385)rn at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)rn at com.pb.hibernate.util.HibernateUtil.congigureSessionFactory(HibernateUtil.java:15)rn at com.pb.hibernate.po.Test.save(Test.java:33)rn at com.pb.hibernate.po.Test.main(Test.java:11)rnCaused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]rn at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:138)rn at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)rn at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:341)rn at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:507)rn at org.hibernate.persister.entity.SingleTableEntityPersister.(SingleTableEntityPersister.java:146)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:513)rn at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)rn ... 6 morernCaused by: java.lang.reflect.InvocationTargetExceptionrn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:513)rn at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)rn ... 15 morernCaused by: org.hibernate.PropertyNotFoundException: Could not find a getter for sname in class com.pb.hibernate.po.Studentrn at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:316)rn at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:310)rn at org.hibernate.mapping.Property.getGetter(Property.java:321)rn at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:436)rn at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:200)rn at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:82)rn ... 20 morern[color=#FF0000]大家帮忙看看是哪出错了?[/color]

java.lang.reflect.InvocationTargetException

08-21

HTTP Status 500 -nntype Exception reportnnmessagenndescription The server encountered an internal error that prevented it from fulfilling this request.nnexceptionnjava.lang.reflect.InvocationTargetExceptionnn sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)n sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)n sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)n java.lang.reflect.Method.invoke(Method.java:597)n com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)n com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)n com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)n com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)n org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)n com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)n com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)n com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:306)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)n com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)n com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)n org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)n org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)n org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)n org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)nroot causennjava.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObjectnnnjava.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObjectn

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭