-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax_server.jsp
52 lines (40 loc) · 1.33 KB
/
ajax_server.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.google.gson.*" %>
<%@ page import="java.io.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
JsonObject json = null;
String s = null;
try{
Process p = Runtime.getRuntime().exec("sh /Users/dou/hello.sh");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
int count = 0;
JsonArray array = new JsonArray();
while((s = stdInput.readLine()) != null){
System.out.println(s);
JsonObject obj = new JsonObject();
String arrays[] = s.split(" ");
int j = 0;
for(int i = 0; i < arrays.length; i++){
if(!arrays[i].equals("")){
obj.addProperty("item"+String.valueOf(j++), arrays[i]);
System.out.print(arrays[i] + " ");
}
}
array.add(obj);
count++;
}
json = new JsonObject();
json.addProperty("totals", count);
json.add("rows", array);
}catch(IOException e){
System.out.println("Excepiton happend -here's what I know:");
e.printStackTrace();
System.exit(-1);
}
response.getWriter().write(json.toString());
%>