淘先锋技术网

首页 1 2 3 4 5 6 7

1.下载json包

2.若使用eclipse for java EE+tomcat开发服务器,则json包需要导入到WEB-INF下的lib目录下。直接拷贝进去

3.编写jsp内容

<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="org.json.JSONArray" %>
<%@ page import="org.json.JSONObject" %>
<html>
<head>
  <title><s:text name="hello.title"/></title>
</head>
<body>
<%!
String jString="ddd";
%>
<%
try {

JSONArray jsonArray=new JSONArray();
JSONObject jsonObject=new JSONObject();
jsonObject.put("code","1");
jsonObject.put("msg", "loginsuccess");
jsonArray.put(jsonObject);
jString=jsonArray.toString();
System.out.print(jString);
} catch (Exception e) {

e.printStackTrace();
}
%>
<%=jString %>


</body>
</html>