To write a class that inherits simpleTagsupport
import javax.servlet.jsp.tagext.SimpleTagSupport; public class loginFilter extends SimpleTagSupport { @Override public void doTag() throws JspException, IOException { PageContext pageContext = (PageContext) this.getJspContext(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); HttpServletResponse response= (HttpServletResponse) pageContext.getResponse(); User user= (User) request.getSession().getAttribute("user"); if(user==null){ response.sendRedirect(request.getContextPath()+"/client/error/privilege.jsp"); } } }
In writing a custom label .tld file in the WEB-INF under
<? xml Version = "1.0" encoding = "UTF-8"?> <taglib xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "HTTP: //www.w3 .org / 2001 / XMLSchema-instance " xsi: schemaLocation =" http://java.sun.com/xml/ns/javaee HTTP: // java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd " version =" 2.1 "> <-! description from one version of the description tag is defined -> <description> loginTag 1.0 Core Library </ description> <-! guide package display name is a display -> <the display-name> loginTag Core </ the display-name> <-! version number -> <tlib-version> 1.0 </ tlib-version> <!-- 短名 --> <short-name>loginTag</short-name> <- URI:! leader packet -> <URI> HTTP: // Login-Tags </ URI> <- define a tag ->! <Tag> <- tag name ->! <name> loginTag </ name> <-! tag handler class -> <tag- class > com.bookstore.utils.loginFilter </ tag- class > <-! tag set is empty -> <body- Content> empty </ Content-body> </ Tag> </ taglib>
To quote his label directly on that page use
<%@ taglib prefix="ln" uri="http://login-tags"%>
<ln:loginTag/>