Spring Redirect시에 데이타 숨겨서 넘기는 방법
Spring Redirect시에 데이타 숨겨서 넘기는 방법
Spring Redirect시에 데이타 넘기는 방법
Spring MVC에서 페이지 Rediect를 하는 방법은 간단하다.
그냥 “rediect:${원하는 페이지주소}” 형식으로 입력하면 된다.
문제는 Redirect시에 데이타를 넘겨서 보내줄 때이다.
보여주고 싶지 않은 데이타도 Rediect시에는 쿼리스트링으로 넘겨주기 때문에 모두 보여진다.
RedirectAttributes.java
라는 놈을 이용하면 사용자에게 보여주 싶지 않은 데이타는 노출하지 않고 넘겨 줄 수 있다.
RedirectAttributes : org.springframework.web.servlet.mvc.support.RedirectAttributes
1
2
3
4
5
6
7
8
9
10
@RequestMapping("/test.do")
public String sendTest(RedirectAttributes redirectAttributes){
redirectAttributes.addFlashAttribute("KeyName", "KeyValue");
return "redirect:/receive.do";
}
@RequestMapping("/receive.do")
public String receiveTest(){
return "resultJSP";
}
/receive.do
의 메소드에는 별도의 작업을 하지 않고 결과 resultJSP
페이지에서 바로 EL 태그로 사용한다.
1
KeyName : ${KeyName}
참고 페이지 :
- https://github.com/SpringSource/spring-framework/blob/master/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributes.java
- http://viralpatel.net/blogs/spring-mvc-flash-attribute-example/
This post is licensed under
CC BY 4.0
by the author.