zoukankan      html  css  js  c++  java
  • Spring SpEL in JSP and Assign SpEL value to Java variable in JSP

    Spring SpEL in JSP and Assign SpEL value to Java variable in JSP
    
        method 1  use----ServletContextAttributeExporter 
    org.springframework.web.context.support.ServletContextAttributeExporter
    
    xml----->
    -------------------
    <bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
            <property name="attributes">
                <map>
                <entry  key="attrname"><value>oracle_name</value></entry>    
                <entry  key="attrvalue"><value>235</value></entry>           
                </map>
            </property>
        </bean>
    
    
    jsp----->
      name:  ${attrname}
      password: ${attrvalue}
      
       <%  //in jsp assign Spel(spring expression) value to java var
       String attrname=(String)application.getAttribute("attrname");
       String attrvalue=(String)application.getAttribute("attrvalue");
       System.out.println(attrname+"----1-----"+attrvalue);
       %>
    --------------------
    
    ===================================================================================
    
        method 2    use-----util:properties
        add your.properties , add add next sentences
        
        xmlns:util="http://www.springframework.org/schema/util"  
         http://www.springframework.org/schema/util 
         http://www.springframework.org/schema/util/spring-util-3.0.xsd  
         
        <util:properties id="comProp" location="classpath:/comProp.properties"/>
         
        jsp add 
         //show  ,if not define var ,expression will show value direct.
         
         <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
         <%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
         
         <spring:eval expression="@comProp.getProperty('db_name')" var="db_name" scope="application"/>
         <spring:eval expression="@comProp.getProperty('db_password')" var="db_password" scope="application"/>
         
         ${db_name}  /  ${db_password}  
         
       <% //in jsp assign Spel(spring expression) value to java var
       String abc=(String)application.getAttribute("db_name");
       String abcd=(String)application.getAttribute("db_password");
       System.out.println(abc+"---------"+abcd);
       %>
         
         
      Reference SpEL tag https://docs.spring.io/spring/docs/current/spring-framework-reference/html/spring-tld.html#spring.tld.eval
     
         
  • 相关阅读:
    在有跳板机的情况下,SecureCRT自动连接到目标服务器
    JavaScript中使用console调试程序的坑
    Python中docstring文档的写法
    Nginx+uWSGI+Django原理
    uWSGI uwsgi_response_write_body_do(): Connection reset by peer 报错的解决方法
    Python LOGGING使用方法
    Python计算斗牛游戏的概率
    Python垃圾回收机制详解
    PhantomJS实现最简单的模拟登录方案
    如何设置Jquery UI Menu 菜单为横向展示
  • 原文地址:https://www.cnblogs.com/rojas/p/6635792.html
Copyright © 2011-2022 走看看