JSP自定义标签扩展----支持EL,访问Spring容器
来源:互联网 发布:java await notifyall 编辑:程序博客网 时间:2024/05/22 06:11
目录:
一、使JSP自定义标签支持EL表达式(${})
二、如果在JSP自定义标签中,须要拿到spring IOC容器管理的bean
伦理片 http://www.dotdy.com/
一、使JSP自定义标签支持EL表达式(${})
我写了自定义标签a:rim,想让他的title属性支持${},可是出现了异常.
- <%
- String str = "这是EL表达式从 request中取出来的文字!";
- request.setAttribute("str",str);
- %>
- <a:rim title="${tut}">
要做下面两件事就可以达到目的了:
1 在tld文件如下配置:
- <tag>
- <icon>
- </icon>
- <name>rim</name>
- <tag-class>com.xui.overall.RimTag</tag-class>
- <body-content>JSP</body-content>
- <attribute>
- <name>title</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
其中关键的是 <rtexprvalue>true</rtexprvalue> ,使title属性可以接受EL表达式.
2 对接收到的EL表达式处理
title属性的 set get 方法 如下写
- private Object title = "";
- public void setTitle(final Object title) throws JspException
- {
- // 对EL表达式的支持
- this.title = ExpressionEvaluatorManager.evaluate("title", title.toString(), Object.class, this, pageContext);
- }
- public Object getTitle()
- {
- return title;
- }
这里处理${}的是org.apache.taglibs.standard.lang.support下,有个叫 ExpressionEvaluatorManager类,
ExpressionEvaluatorManager.evaluate有五个参数。第一个title属性的名字,本例用"title"就行。第二个要求字符串,通常简单调用输入对象的toString方法。第三个是类,通常用Object.class。第四个用this即可,第五个是pageContext变量。
注意:当你的tag属性支持el表达式时,你必须把它声明为Object对象:本例中是 private Object title = "标题";
这样工作就做完了,自定义标签就可以处理 ${}了.
二、如果在JSP自定义标签中,须要拿到spring IOC容器管理的bean可以:
你的JSP自定义标签类可以从org.springframework.web.servlet.tags.RequestContextAwareTag继承,使用
getRequestContext().getWebApplicationContext()可以得到spring的context
- JSP自定义标签扩展----支持EL,访问Spring容器
- JSP自定义标签扩展----支持EL,访问Spring容器
- 基于Spring可扩展Schema提供自定义配置支持(spring配置文件中 配置标签支持)
- 基于Spring可扩展Schema提供自定义配置支持(spring配置文件中 配置标签支持)
- 基于Spring可扩展Schema提供自定义配置支持(spring配置文件中 配置标签支持)
- 基于Spring可扩展Schema提供自定义配置支持(spring配置文件中 配置标签支持)
- 基于Spring可扩展Schema提供自定义配置支持(spring配置文件中 配置标签支持)
- jsp自定义标签tag EL函数
- 自定义jsp标签和El表达式
- 18、EL表达式、JSP标签、JSTL标签、自定义标签
- EL表达式、JSP标签、JSTL标签、自定义标签
- 使用SimpleTag支持自定义JSP标签
- jsp 自定义标签【EL表达式定义】 简单例子一
- jsp自定义标签-----EL表达式中连接两个字符串
- JSP页面中的EL自定义标签及使用
- Spring扩展Schema提供自定义配置支持
- 让jsp支持EL
- spring扩展自定义标签的方法
- 网易游戏2011.10.15校园招聘笔试题
- Opencv学习笔记(背景更新---目标跟踪)
- 去除jsp执行后,网页源码中的空行
- Could not instantiate bean class [org.springframework.web.multipart.MultipartFile]: Specified class
- WebService学习笔记(二)服务端Demo
- JSP自定义标签扩展----支持EL,访问Spring容器
- Git使用教程
- Linux战地日记——历史命令
- jQuery 将网页中一个表格中的数据已行为最小单元添加到另外的一个表格当中
- 初识 Spring 框架,进入Spring的世界
- [企业管理]到了移动互联网泡沫破裂的时候了
- 如何判断程序是x86还是x64类型
- 笔记---多页面控制 (不定时更新)
- OPENCV——直方图计算calcHist