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

最新文章

  1. java 生成 csv文件
  2. ssm(spring,springmvc,mybatis)
  3. bootstrap-进度条
  4. JavaScript高级---门面模式设计
  5. Android 的自定义Spinner组件实现方式
  6. Vijos P1325桐桐的糖果计划(有向图双连通分量)
  7. asp.net学习之GridView事件、GridViewRow对象
  8. 浅析PageRank算法
  9. Data access between different DBMS and other txt/csv data source by DB Query Analyzer
  10. 我的FPGA之旅4---led流水灯
  11. 2018 CCPC 网络赛 Buy and Resell
  12. 在 Linux 系统中读取 GBK 编码的文档
  13. RabbitMQ的安装与配置
  14. 制作docker基础镜像
  15. mongodb集群配置分片集群
  16. apache 80端口占用问题
  17. bootstrap css布局
  18. Kafka 配置
  19. 工程部署从tomcat6.0迁移到jboss6.0错误总结
  20. Webservice简单案例

热门文章

  1. TRIZ系列-创新原理-34-抛弃和再生部件原理
  2. cocos2d-x-lua基础系列教程一(hello lua)
  3. pugixml读取unicode编码的xml文件的做法
  4. windows 路由
  5. Promise语法
  6. js上传文件获取文件流
  7. luogu P2137 Gty的妹子树(分块,主席树)
  8. java 获取config 配置文件
  9. KVM 日常使用命令
  10. 一线 | 中国联通宣布首批5G手机到位