什么情况。。
自定义标签 代码处理文件:
Print.java代码 如下
package com.taglib;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
public class Print extends TagSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
PageContext pageContext;
public void Print(){
System.out.println("hhh");
}
public int doStartTag() throws JspException{
System.out.println("doStartTag");
return this.SKIP_BODY;
}
public int doEndTag() throws JspException{
System.out.println("deEndTag");
JspWriter out = pageContext.getOut();
try {
out.println("<html><body>");
out.println("<b>这是我第一个自定义标签</b>");
out.println("</body></html>");
} catch (IOException e) {
e.printStackTrace();
}
return this.EVAL_PAGE;
}
public void setPageContext(PageContext pageContext){
this.pageContext=pageContext;
}
public PageContext getPageContext(){
return this.pageContext;
}
}
标签库描述文件:
taglib.tld代码若下:
<?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.1</jsp-version>
<short-name>nn</short-name>
<uri>stu</uri>
<tag>
<name>name</name>
<tag-class>com.taglib.Print</tag-class>
</tag>
</taglib>
taglib.jsp代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="stu" prefix="ll" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'taglib.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<ll:name />
</body>
</html>
------解决思路----------------------
1、taglib标签文件要放在WEB-INF/tags目录下面
2、引入标签中的uri改为<%@?taglib?uri="/WEB-INF/tags/taglib.tld"??prefix="ll"?%>
前面说了把taglib.tld放到WEB-INF下的tags目录中,如果没有新建一个tags文件夹
------解决思路----------------------
你按照我拷过去的代码照着把你的改一遍就行了呀!