// add to web.xml
// create new java2s.tld file in WEB-INF directory
//File:java2s.tld
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
// create HelloWorldTag.java under WEB-INF\classes\com\java2s\
// include jsp-api.jar into your CLASSPATH
// and compile it
package com.java2s;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.*;
public class HelloWorldTag extends TagSupport
{
public int doStartTag() throws JspException
{
try
{
JspWriter out = pageContext.getOut();
HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
out.write("Hello world from www.java2s.com!");
}
catch(Exception e)
{
throw new JspException(e.getMessage());
}
return EVAL_PAGE;
}
}
// create JSP file: HelloWorldTag.jsp
<%@ taglib uri='WEB-INF/java2s.tld' prefix='hw' %>
// start tomcat and load the JSP file in the browser


No comments:
Post a Comment