当前位置: 代码迷 >> Java Web开发 >> java.lang.reflect.InvocationTargetException解决方案
  详细解决方案

java.lang.reflect.InvocationTargetException解决方案

热度:55   发布时间:2016-04-16 22:17:36.0
java.lang.reflect.InvocationTargetException
本帖最后由 Ugly__Duckling 于 2014-06-15 19:56:01 编辑
在通过ajax的异步时出现问题。
问题如图:
  

代码如下:
    页面代码:

  $('.editClick').live('click',function(){
var click = $('.editClick');
var obj=$('.questionID');
var index=click.index(this);
var questionID = obj.eq(index).text();
var nameHttp;
try{
nameHttp = new XMLHttpRequest();
}catch(e) {
nameHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
nameHttp.open('POST', 'json/seeExamAct.do', true);
nameHttp.onreadystatechange = function() {
alert( nameHttp.responseText); //上图中的错误信息弹出框
if (nameHttp.readyState == 4 && nameHttp.status == 200)
{
var userObj = eval('(' + nameHttp.responseText + ')'); 
var title = $('#title');
alert(title);
var desc = $('#desc');
var id = $('#clearId');
var flag = $('#flag');
id.val(userObj.id);
flag.val(userObj.flag);
title.val(userObj.title);
desc.val(userObj.desc);

editor.setContent(userObj.content,false);
}
};
nameHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
nameHttp.send("questionID="+questionID);

});

struts-server.xml

<package name="json" extends="json-default" namespace="/json">
<!-- 查看试题的action -->
<action name="seeExamAct" class="com.action.ExamAction" method="seeExam">
<!-- 返回类型为json 在sjon-default中定义 -->  
<result type="json">
  <!-- root的值对应要返回的值的属性 -->  
                <!-- 这里的result值即是 对应action中的 result --> 
<param name="root">object</param>
</result>
</action>

</package>   


action 中代码:

public String seeExam() throws Exception {

HttpServletRequest request = ServletActionContext.getRequest();
String questionID = request.getParameter("questionID");

System.out.println("questionID" + questionID);

int id = Integer.parseInt(questionID);
Exam examInfo = this.examService.findExamID(id);

System.out.println(examInfo.getTitle());
Map<String, String> map = new HashMap<String, String>();
map.put("content", examInfo.getContent());
map.put("title", examInfo.getTitle());
map.put("desc", examInfo.getDescription());
map.put("id", examInfo.getId() + "");

this.object = JSONObject.fromObject(map);

System.out.println("object" + object.toString());    //在控制台中不能输出,不知为啥?
System.out.println(this.object == null); //如上,也是不能输出
return SUCCESS;
}

其中已经有object的setter和getter方法

为啥啊?
。。。
------解决方案--------------------
一般多个jar之间需配套使用。
还有struts2使用时,可以使用struts2的一套jar包,就是struts 下载时的自带war包里面的jar,这些都是配套好的。
------解决方案--------------------
下载一个框架,里面使用的jar都是统一版本的,不会错。
  相关解决方案