tag 标签开发 note

action**************

package com.uu.tags;



import java.io.IOException;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;


public class ContextPathTag extends SimpleTagSupport {


@Override
public void doTag() throws JspException, IOException {
super.doTag();
PageContext ctx = (PageContext)getJspContext();
HttpServletRequest request=(HttpServletRequest)ctx.getRequest();
String contextPath =request.getContextPath();
JspWriter out = ctx.getOut();
out.print(contextPath);
}

}

tags.tld*********************

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
                        "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">


<taglib>
 <tlib-version>1.0</tlib-version>
 <jsp-version>1.0</jsp-version>
 <short-name>pagination</short-name>
 <uri>http://congratulation.iego.cn</uri>
 <description></description>
 <tag>
  <name>contextPath</name>
  <tag-class>com.uu.tags.ContextPathTag</tag-class>
  <body-content>empty</body-content>
  <description>to get the contextPath of the application</description>
 </tag>
</taglib>


jsp**********

<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://ajaxanywhere.sourceforge.net/" prefix="aa"%>
<%@taglib uri="/WEB-INF/tags.tld" prefix="uu"%>
<%@ taglib uri="/struts-tags" prefix="s"%>




你可能感兴趣的:(标签,tag)