我用eclipse写的
要导入包<%@taglib prefix="movie" uri="/WEB-INF/movie.tld"%>
而在包里创建的代码是package com.tman.forum.tag;
import
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class SelectTag extends SimpleTagSupport {
private String name;
private int begin;
private int end;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getBegin() {
return begin;
}
public void setBegin(int begin) {
this.begin = begin;
}
public int getEnd() {
return end;
}
public void setEnd(int end) {
this.end = end;
}
public void doTag() {
JspWriter out = this.getJspContext().getOut();
StringBuffer sb = new StringBuffer();
try {
sb.append("<select name="+name+">");
for (int i = begin; i < end; i++) {
sb.append("<option value=");
sb.append(i);
sb.append(">");
sb.append(i);
sb.append("</option>");
}
sb.append("</select>");
out.write(sb.toString());
} catch (IOException e) {
}
}
}
界面:
<tr>
<td>
出生年月;
</td>
<td>
<movie:select name="year" begin="1960" end="2007" />
年
<movie:select name="month" begin="1" end="12" />
月
<movie:select name="day" begin="1" end="31" />
日
</td>
</tr>