forked from JoyChou93/java-sec-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.java
More file actions
52 lines (42 loc) · 1.42 KB
/
Index.java
File metadata and controls
52 lines (42 loc) · 1.42 KB
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
package org.joychou.controller;
import com.alibaba.fastjson.JSON;
import org.apache.catalina.util.ServerInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* Index page
*
* @author JoyChou @2018-05-28
*/
@Controller
public class Index {
@RequestMapping("/appInfo")
@ResponseBody
public static String appInfo(HttpServletRequest request) {
String username = request.getUserPrincipal().getName();
Map<String, String> m = new HashMap<>();
m.put("tomcat_version", ServerInfo.getServerInfo());
m.put("username", username);
m.put("login", "success");
m.put("app_name", "java security code");
m.put("java_version", System.getProperty("java.version"));
m.put("fastjson_version", JSON.VERSION);
// covert map to string
return JSON.toJSONString(m);
}
@RequestMapping("/")
public String redirect() {
return "redirect:/index";
}
@RequestMapping("/index")
public static String index(Model model, HttpServletRequest request) {
String username = request.getUserPrincipal().getName();
model.addAttribute("user", username);
return "index";
}
}