package com.struts2.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.Action;
import net.sf.json.JSONArray;
public class JSONExample {
private String pass;
private String email;
private String address;
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
private int[] ints = { 10, 20 };
private Map map = new HashMap();
private String customName = "custom";
public String execute(){
map.put("email", "[email protected]");
//格式化时间
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//设置javabean值
JSONExample test = new JSONExample();
test.setCustomName("admin");
test.setEmail("[email protected]");
test.setAddress(format.format(new Date()));
test.setMap(map);
//格式化javabean里的值
JSONArray array = JSONArray.fromObject(test);
return Action.SUCCESS;
}
public int[] getInts() {
return ints;
}
public void setInts(int[] ints) {
this.ints = ints;
}
public Map getMap() {
return map;
}
public void setMap(Map map) {
this.map = map;
}
@JSON(name="newName")
public String getCustomName() {
return customName;
}
public void setCustomName(String customName) {
this.customName = customName;
}
//测试json数据格式输出
public static void main(String[] args) {
//格式化时间
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//设置javabean值
JSONExample test = new JSONExample();
test.setCustomName("admin");
test.setEmail("[email protected]");
test.setAddress(format.format(new Date()));
//格式化javabean里的值
JSONArray array = JSONArray.fromObject(test);
System.out.println(array.toString());
}
}
struts2+json结合
4星 · 超过85%的资源 需积分: 9 90 浏览量
2008-09-03
11:56:02
上传
评论
收藏 4.5MB RAR 举报
godenvoy
- 粉丝: 0
- 资源: 1
最新资源
- 基于mysql和python的学生选课系统【课程设计(实验报告+源码)】
- PxCook-像素大厨Windows版本安装包
- aspose-words-23.12-jdk16 有水印
- [大模型部署]在C# Winform中使用文心一言ERNIE-3.5 4K 聊天模型
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统设计与实现.zip
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统设计与实现+使用说明.zip
- 基于STM32单片机空气监测系统设计源码+详细文档+配套全部资料(毕业设计).zip
- rdf0412-kcu116-pcie-c-2019-1.zip(XILINX KCU116 源码)
- 基于C#语言的winform界面火车票订票系统(源码+实验报告)
- 【华为OD部分真题及讲解】华为OD部分真题及讲解
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈