日期:2014-05-16  浏览次数:20364 次

STRUTS2与JSON的LIST和MAP对象返回
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'JsonLogin.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">   
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="conf/themes/default/easyui.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="conf/themes/icon.css" type="text/css" media="screen" />
    <script src="conf/js/jquery-1.3.2.min.js"></script>
    <script src="conf/js/jquery.easyui.min.js"></script>
<script src="conf/js/easyui-lang-zh_CN.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

<script type="text/javascript">

$(document).ready(function() {
    // 直接把onclick事件写在了JS中
    $("#submit").click(function() {
       $.ajax({       
           url : "jsonLogin.action",// 后台处理程序         
           type : "post", // 数据发送方式          
           dataType : "json",// 接收数据格式
           //dataType : "text",          
           data : "loginBean.userName="+$("#username").val() + "&loginBean.passwd="+$("#password").val(),// 要传递的数据          
           // 回传函数
            timeout:20000,// 设置请求超时时间(毫秒)。
            error: function () {// 请求失败时调用函数。
                  $("#msg").html("请求失败!"); 
            }, 
            /* success:function(data){ //请求成功后回调函数。
             var dataObj=eval("("+data+")");//如果dataType是text则需要转换为json对象
             $("#msg").html(dataObj.message);
             alert("用户名:"+dataObj.user.username+",密码:"+dataObj.user.password);
            }*/
           
            success:function(data){ // 请求成功后回调函数。如果dataType是json不就需要再转换为json对象
           
   &n