<script>
var c;
var database = "torchdb";
var ou;
DBCursor cursor;
try {
MongoClient mongoClient = new MongoClient();
DB db = mongoClient.getDB(database);
DBCollection con = db.getCollection("torchReleaseUnit");
cursor = con.find();
while(cursor.hasNext())
{
//out.println(cursor.next());
ou +=cursor.next();
}
out.println(ou);
c = JSON.parse(ou);
out.println(c);
out.println("middle");
}
finally{
cursor.close();
}
</script>
我正在尝试从mongoDB访问数据但无法访问它。似乎脚本标记不会执行。
我需要像这样格式化
enter code here try {
// read the json file
JSONParser jsonParser = new JSONParser();
JSONArray a = (JSONArray)jsonParser.parse(ss);
for (Object o : a)
{
JSONObject person = (JSONObject) o;
Long id = (Long) person.get("_id");
%>
<tr>
<td><%out.println(id); %></td>
<%String ip = (String) person.get("ip");%>
<td><%out.println(ip); %></td>
<% String test_type = (String) person.get("test_type");%>
<td><%out.println(test_type); %></td>
<% String os = (String) person.get("operating_system");%>
<td><%out.println(os); %></td>
<% String status = (String) person.get("status");%>
<td><%out.println(status);%></td>
</tr>
<%
}%>
</table>
<% }
最后{} %GT;