jquery请求action,添加spring后无返回值

jquery请求action,如果list是在action里创造的,可以返回jsp页面,但是如果list是通过spring读取数据库得到的,缺无法返回jsp页面,请指点。

jsp代码

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<html>
  <head>
    <script type="text/javascript" src="<c:url value='/js/jquery-1.4.2.min.js'/>"></script>
    
  </head>
  <body>
    <a href="javascript:bb();">测试返回json数组</a>
    <br/>
    <table id="_t" border="1">
        <tr><td>Name</td></tr>
        
    </table>
  </body>
  <script type="text/javascript">
     function aa(){
        //var url = "<c:url value='one.action'/>";
        $.post("one.action",{},function(json){
            alert("name: "+json.name+",age: "+json.age);
        },"json");
     }
     function bb(){
        var url = "<c:url value='/first/two.action'/>";
        alert("123");
        $.post(url,{},function(json){
            alert("456");
            alert(json.jlist[0].users_name);
        },"json");
     }
  </script>
</html>

 xml代码

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="true" ></constant>
    <constant name="struts.i18n.encoding" value="UTF-8"></constant>
    <constant name="struts.custom.i18n.resources" value="application"></constant>
    <package name="sun" extends="json-default" namespace="/first">
        <action name="two" class="twoaction">
            <result name="success" type="json"></result>
        </action>
    </package>
</struts>

 action代码

package com.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import com.users.service.IUserService;

public class TwoAction extends ActionSupport{
    private List jlist;
    private IUserService service;

    public List getJlist() {
        return jlist;
    }

    public void setJlist(List jlist) {
        this.jlist = jlist;
    }

    public IUserService getService() {
        return service;
    }

    public void setService(IUserService service) {
        this.service = service;
    }

    public String execute(){
        System.err.println("two.....");
        jlist = new ArrayList();
        jlist = getService().UsersLoad(3);
//      jlist = list;
//      for(int i=0;i<10;i++){
//          Map map = new HashMap();
//          map.put("name", "Hello"+i);
//          jlist.add(map);
//      }
//      Map map = new HashMap();
//      map.put("users_id", 3);
//      map.put("users_name", "users_03");
//      map.put("users_sex", 1);
//      jlist.add(map);
        System.err.println(jlist);
        return SUCCESS;
    }
}

 System.err.println(jlist);成功在后台打出来了,但是jsp页面上没有反应,请问哪里出问题了?

查看全部
weixin_42382460
独白°
2010/07/12 07:42
  • it技术
  • 互联网问答
  • IT行业问题
  • 编程语言问答
  • 计算机技术
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

0个回复