Struts2 use Json
来源:互联网 发布:始作俑者,其无后乎 编辑:程序博客网 时间:2024/06/15 12:36
Struts2返回json需要jsonplugin-0[1].25的包
然后我们的配置文件中需要继承json-default
然后我们的Action中需要返回的json信息需要加上注解
然后我们的配置文件中需要继承json-default
- <?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>
- <package name="com.action.testJson" extends="json-default" namespace="/" >
- <action name="jsonUser" class="com.action.testJson.JsonAction" method="testUser">
- <result type="json"/>
- </action>
- <!-- Add actions here -->
- </package>
- </struts>
<?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> <package name="com.action.testJson" extends="json-default" namespace="/" > <action name="jsonUser" class="com.action.testJson.JsonAction" method="testUser"> <result type="json"/> </action> <!-- Add actions here --> </package></struts>
然后我们的Action中需要返回的json信息需要加上注解
- //pizza
- package com.action.testJson;
- import java.util.ArrayList;
- import java.util.List;
- import com.googlecode.jsonplugin.annotations.JSON;
- import com.opensymphony.xwork2.ActionSupport;
- public class JsonAction extends ActionSupport {
- private static final long serialVersionUID = -4082165361641669835L;
- Users user=new Users();
- List userList=new ArrayList();
- public String testUser(){
- System.out.println("in the json Acton");
- userInit();
- userList.add(user);
- return SUCCESS;
- }
- public void userInit(){
- user.setAge(1);
- user.setName("张泽峰");
- user.setPassword("nofengPassword");
- }
- @JSON(name="userString")
- public Users getUser() {
- return user;
- }
- @JSON(name="userList")
- public List getUserList() {
- return userList;
- }
- public void setUser(Users user) {
- this.user = user;
- }
- public void setUserList(List userList) {
- this.userList = userList;
- }
- }
- Struts2 use Json
- Use JSON in Flex
- Why to use JSON?
- Why to use JSON?
- struts2 json
- struts2+json
- Json+struts2
- Json+struts2
- struts2 json
- struts2 + JSON
- struts2 json
- struts2 json
- struts2 json
- Struts2 json
- struts2+json
- Struts2 JSON
- Lotus Notes Search Use JSON
- WCF use json communicate data
- VC预处理指令与宏定义的妙用
- CodeBlocks的一个小bug
- 微软架构师谈编程语言发展
- 正则表达式之道
- Mongodb快速入门之使用Java操作Mongodb
- Struts2 use Json
- 高级编程语言的发展历程
- 编码人员的误区
- C#之父Anders Hejlsberg演讲解读:编程语言大趋势
- SOSO平台部产品总监聊产品经理这一行
- 面向对象之父Alan Kay:预测未来,创造未来
- 主流计算机编程语言之父---集锦
- Oracle基础
- 【web】FireBug调试技巧