How to set the JSTL variable value in javascript?

后端 未结 8 2098
我在风中等你
我在风中等你 2020-11-27 16:56

How to set the JSTL variable value in java script?



        
8条回答
  •  失恋的感觉
    2020-11-27 17:39

    You can save the whole jstl object as a Javascript object by converting the whole object to json. It is possible by Jackson in java.

    import com.fasterxml.jackson.databind.ObjectMapper;
    
    public class JsonUtil{
       public static String toJsonString(Object obj){
          ObjectMapper objectMapper = ...; // jackson object mapper
          return objectMapper.writeValueAsString(obj);
       }
    }
    

    /WEB-INF/tags/util-functions.tld:

    
     
    
      1.0
      http://www.your.url/util-functions
    
      
          toJsonString
          your.package.JsonUtil
          java.lang.String toJsonString(java.lang.Object)
        
    
     
    

    web.xml

    
      
        http://www.your.url/util-functions
        /WEB-INF/tags/util-functions.tld
      
    
    

    mypage.jsp:

    <%@ taglib prefix="uf" uri="http://www.your.url/util-functions" %> 
    
    
    

提交回复
热议问题