ITPub博客

首页 > Linux操作系统 > Linux操作系统 > getJSON

getJSON

原创 Linux操作系统 作者:nimingyonghu 时间:2013-06-23 14:53:38 0 删除 编辑
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;
import com.shengsiyuan.action.xml.People;

public class GetJsonAction extends ActionSupport
{
private String name;
public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

@Override
public String execute() throws Exception
{
People people = new People();
people.setId(1);
people.setName(name);
people.setAge(30);
people.setAddress("beijing");
Gson gson = new Gson();
String result = gson.toJson(people);
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/json; charset=utf-8");
response.setHeader("cache-control", "no-cache"); 
PrintWriter ut = response.getWriter();
out.print(result);
out.flush();
out.close();
return null;
}
}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28995756/viewspace-764625/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2013-06-23

  • 博文量
    1
  • 访问量
    1651