RSS订阅优然探索
你的位置:首页 » JAVA » 正文

jstl 自定义标签

选择字号: 超大 标准 发布时间:2013-4-3 17:30:24 | 作者:admin | 0个评论 | 人浏览

 package net.lisoft.basic;

 
import java.io.IOException;
import java.util.ResourceBundle;
 
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
 
public class HelloTag extends TagSupport {
 
private String name;
 
@Override
public int doEndTag() throws JspException {
 
try {
 
this.pageContext.getOut().println("Hello, " + name);
} catch (IOException e) {
throw new JspException(e);
}
return EVAL_PAGE;
}
public String getName() {
return name;
}
}
 
 
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
 
<%@ taglib uri="/tld/helloworld" prefix="mytag"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyJSP</title>
</head>
<body>
<h1>
自定义标签:
</h1>
<br>
<mytag:helloworld></mytag:helloworld>
</body>
</html>
 
 
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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-app_2_5.xsd">
<servlet>
<servlet-name>UserLogin</servlet-name>
<servlet-class>
net.lisoft.service.servlet.CUserLoginServlet
</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>welcom to Firservlet</param-value>
</init-param>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>CIdentityServlet</servlet-name>
<servlet-class>
net.lisoft.service.servlet.CInentityServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserLogin</servlet-name>
<url-pattern>/servlet/UserLogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CIdentityServlet</servlet-name>
<url-pattern>/servlet/CIdentityServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
 
<jsp-config>
<taglib>
<taglib-uri>/tld/helloworld</taglib-uri>
<taglib-location>
/WEB-INF/tlds/helloworld.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>/mytaglib</taglib-uri>
<taglib-location>/WEB-INF/taglib.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
 
<?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.2</jsp-version><!-- 这个标签库要求的JSP规范版本 -->
 
<short-name>mytag</short-name><!-- JSP页面编写工具可以用来创建助记名的可选名字 -->
 
<tag>
 
<name>helloworld</name><!-- 唯一标签名 -->
 
<tag-class>net.lisoft.basic.HelloWorldTag</tag-class><!-- 标签HelloWorldTag类的完全限定名 -->
 
<body-content>empty</body-content><!-- 正文内容类型 -->
 
</tag>
 
</taglib>
 

标签:

猜你喜欢

发表评论

必填

选填

选填

必填,不填不让过哦,嘻嘻。

记住我,下次回复时不用重新输入个人信息

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。