Struts 2中注解result type为json类型的小示例
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
java类代码:
package com.rain.json.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
@ParentPackage("json-default")
@Results({ @Result(name = "jsonExample", type = "json") })
public class JsonExampleAction {
private String result;
private String type;
@Action(value = "/json/jsonExample")
public String jsonExample() {
if ("json".equals(type)) {
result = "json";
} else {
result = "other";
}
return "jsonExample";
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
jsp页面代码:
<%@ 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>jsonExample</title>
<script type="text/javascript" src="<%=basePath%>js/base/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
function jsonExample(){
$.ajax({
type : "POST",
dataType : "json",
data : {type:"json"},
url : "<%=basePath%>json/jsonExample.do",
async : false,
success : function(data) {
if (data.result == "json") {
alert("json");
} else if (data.result == "other") {
alert("other");
}
}
});
}
</script>
</head>
<body>
<input type="button" value="json" οnclick="jsonExample();"/>
</body>
</html>
GitHub 加速计划 / js / json
18
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:3 个月前 )
2d42229f
* Support BSON uint64 de/serialization
Signed-off-by: Michael Valladolid <mikevalladolid@gmail.com>
* Treat 0x11 as uint64 and not timestamp specific
Signed-off-by: Michael Valladolid <mikevalladolid@gmail.com>
---------
Signed-off-by: Michael Valladolid <mikevalladolid@gmail.com> 4 天前
1809b3d8
Signed-off-by: Niels Lohmann <mail@nlohmann.me> 5 天前
更多推荐
已为社区贡献1条内容
所有评论(0)