你知道么?????!!!!!
错误一:
自定义带标签体的标签,发生错误:
标签处理类:
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
{
. .. . ..
}
求具体的操作步骤 !