FrameWork/Spring

[spring] taglib 활용

밍글링글링 2018. 4. 24.
728x90

사용할 JSP 페이지에서

<%@ taglib prefix="zz" tagdir="/WEB-INF/tags"%>
<zz:user-detail />
 

해당 URL에서 

<%@ tag import="com.chequer.axboot.core.utils.JsonUtils"%>
<%@ tag import="org.springframework.security.core.userdetails.UserDetails"%>
<%@ tag import="com.jungle.common.utils.SessionUtils"%>
<%@ tag import="java.util.*"%>
<%@ tag language="java" pageEncoding="UTF-8" body-content="scriptless"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
    UserDetails detail = SessionUtils.getCurrentUserDetail();
    String json = JsonUtils.toJson(detail);
%>
<script type="text/javascript">
    window.USER_DETAIL = function () {
        return <%=json%>;
    }
</script>
 

.JS

var userDetail = USER_DETAIL();
res.memberId = userDetail.memberId;

 
728x90

댓글