刚开始学习写自定义标签,按照网上的说法照做,问题最后写道jsp页面导入自定义标签时说uri找不到。大侠请赐教!
以下是我的代码:HelloTag.java:package fox.tags.hello;import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;public class HelloTag extends TagSupport{
@Override
public int doStartTag() throws JspException {
JspWriter out=this.pageContext.getOut();
try{
out.write("hello world !");//页面中显示的内容
}catch(IOException e){
e.printStackTrace();
}
return this.SKIP_BODY;//不包含主体内容
}
}
hello.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.2</jsp-version>
<short-name>shortname</short-name>
<tag>
<name>hello</name>
<tag-class>fox.tags.hello.HelloTag</tag-class>
</tag>
</taglib>
web.xml<?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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>/hello-tags</taglib-uri>
<taglib-location>/WEB-INFO/tld/hello.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
index.jsp<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!-- 下面的uri="/hello-tags"有问题,说是找不到-->
<%@ taglib prefix="f" uri="/hello-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
This is my JSP page. <br>
</body>
</html>
以下是我的代码:HelloTag.java:package fox.tags.hello;import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;public class HelloTag extends TagSupport{
@Override
public int doStartTag() throws JspException {
JspWriter out=this.pageContext.getOut();
try{
out.write("hello world !");//页面中显示的内容
}catch(IOException e){
e.printStackTrace();
}
return this.SKIP_BODY;//不包含主体内容
}
}
hello.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.2</jsp-version>
<short-name>shortname</short-name>
<tag>
<name>hello</name>
<tag-class>fox.tags.hello.HelloTag</tag-class>
</tag>
</taglib>
web.xml<?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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>/hello-tags</taglib-uri>
<taglib-location>/WEB-INFO/tld/hello.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
index.jsp<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!-- 下面的uri="/hello-tags"有问题,说是找不到-->
<%@ taglib prefix="f" uri="/hello-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
This is my JSP page. <br>
</body>
</html>
解决方案 »
- 关于一个登录效果的问题
- 在web开发中如何将时间的时分秒存在sql数据库中
- JPA是什么?
- 救急:spring中普通类调用service类怎么调用
- 创建sessionFactory失败,java.lang.UnsupportedClassVersionError:/hibernate/cfg/SecondPass (Unsupported major.minor version 49.0)
- JXL 写excel文件时"00111"在excel只能看到111
- JSP在线修改的问题
- 关于登陆问题 jsp
- jsp中的js代码放在head中不显示
- jsp在两个不同地域的数据库间传递数据的问题
- 在哪儿可以找到javaee.jar的src包,有的虾们可以给我传一个么?---在线等([email protected])
- 网络编辑程序员需要具备哪些技能?
?