「Spring Boot」セッションIDを取得するサンプル

2021年11月12日

書式
request.getSession().getId()
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public class UserController {
// HttpSessionの場合
@GetMapping
String login(HttpSession session) {
String sesId = session.getId();
return "top";
}
// HttpServletRequestの場合
@GetMapping
String index(HttpServletRequest req) {
String sessId;
sessId = req.getSession().getId();
return "top";
}
}
public class UserController { // HttpSessionの場合 @GetMapping String login(HttpSession session) { String sesId = session.getId(); return "top"; } // HttpServletRequestの場合 @GetMapping String index(HttpServletRequest req) { String sessId; sessId = req.getSession().getId(); return "top"; } }
public class UserController {

    // HttpSessionの場合
    @GetMapping
    String login(HttpSession session) {
        String sesId = session.getId();
        return "top";
    }

    // HttpServletRequestの場合
    @GetMapping
    String index(HttpServletRequest req) {
        String sessId;
        sessId = req.getSession().getId();

        return "top";
    }
}

 

Spring Boot

Posted by arkgame