b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

ognl表达式和el表达式_ognl取值_jsel表达式和ognl

电脑杂谈  发布时间:2017-02-12 08:02:31  来源:网络整理

ognl表达式和el表达式_jsel表达式和ognl_ognl取值

jsp EL表达式中令人郁闷的int/float/char

博客分类: java webjava开发常见问题分析

在EL表达式计算过程中,有朋友会遇到许多奇怪的问题,经常非常郁闷,在此我把这些总结一下,方便查询:

1、所有的整数数字字面量都是Long类型的;

2、所有小数字面量都是Double类型的;

3、""或''声明的是字符串,即''也是字符串,非char;

4、比较时都是equals比较。

接下来看几个可能出问题的例子,你会遇到一下的几个呢:

1、

如${1+2147483647} 结果是多少?

如果在java程序里边运行会得到-2147483648,而在jsp el中会得到2147483648。ognl表达式和el表达式

2、

<%

Map<Object, Object> map = new HashMap<Object, Object>();

map.put(new Long(1), 123);

request.setAttribute("map", map);

request.setAttribute("a", new Long(1));

%>

${map[1]} 正确

${map[a]} 正确

3、

<%

Map<Object, Object> map = new HashMap<Object, Object>();

map.put(new Integer(1), 123);

request.setAttribute("map", map);

request.setAttribute("a", new Long(1));

request.setAttribute("b", new Integer(1));

%>

${map[1]} 错误

${map[a]} 错误

${map[b]} 正确

4、

<%

Map<Object, Object> map = new HashMap<Object, Object>();

map.put(1.1, 123); //map.put(1.1d, 123);

request.setAttribute("map", map);

request.setAttribute("a", new Double(1.1));

%>

map.a=${map[1.1]} 正确

map.a=${map[a]}正确

5、

<%

Map<Object, Object> map = new HashMap<Object, Object>();

map.put(1.1f, 123); //map.put(new Float(1.1), 123);

request.setAttribute("map", map);

request.setAttribute("a", new Double(1.1));

request.setAttribute("b", new Float(1.1));

%>

map.a=${map[1.1]} 错误

map.a=${map[a]}错误

map.a=${map[b]}正确

6、

结合struts2的ognl表达式

<s:property value="#map = #{&#39;a&#39;:123, &#39;b&#39;:234}, &#39;&#39;"/> --->定义一个map,放入值栈的上下文区


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-31948-1.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 陈宇凡
      陈宇凡

      绝对应该对社会做个正式的道歉

    • 袁求贤
      袁求贤

      当然如果你还给孩子还房贷什么的就没办法了

    热点图片
    拼命载入中...