Jsp tag file例子以及说明(20)
throw (java.lang.IllegalStateException) t;
if( t instanceof javax.servlet.jsp.JspException )
throw (javax.servlet.jsp.JspException) t;
throw new javax.servlet.jsp.JspException(t);
} finally {
jspContext.getELContext().putContext(javax.servlet.jsp.JspContext.class,super.getJspContext());
((org.apache.jasper.runtime.JspContextWrapper) jspContext).syncEndTagFile();
}
}
例子7 嵌套引入tag file
taglibDemoTest.jsp
[java]
<%@ taglib prefix="easy" tagdir="/WEB-INF/tags" %>
<easy:taglibDemo/>//引入tag
tagliDemo.tag
[java]
<%@ taglib prefix="simple" tagdir="/WEB-INF/tags" %>
The server's date: <simple:firstTag>//继续嵌套引入tag\
firstTag.tag
[java]
<%@ tag import="java.util.Date" import="java.text.DateFormat"%>
<%
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG);
Date now = new Date(System.currentTimeMillis());
out.println(dateFormat.format(now));
%>
例子8 调用tag file的变量
varDemoTest.jsp
[java]
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
Today's date:
<br/>
<tags:varDemo>
In long format: ${longDate}
<br/>
In short format: ${shortDate}
</tags:varDemo>
varDemo.tag
[java]
<%@ tag import="java.util.Date" import="java.text.DateFormat"%>
<%@ variable name-given="longDate" %>
<%@ variable name-given="shortDate" %>
<%
Date now = new Date(System.currentTimeMillis());
DateFormat longFormat = DateFormat.getDateInstance(DateFormat.LONG);
DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);
jspContext.setAttribute("longDate", longFormat.format(now));
jspContext.setAttribute("shortDate", shortFormat.format(now));
%>
<jsp:doBody/>//说明要让jsp编译的java类回调,所以jsp编译的java类有Helper类封装JspFragment(即tag编译后的java类)
相关新闻>>
- 发表评论
-
- 最新评论 更多>>