« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
| 公告 |
戒除浮躁,读好书,交益友 |
Blog信息 |
blog名称:邢红瑞的blog 日志总数:523 评论数量:1142 留言数量:0 访问次数:9693465 建立时间:2004年12月20日 |

| |
[j2ee]resin标签EL表达式的执行问题 原创空间, 软件技术, 电脑与网络, 科学研究
邢红瑞 发表于 2008/7/6 16:12:20 |
现在遇到这个问题真是丢人。写一个tag 就是实现 几小时进分钟前的显示很简单import java.io.*;import java.util.Date;
import javax.servlet.jsp.tagext.*;
public class RequestTag extends SimpleTagSupport { public String getTime() { return time; }
public void setTime(String time) { this.time = time; }
private String time;
public void doTag() throws IOException { System.out.println(time); long tt = 0; try { tt = Long.parseLong(time); } catch (NumberFormatException nfe) { tt=new Date().getTime(); } getJspContext().getOut().println(formatDiggTime(tt)); }
public static String formatDiggTime(long time) { long interval = System.currentTimeMillis() - time;
int minu = (int) (interval / (60 * 1000)); int hour = minu / 60; int day = hour / 24;
StringBuffer sb = new StringBuffer(); if (day >= 1) { sb.append(day); sb.append("天"); }
if (hour < 48 && hour > 0) { int dayhour = hour % 24; if (dayhour > 0) { sb.append(dayhour); sb.append("小时"); } }
if (hour < 24) { sb.append(minu % 60); sb.append("分钟"); }
sb.append("前"); return sb.toString(); }
public static void main(String[] args) { Date dt = new Date(); System.out.println(dt.getTime()); }}标签体<tag> <name>formattime</name> <tag-class> com.xxx.web.util.RequestTag</tag-class> <body-content>empty</body-content> <attribute> <name>time</name> </attribute> </tag>jsp内写法<req:formattime time="${time}" />返回一直是0分钟前,一般的servlet都有将string int long 自动转换的能力,浮点不保证有。调试进去一看time的值是${time},气个半死,原来是EL表达时没有执行。但是同一个jsp里面的jstl 用得不错。但是对于resin来说,jstl resin使用自己优化的版本,基本不靠谱。看了jstl标签 标签体改为 <tag> <name>formattime</name> <tag-class> com.xxx.web.util.RequestTag</tag-class> <body-content>empty</body-content> <attribute> <name>time</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute>一切ok,郁闷啊禁止EL表示式执行web.xml web.xml 是 verstion 2.4 或以上的版本 加入 <jsp-config> 包括<taglib> 和<jsp-property-group> 两个子元素。:
<jsp-config> <taglib> <taglib-uri>Taglib</taglib-uri> <taglib-location>/WEB-INF/tlds/MyTaglib.tld</taglib-location> </taglib> <jsp-property-group> <description>Special property group for JSP Configuration JSP example.</description> <display-name>JSPConfiguration</display-name> <url-pattern>/jsp/* </url-pattern> <el-ignored>true</el-ignored> <page-encoding>GB2312</page-encoding> <scripting-invalid>true</scripting-invalid> <include-prelude>/include/prelude.jspf</include-prelude> <include-coda>/include/coda.jspf</include-coda> </jsp-property-group></jsp-config> 其中<taglib>元素在JSP 1.2时就已经存在;而<jsp-property-group>是JSP 2.0 新增的元素。 <jsp-property-group>元素主要有八个子元素,它们分别为: 1.<description>:设定的说明; 2.<display-name>:设定名称; 3.<url-pattern>:设定值所影响的范围,如:/CH2 或 /*.jsp; 4.<el-ignored>:若为true,表示不支持EL 语法; 5.<scripting-invalid>:若为true,表示不支持<% scripting %>语法; 6.<page-encoding>:设定JSP 网页的编码; 7.<include-prelude>:设置JSP 网页的抬头,扩展名为.jspf; 8.<include-coda>:设置JSP 网页的结尾,扩展名为.jspf。
JSP2.0中默认启用JSP EL表达式。<% @page isELIgnored = "true|false"%>其中,page表示页面指令,isELIgnored确定是否应忽略对EL表达式进行计算。如果isELIgnored设置为true,当EL表达式在静态文本或标签属性中出现时将被忽略;如果isELIgonred设置为false,EL表达式则由JSP容器进行计算。<?xml version="1.0" encoding="ISO-8859-1"?> web.xml 2.0的头<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>WebModule1 </display-name> </web-app>
看了看,规范没有默认是就是false
rtexprvalue
Defines if the nesting attribute can have scriptlet expressions as a value, i.e., the value of the attribute may be dynamically calculated at request time, as opposed to a static value determined at translation time.
The syntax is:<!ELEMENT rtexprvalue (#PCDATA) > #PCDATA ::= true | false | yes | no
If not present then the default is "false," i.e., the attribute has a static value. |
|
|