最近研究Jfinal这个框架,对于刚上手的的人来说,这个框架容易配置,使用,但是对于javaweb的学习来说这个框架还是有一点浅,今天再使用前台ajax点用后台controller显示图表时遇到了如下问题,前台代码:
$.ajax({
type: 'POST',
async: false,
contentType: "application/json",
url: "/Blog/ChartManage2",
data: "{dataType:'handong123'}",
// data: "{dataType:'handong123'}",
// responseText = JSON.parse(responseText)
dataType: "json",
//dataType: "text",
beforeSend: function () {
//alert("kashi");
},
success: function (msg) {
//alert("hh");
//alert(JSON.stringify(msg));
if (msg) {
try {。。。。。。。。。
就是调用的后台 chartmanage2方法返回数据:
后台代码:
public void ChartManage2(){
//HttpServletResponse resp = ServletActionContext.getResponse();
//response.setCharacterEncoding("utf-8");
//response.setContentType("text/json;charset=UTF-8");
ArrayList lst = new ArrayList();
for (int i = 1; i <= 3; i++)
{
//奖项
abc st2 = new abc();
st2.name1 = i + "等奖";//一等奖,二等奖,三等奖
for (int j = 2014; j < 2027; j++)
{
st2.data.add(2);//每年的论文数量
}
lst.add(st2);
}
// JSONObject json = new JSONObject(lst);
setAttr("username",lst);
但是调用的时候一直会报:404 not found错误,最后发现时url没有被认出来,再后台controller方法前加上标示后解决:
@ActionKey("/Blog/ChartManage2")
public void ChartManage2(){
具体原理不清楚,主要还是对javaweb开发不熟导致的,继续学习吧,还有很多不知道的东西。