jakarta-tomcat-5.0.4中包含了非常好的例子,特别是支持JSP 2.0。
ftp://210.36.70.51下的JSPStduio开发工具中带有 jakarta-tomcat-5.0.4,可下载。
例如:
HelloWorldSimpleTag.java
/**
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*/package jsp2.examples.simpletag;import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;/**
* SimpleTag handler that prints "Hello, world!"
*/
public class HelloWorldSimpleTag extends SimpleTagSupport {
public void doTag() throws JspException, IOException {
getJspContext().getOut().write( "Hello, world!" );
}
}
jsp2-example-taglib.tld:
。。
<tag>
<description>Outputs Hello, World</description>
<name>helloWorld</name>
<tag-class>jsp2.examples.simpletag.HelloWorldSimpleTag</tag-class>
<body-content>empty</body-content>
</tag>
。。hello.jsp:
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
<head>
<title>JSP 2.0 Examples - Hello World Using a Tag File</title>
</head>
<body>
<h1>JSP 2.0 Examples - Hello World Using a Tag File</h1>
<hr>
<p>This JSP page invokes a custom tag that simply echos "Hello, World!"
The custom tag is generated from a tag file in the /WEB-INF/tags
directory.</p>
<p>Notice that we did not need to write a TLD for this tag. We just
created /WEB-INF/tags/helloWorld.tag, imported it using the taglib
directive, and used it!</p>
<br>
<b><u>Result:</u></b>
<tags:helloWorld/>
</body>
</html>
ftp://210.36.70.51下的JSPStduio开发工具中带有 jakarta-tomcat-5.0.4,可下载。
例如:
HelloWorldSimpleTag.java
/**
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*/package jsp2.examples.simpletag;import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;/**
* SimpleTag handler that prints "Hello, world!"
*/
public class HelloWorldSimpleTag extends SimpleTagSupport {
public void doTag() throws JspException, IOException {
getJspContext().getOut().write( "Hello, world!" );
}
}
jsp2-example-taglib.tld:
。。
<tag>
<description>Outputs Hello, World</description>
<name>helloWorld</name>
<tag-class>jsp2.examples.simpletag.HelloWorldSimpleTag</tag-class>
<body-content>empty</body-content>
</tag>
。。hello.jsp:
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
<head>
<title>JSP 2.0 Examples - Hello World Using a Tag File</title>
</head>
<body>
<h1>JSP 2.0 Examples - Hello World Using a Tag File</h1>
<hr>
<p>This JSP page invokes a custom tag that simply echos "Hello, World!"
The custom tag is generated from a tag file in the /WEB-INF/tags
directory.</p>
<p>Notice that we did not need to write a TLD for this tag. We just
created /WEB-INF/tags/helloWorld.tag, imported it using the taglib
directive, and used it!</p>
<br>
<b><u>Result:</u></b>
<tags:helloWorld/>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货