Web/Spring 2018. 10. 23. 23:58

사실 아예 숨기는 것이라고는 말할 수 없지만 보통 사용자들이 보이지 않는다고 생각할 수 있는 쿼리파라미터를 생략한 뷰리턴 방법입니다. 사실상 보안에 강하다라는 그런 방법은 아닙니다. 단지 보이지 않을 뿐입니다.


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
package com.kt.chatbot.ui.controller;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
@Controller
public class ChatController {
 
    private final static Logger log = LoggerFactory.getLogger(ChatController.class);
    
    /*
     * yeoseong_yoon,2018/10/23
     * query string 을 숨기기 위한 처리로직 포함
     */
    @RequestMapping("/chat.do")
    public String getChatRedirect(@RequestParam(value="userId"String userId,@RequestParam(value="channel"String channel,RedirectAttributes redirectAttr) {
        
        redirectAttr.addFlashAttribute("userId",userId);
        redirectAttr.addFlashAttribute("channel",channel);
        return "redirect:/chat";
    }
    
    @RequestMapping("/chat")
    public String getChatView() {
        return "chat";
    }
}
 
 
cs


첫번째 요청 chat.do?userId=aa&channel=PC 이런 식으로 쿼리파라미터를 포함하여 요청이 넘어옵니다. 이때 넘어온 파라미터를 RedirectAttributes라는 놈으로 받아서 리턴을 다른 컨트롤러 요청으로 리다이렉트해줍니다. 그러면 redirectAttr에 저장한 값들은 기존에 model에 넣은것처럼 그대로 jsp에서 ${변수명} 형태로 받을 수 있습니다. 만약 리턴하는 뷰페이지의 확장자를 그대로 보여도 된다면 바로 페이지로 리다이렉트 하셔도됩니다.

posted by 여성게
: