2008-06-05
1.2版标签支持el语句
1.2版的标签不支持el语句,需要在标签体中处理el语句。
2.0版的标签继承SimpleTagSupport类,已经支持el语句,不需要在标签体里面单独处理。
详细参考:http://liudaoru.javaeye.com/blog/194491
ExpressionEvaluatorManager.evaluate("selectProvince", subjectionCode, String.class, this, pageContext);
五个参数:
selectProvince:标签名称
subjectionCode:要支持el语句的属性名称
String.class:属性class
this: 本标签
pageContext:本标签继承TagSupport的属性
2.0版的标签继承SimpleTagSupport类,已经支持el语句,不需要在标签体里面单独处理。
详细参考:http://liudaoru.javaeye.com/blog/194491
ExpressionEvaluatorManager.evaluate("selectProvince", subjectionCode, String.class, this, pageContext);
五个参数:
selectProvince:标签名称
subjectionCode:要支持el语句的属性名称
String.class:属性class
this: 本标签
pageContext:本标签继承TagSupport的属性
package com.chenkun.web.tag;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.commons.lang.StringUtils;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
public class SelectProvinceTag extends TagSupport{
private String subjectionCode;
public int doEndTag() throws JspException {
return TagSupport.EVAL_BODY_INCLUDE;
}
public int doStartTag() throws JspException {
Connection con = JdbcUtil.getConnection();
Statement stm = null;
ResultSet rs = null;
StringBuilder sb = new StringBuilder("");
sb.append("<select name=\"subjectionCode\">" + "\n");
if(StringUtils.isBlank(subjectionCode) || subjectionCode.equals("0")){
sb.append("<option value=\"0\" selected>--省份--</option>" + "\n");
}else{
sb.append("<option value=\"0\">--省份--</option>" + "\n");
}
try {
stm = con.createStatement();
rs = stm.executeQuery("select SSDM, ABBR from DIC_SSMC where IS_EXTENDED = 0");
while(rs.next()){
String value = rs.getString("SSDM");
String name = rs.getString("ABBR");
if(!value.equals(subjectionCode)){
sb.append("<option value=\"" + value + "\"> " + name + "</option>" + "\n");
}else{
sb.append("<option value=\"" + value + "\" selected> " + name + "</option>" + "\n");
}
}
sb.append("</select>");
} catch (SQLException e) {
e.printStackTrace();
}finally{
JdbcUtil.realease(rs, stm, con);
}
try {
pageContext.getOut().print(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}
return EVAL_PAGE;
}
public String getSubjectionCode() {
return subjectionCode;
}
public void setSubjectionCode(String subjectionCode) {
try {
this.subjectionCode = (String) ExpressionEvaluatorManager.evaluate("selectProvince", subjectionCode, String.class, this, pageContext);
} catch (JspException e) {
e.printStackTrace();
}
}
}







评论排行榜