我的编写的代码结构是这样的
1.在WEB-INF/classes/ 下编写类HelloTag.java代码如下//=====================================================
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;public class HelloTag implements Tag {
private PageContext context;
private Tag parent;
public void setPageContext(PageContext ctx) {
this.context=ctx; } public void setParent(Tag tag) {
this.parent=tag; } public Tag getParent() {
return this.parent;
} public int doStartTag() throws JspException {
System.out.println("doStartTag");
return Tag.SKIP_BODY;
} public int doEndTag() throws JspException {
System.out.println("doStartTag");
try {
this.context.getOut().write("Hello World");
} catch (Exception e) {
e.printStackTrace();
}
return Tag.EVAL_PAGE;
} public void release() {
// TODO Auto-generated method stub
}}
//=================================================
编译没报错
2.在/WEB-INF/下编写helloTag.tld文件//=================================================
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0"> <description>xmddl 1.1 hello library</description>
<display-name>xmddl hello</display-name>
<tlib-version>1.1</tlib-version>
<short-name>hello</short-name>
<uri>/hello</uri>
<tag>
<description>Hello World</description>
<name>hello</name>
<tag-class>HelloTag</tag-class>
<body-content>empty</body-content>
</tag></taglib>//================================================
3.在web.xml编写下面代码
//============================================
<?xml version="1.0" encoding="ISO-8859-1"?><web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4"> <display-name>Welcome to Tomcat</display-name>
<description>
JSPÓ¦Óÿª·¢Ïê½â
</description>
<taglib>
<taglib-uri>/hello</taglib-uri>
<taglib-location>/WEB-INF/helloTag.tld</taglib-location>
</taglib>
</web-app>
//===============================================================
4。在WEB-INF同级目录下,编写hello.jsp
//==============================================
<%@ page language="java" pageEncoding="UTF-8" import="java.util.*"%>
<%@ taglib uri="/hello" prefix="lu"%>
<html>
<head>
<title>MyJsp.jsp</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">
</head>
<body>
<h1>This is a test tag page for person.</h1> <br>
<lu:hello/>
</body>
</html>
//==============================================--------------------------------------------------------
代码编写完了,测试:http://localhost:8080/ch14_1/hello.jsp报错为:HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 15 in the jsp file: /hello.jsp
HelloTag cannot be resolved to a type
12:
13: <body>
14: <h1>This is a test tag page for person.</h1> <br>
15: <lu:hello/>
16: </body>
17: </html>
An error occurred at line: 15 in the jsp file: /hello.jsp
HelloTag cannot be resolved to a type
12:
13: <body>
14: <h1>This is a test tag page for person.</h1> <br>
15: <lu:hello/>
16: </body>
17: </html>
An error occurred at line: 15 in the jsp file: /hello.jsp
HelloTag cannot be resolved to a type
12:
13: <body>
14: <h1>This is a test tag page for person.</h1> <br>
15: <lu:hello/>
16: </body>
17: </html>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.问:我是错了,好几天了,都没调出来,快吐血了,
1.在WEB-INF/classes/ 下编写类HelloTag.java代码如下//=====================================================
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;public class HelloTag implements Tag {
private PageContext context;
private Tag parent;
public void setPageContext(PageContext ctx) {
this.context=ctx; } public void setParent(Tag tag) {
this.parent=tag; } public Tag getParent() {
return this.parent;
} public int doStartTag() throws JspException {
System.out.println("doStartTag");
return Tag.SKIP_BODY;
} public int doEndTag() throws JspException {
System.out.println("doStartTag");
try {
this.context.getOut().write("Hello World");
} catch (Exception e) {
e.printStackTrace();
}
return Tag.EVAL_PAGE;
} public void release() {
// TODO Auto-generated method stub
}}
//=================================================
编译没报错
2.在/WEB-INF/下编写helloTag.tld文件//=================================================
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0"> <description>xmddl 1.1 hello library</description>
<display-name>xmddl hello</display-name>
<tlib-version>1.1</tlib-version>
<short-name>hello</short-name>
<uri>/hello</uri>
<tag>
<description>Hello World</description>
<name>hello</name>
<tag-class>HelloTag</tag-class>
<body-content>empty</body-content>
</tag></taglib>//================================================
3.在web.xml编写下面代码
//============================================
<?xml version="1.0" encoding="ISO-8859-1"?><web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4"> <display-name>Welcome to Tomcat</display-name>
<description>
JSPÓ¦Óÿª·¢Ïê½â
</description>
<taglib>
<taglib-uri>/hello</taglib-uri>
<taglib-location>/WEB-INF/helloTag.tld</taglib-location>
</taglib>
</web-app>
//===============================================================
4。在WEB-INF同级目录下,编写hello.jsp
//==============================================
<%@ page language="java" pageEncoding="UTF-8" import="java.util.*"%>
<%@ taglib uri="/hello" prefix="lu"%>
<html>
<head>
<title>MyJsp.jsp</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">
</head>
<body>
<h1>This is a test tag page for person.</h1> <br>
<lu:hello/>
</body>
</html>
//==============================================--------------------------------------------------------
代码编写完了,测试:http://localhost:8080/ch14_1/hello.jsp报错为:HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 15 in the jsp file: /hello.jsp
HelloTag cannot be resolved to a type
12:
13: <body>
14: <h1>This is a test tag page for person.</h1> <br>
15: <lu:hello/>
16: </body>
17: </html>
An error occurred at line: 15 in the jsp file: /hello.jsp
HelloTag cannot be resolved to a type
12:
13: <body>
14: <h1>This is a test tag page for person.</h1> <br>
15: <lu:hello/>
16: </body>
17: </html>
An error occurred at line: 15 in the jsp file: /hello.jsp
HelloTag cannot be resolved to a type
12:
13: <body>
14: <h1>This is a test tag page for person.</h1> <br>
15: <lu:hello/>
16: </body>
17: </html>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.问:我是错了,好几天了,都没调出来,快吐血了,
不是代码写在里面,源代码写在src目录,是编译后的class放在classes目录
对 如果是你写的tld文件 应该建个classes文件夹 默认是没有的
import javax.servlet.jsp.tagext.*;
import java.util.Hashtable;
import java.io.Writer;
import java.io.IOException;
import java.util.Date; /**
*演示怎么实现Tag接口的方式来开发标签程序
*/
public class HelloTag_Interface implements javax.servlet.jsp.tagext.Tag
{
private PageContext pageContext;
private Tag parent;
public HelloTag_Interface()
{
super();
}
/**
*设置标签的页面的上下文
*/
public void setPageContext(final javax.servlet.jsp.PageContext pageContext)
{
this.pageContext=pageContext;
}
/**
*设置上一级标签
*/
public void setParent(final javax.servlet.jsp.tagext.Tag parent)
{
this.parent=parent;
}
/**
*开始标签时的操作
*/
public int doStartTag() throws javax.servlet.jsp.JspTagException
{
return SKIP_BODY; //返回SKIP_BODY,表示不计算标签体
}
/**
*结束标签时的操作
*/
public int doEndTag() throws javax.servlet.jsp.JspTagException
{
try
{
pageContext.getOut().write("Hello World!你好,世界!");
}
catch(java.io.IOException e)
{
throw new JspTagException("IO Error: " + e.getMessage());
}
return EVAL_PAGE;
}
/**
*release用于释放标签程序占用的资源,比如使用了数据库,那么应该关闭这个连接。
*/
public void release() {}
public javax.servlet.jsp.tagext.Tag getParent()
{
return parent;
}
}
import javax.servlet.jsp.tagext.*;
import java.util.Hashtable;
import java.io.Writer;
import java.io.IOException;
import java.util.Date; /**
*演示怎么实现Tag接口的方式来开发标签程序
*/
public class HelloTag_Interface implements javax.servlet.jsp.tagext.Tag
{
private PageContext pageContext;
private Tag parent;
public HelloTag_Interface()
{
super();
}
/**
*设置标签的页面的上下文
*/
public void setPageContext(final javax.servlet.jsp.PageContext pageContext)
{
this.pageContext=pageContext;
}
/**
*设置上一级标签
*/
public void setParent(final javax.servlet.jsp.tagext.Tag parent)
{
this.parent=parent;
}
/**
*开始标签时的操作
*/
public int doStartTag() throws javax.servlet.jsp.JspTagException
{
return SKIP_BODY; //返回SKIP_BODY,表示不计算标签体
}
/**
*结束标签时的操作
*/
public int doEndTag() throws javax.servlet.jsp.JspTagException
{
try
{
pageContext.getOut().write("Hello World!你好,世界!");
}
catch(java.io.IOException e)
{
throw new JspTagException("IO Error: " + e.getMessage());
}
return EVAL_PAGE;
}
/**
*release用于释放标签程序占用的资源,比如使用了数据库,那么应该关闭这个连接。
*/
public void release() {}
public javax.servlet.jsp.tagext.Tag getParent()
{
return parent;
}
}----------------------------------------------//
把 package com.jspdev.ch11;去掉,然后在helloTag.tld里修改相应的路径,发现也会报同样的错误,好像一定要放在包里才可以,
我们在找的人:
一、技术类:
要求:
1、计算机或相关专业本科以上学历,二年以上的JAVA程序网站应用开发经 验;
2、有项目管理领域架构设计及开发经验;
3、精通Java语言和面向对象设计方法,熟练应用Struts、 Hibernate、 JSP、Servlet、 Ajax、 J2EE应用开发和HTML、CSS、XML等;
4、有很好的理解、分析能力,技术架构的洞察力及把握能力强;
5、精通关系型数据库原理和数据库设计;
6、具备较强的协调沟通能力和文档编写能力。
7、解决开发中的技术难点;
8、对开发团队进行技术培训。
9、有大型Web2.0网站相关工作经验(提供案例)优先考虑;计划找1到2位合作伙伴。
二、营销类:希望你在互联网内口碑良好,2年以上从业经验,资源丰富;计划找1到2位合作伙伴。
三、管理类:1年以上互联网从业经验,业内口碑良好;计划找1到2位合作伙伴。
以上合作伙伴均为项目核心合作伙伴,可获得项目一定比例的原始股份(不低于5%)
项目所在地:厦门,外地朋友如有兴趣,需来北京发展。
请先仔细阅读以上文字,如有意,请联系:QQ:6172867, 或发邮件至:[email protected]注:加入的成员请在加入的时候注明自己的特长是什么,联系方式,最好能提供个人作品。本团队暂时不接纳入门级开发人员,请谅 解!