본문 바로가기

컴퓨터/Spring

jstl custom tag 에서 spring bean 주입하기

1. RequestContextAwareTag 상속받기

1
2
3
4
5
6
7
8
9
10
11
 
public class XXXTag extends RequestContextAwareTag {
    @Override
    protected int doStartTagInternal() throws Exception {
        // WebApplicationContext 를 얻는다.
        WebApplicationContext ctx = getRequestContext().getWebApplicationContext();
        // bean 주입
 
        return SKIP_BODY;
    }
cs

 

 



2. request 사용하기

 

 

1
2
3
4
5
6
7
8
9
10
11
 
 public class XXXTag extends SimpleTagSupport {
    @Override
    public void doTag() throws JspException, IOException {
        PageContext context = (PageContext) getJspContext();
        HttpServletRequest request = (HttpServletRequest) context.getRequest();
        ApplicationContext applicationContext = RequestContextUtils.findWebApplicationContext(request);
        // bean 주입 
    }
 
}

 

https://luigi-yoon.tistory.com/1

 

 

jstl custom tag 에서 spring bean 주입하기

1. RequestContextAwareTag 상속받기 1 2 3 4 5 6 7 8 9 10 11 public class XXXTag extends RequestContextAwareTag {     @Override     protected int doStartTagInternal() throws Exception..

luigi-yoon.tistory.com

 

 

'컴퓨터 > Spring' 카테고리의 다른 글

[JSTL] 커스텀 태그 작성하기  (0) 2022.03.15