文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > 计算机软件及应用 > struts2转成json
侵权投诉

struts2转成json

commons-lang-2.4.jar;

json-lib-2.3-jdk13.jar;

jsonplugin-0[1].32.jar;

ezmorph-1.0.2.jar;

commons-beanutils-1.7.0.jar;




commons-collections-3.2.1.jar(这个包要注意版本,我用2.1不行)


还需要把jquery-1[1].2.6.pack.js;

struts.xml配置:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"doc.guandang.net;
<struts>
<package name="ajax" extends="json-default">
<action name="testAction" class="model.testAction">
<result type="json">/index.jsp</result>
</action>
</package>
</struts>

testAction.java

package model;

import net.sf.json.JSONObject;

import com.opensymphony.xwork2.ActionSupport;

public class testAction extends ActionSupport {
User user;
String result;
@Override
public String execute() throws Exception {
JSONObject js=JSONObject.fromObject(user) ;
System.out.println(js);
result=js.toString();
return SUCCESS;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}


package model;

public class User {
String username;
String password;

public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
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 'index.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" type="text/css" href="styles.css">
-->

<script type="text/javascript" src="<%=path %>/js/jquery-1[1].2.6.pack.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
var params=$("input").serialize();
$.ajax({
url:"testAction.action",
type:"post",
dataType:"json",
data:params,
success:update_page


});
});
});
function update_page(result){

var json=eval(result);
alert(json);
var str="姓名:"+json.user.username+"<br>";
str+="密码:"+json.user.password+"<br>";
$("#result").html(str);
}
</script>

</head>

<body>
<div id=

第1页

热门文档

相关文档

  • Struts2返回JSON数据原理

    Struts2返回JSON数据原理_计算机软件及应用_IT/计算机_专业资料。JSON(JavaScript...我们需要做的是将数据从存放位置中取出,然后将其转 换为 JSON 字符串,输出在...

  • Struts2返回JSON对象

    Struts2返回JSON对象_IT/计算机_专业资料。Javascript 操作 JSON 格式的 ...json 拦截器会将相关联的所有对象的属性全部转换成 json 格式, 如果其它对象有...

  • json和struts2

    json和struts2_计算机软件及应用_IT/计算机_专业资料。该文件介绍如何在struts...通过debug你会发现前台返回的json字符串,是把action中的所有属性全部转化成json...

  • 在STRUTS2中如何使用JSON

    在STRUTS2中如何使用JSON_IT/计算机_专业资料。STRUTS2 对 JSON 的做了很好...{ //请求的地址 var url = 'res.action'; //将form1表单域的值转换为...

  • Struts2_Jsonplugin_详解

    在Struts 2 中使用 JSON Ajax 支持 JSON 插件提供了一种名为 json 的 Result...Struts2 Jsonplugin 详解 本文转自: http://www.blogjava.net/fuhoujun/...

  • struts2使用json返回对象和列表(案例)

    struts2使用json返回对象和列表(案例)_IT/计算机_专业资料。返回对象: 返回...{ // 将 JSON 对象转换为 JSON 字符串,需要注意调用 eval 函数时必须使用"(...

  • Struts2中的Json使用

    Struts2中的Json使用_四年级语文_语文_小学教育_教育专区。这是描述Struts2中...你会发现前台返回的json字符串,是把action中的所有属性全部转化为json字符串返回...

  • Struts2返回JSON及注意事项

    Struts2返回JSON及注意事项_计算机软件及应用_IT/计算机_专业资料。Struts2返回JSON及注意事项今日推荐 180份文档 CET四六级高分通关宝典...

  • 后台转换JSON数据类型,前台解析JSON数据等等例子总结

    6.json-lib-2.2.2-jdk15.jar , 由于在 struts2 中没有自带的 .ezmorph.jar ,一开始 List 对象列表转换成 json 数据格式的时候并不对还报错 List<Image...

  • Struts2+JQuery+JSON集成

    Struts2+JQuery+JSON集成_计算机软件及应用_IT/计算机_专业资料。用几乎一天的...(jo); //调用 json 对象的 toString 方法转换为字符串然后赋值给 result ...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email