<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><%@taglib prefix="T"URI="/web-inf/tag.tld"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML><Head></Head><Body> <%Request.setattribute ("User", "User"); %> <t:ifTest= "${user==null}">Not yet logged in</t:if> <t:ifTest= "${user!=null}">Welcome: ${user}</t:if></Body></HTML>
<?XML version= "1.0" encoding= "UTF-8"?><!--file name/web-inf/referer.tld -<taglibxmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"version= "2.0"> <tlib-version>1.0</tlib-version> <Short-name>Anyname</Short-name><!--This value can be set arbitrarily - <URI>AnyUri</URI><!--This URI can be set arbitrarily, but not the same as other. tld Files - <Tag> <name>If</name> <Tag-class>De.bvb.web.tag.IfTag</Tag-class> <body-content>Scriptless</body-content> <attribute> <name>Test</name> <Required>True</Required> <Rtexprvalue>True</Rtexprvalue> </attribute> </Tag></taglib>
PackageDe.bvb.web.tag;Importjava.io.IOException;Importjavax.servlet.jsp.JspException;ImportJavax.servlet.jsp.tagext.SimpleTagSupport; Public classIftagextendsSimpletagsupport {Private Booleantest; Public voidSettest (Booleantest) { This. Test =test; } @Override Public voidDotag ()throwsjspexception, IOException {if(test) { This. Getjspbody (). Invoke (NULL);//Execute label Body } }}
Javaweb using JSP to develop if tags