Jsp tag file例子以及说明(17)
[java]
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
Your referer header:
${header.referer}//从http协议中header获取referer,上一个http地址(从这里跳转到当前的地址)
<br/>
<tags:doBodyDemo> //设置jspFragment为tag helper类
${header.referer}//将header.referer的值通过jspFragment的dotag,在dotag回调invoke(out),放入到jspFragment(tag编译后的类)指定的变量
</tags:doBodyDemo>
<a href="viewReferer.jsp">View</a> the referer as a Session attribute.
doBodyDemo.tag
[java]
<jsp:doBody var="referer"
scope="session"/>//转换out.tostring保存在session变量referer中
viewReferer.jsp
[java]
The Referer header of the previous page is
${sessionScope.referer}//这是session中有referer变量,直接可以展示
例子6 调用tag file并传入参数
powerTagTest.jsp
[java]
//自定义标签,通过传入参数调用jspFragment.dotag
<%@ taglib prefix="easy" tagdir="/WEB-INF/tags" %>
2^3=<easy:power number="2" power="3"/>
power.tag
[java]
<%-- Shows how to use attributes in a tag file --%>
<%@ attribute name="number" required="true" description="base" %>
<%@ attribute name="power" required="true" description="exponent" %>
<%=Math.pow(Double.parseDouble(number),
Double.parseDouble(power))%>//通过传入的参数计算
编译后的代码
powerTagTest_jsp.java
[java]
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException {
final javax.servlet.jsp.PageContext pageContext;
javax.servlet.http.HttpSession session = null;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this;
javax.servlet.jsp.JspWriter _jspx_out = null;
javax.servlet.jsp.PageContext _jspx_page_context = null;
try {
response.setContentType("text/html");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
相关新闻>>
- 发表评论
-
- 最新评论 更多>>