你知道么?????!!!!!

zs312979674 2013-03-30 06:25:40
错误一:
自定义带标签体的标签,发生错误:

标签处理类:
package com.tag;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class IteratorTag extends SimpleTagSupport {

private String collection;
private String item;



public String getCollection() {
return collection;
}

public void setCollection(String collection) {
this.collection = collection;
}

public String getItem() {
return item;
}



public void setItem(String item) {
this.item = item;
}



@Override
public void doTag() throws JspException, IOException {

Collection itemList = (Collection)this.getJspContext().getAttribute("collection");

for(Object s : itemList){
this.getJspContext().setAttribute("item", s);
this.getJspBody().invoke(null);
}


}
}

MyTag.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>mytag</short-name>
<uri>http://www.tag.com</uri>

<tag>
<name>tagInterator</name>
<tag-class>com.tag.IteratorTag</tag-class>
<body-content>scriptless</body-content>

<attribute>
<name>collection</name>
<required>true</required>
</attribute>

<attribute>
<name>item</name>
<required>true</required>
</attribute>
</tag>
</taglib>

Jsp页面使用标签:
<body>
<%
List<String> a = new ArrayList<String>();
a.add("admin");
a.add("tom");
a.add("amy");
%>


<t:mytag/> <br/>

<t:tagAndAtt password="123" username="admin"/> <br/>

<t:tagInterator item="item" collection="a">

item : ${item } <br/>
</t:tagInterator>
</body>

报错信息如下:
java.lang.NullPointerException
at com.tag.IteratorTag.doTag(IteratorTag.java:44)


Collection itemList = (Collection)this.getJspContext().getAttribute(collection);

这行获取不到值


错误二: 动态属性标签问题
我在一个tld标签描述文件的<tag>标签里面没有<dynamic-attributes>子标签
是不是自定义标签有版本有关!

问题三:
怎么把servlet在web.xml里的配置信息,直接配置到servlet类的上面呢:
例如:@WebServlet(name=”loginServlet”,
urlPatterns={“/loginServlet”})
public class LoginServlet extends HttpServlet
{
. .. . ..
}
求具体的操作步骤 !

...全文
54 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧