新增服务器列表显示list.jsp

master
wukang 2019-01-04 11:03:10 +08:00
parent 6b513c704b
commit bb18d87e40
3 changed files with 169 additions and 0 deletions

View File

@ -0,0 +1,73 @@
package com.ljsd.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ljsd.pojo.UserServerInfo;
import com.ljsd.redis.RedisKey;
import com.ljsd.util.BaseGlobal;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ServerListController extends HttpServlet{
private String message;
private final static String _COLLECTION_NAME = "server_info";
public void init() throws ServletException
{
// 执行必需的初始化
try {
List<DBObject> serverInfoList = BaseGlobal.getInstance().mongoDBPool.findList(_COLLECTION_NAME);
message = serverInfoList.toString();
} catch (Exception e) {
e.printStackTrace();
}
// message = "Hello World";
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// 设置响应内容类型
// response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
// 实际的逻辑是在这里
PrintWriter out = response.getWriter();
String title = "戒灵服务器列表";
String docType =
"<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType +
"<html>\n" +
"<head><meta charset=\"utf-8\"><title>" + title + "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + title + "</h1>\n" +
message +
"<table width=\"100%\" border=\"1\" align=\"center\">\n" +
"<tr bgcolor=\"#949494\">\n" +
"<th>ID</th><th>服务器名</th><th>ip</th><th>port</th><th>server_id</th><th>渠道</th><th>子渠道</th><th>plat</th><th>状态</th><th>开服时间</th>\n"+
"</tr>\n");
//out.println("<h1>" + "戒灵服务器列表:" + "</h1>");
//out.println("<h3>" + message + "</h3>");
}
public void destroy()
{
// 什么也不做
}
}

View File

@ -50,6 +50,15 @@
<url-pattern>/getUserInfo</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>serverList</servlet-name>
<servlet-class>com.ljsd.controller.ServerListController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>serverList</servlet-name>
<url-pattern>/serverList</url-pattern>
</servlet-mapping>
<listener>

View File

@ -0,0 +1,87 @@
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@page import="com.ljsd.controller.ServerListController,com.ljsd.controller.ServerListController"%>
<%@ page import="com.mongodb.DBObject" %>
<%@ page import="com.ljsd.util.BaseGlobal" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Show Table</title>
</head>
<style>
.bbody{
margin-left:300px;
margin-top:100px
}
.bbody > table {
height:200px;
width:400px;
}
td{
text-align:center;
}
</style>
<body>
<div class="bbody">
<table border="1">
<tr >
<td>ID</td>
<td>服务器名</td>
<td>ip</td>
<td>port</td>
<td>server_id</td>
<td>渠道</td>
<td>子渠道</td>
<td>plat</td>
<td>状态</td>
<td>开服时间</td>
</tr>
<%
List<DBObject> serverInfoList = BaseGlobal.getInstance().mongoDBPool.findList("server_info");
String message = serverInfoList.toString();
{%>
var jsonString = <%=message%>
var jsObject = JSON.parse(jsonString);
alert(jsObject._id);
<tr>
<td><%=message%></td>
<td><%=2 %></td>
<td><%=3 %></td>
<td><%=4 %></td>
<td><%=1 %></td>
<td><%=2 %></td>
<td><%=3 %></td>
<td><%=4 %></td>
<td><%=1 %></td>
<td><%=2 %></td>
</tr>
<tr>
<td><%=999 %></td>
<td><%=999 %></td>
<td><%=999 %></td>
<td><%=999 %></td>
<td><%=999 %></td>
<td><%=999 %></td>
<td><%=999 %></td>
<td><%=999 %></td>
<td><%=999 %></td>
<td><%=999 %></td>
</tr>>
<%}
%>
</table>
</div>
</body>
</html>