jsp自定义标签下拉框(4)
来源:未知 责任编辑:责任编辑 发表时间:2014-03-23 22:28 点击:次
public int doEndTag() throws JspException {
// TODO Auto-generated method stub
JspWriter out=this.pageContext.getOut();
String sql="select "+label+","+value+" from "+tableName+" "+where+"";//定义sql语句
Connection conn=BaseDao.getConnection();
try {
PreparedStatement ps=conn.prepareStatement(sql);
ResultSet res=ps.executeQuery();
out.print("<select id=\""+selectId+"\" name=\""+selectName+"\">");
out.print("<option value=\"\">请选择</option>");
while(res.next()){
Object values=res.getObject(value);
Object labels=res.getObject(label);
out.print("<option value=\""+values+"\">"+labels+"</option>");
}
out.print("</select>");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
}
return super.doEndTag();
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getWhere() {
return where;
}
public void setWhere(String where) {
this.where = where;
相关新闻>>
- 发表评论
-
- 最新评论 更多>>