JSP自定义标签(三) 多选控件

来源:互联网 发布:自学电脑编程要下什么 编辑:程序博客网 时间:2024/05/02 04:56

一、效果图


二、标签定义代码


package com.swcares.util.tags;import java.io.IOException;import javax.servlet.http.HttpServletRequest;import javax.servlet.jsp.JspException;import javax.servlet.jsp.JspWriter;import javax.servlet.jsp.tagext.TagSupport;/** *  * @author HHB *  *  多选自定义标签标签处理类 * */public class MultiSelectorTag extends TagSupport {    private static final long serialVersionUID = 1164199147616542853L;    //标签name属性    private String name;        //所需图片的路径    private String imgPath;        //所需javascript文件的路径    private String scriptPaht;        //所需css文件的路径    private String cssPath;        //项目的根路径    private String rootPath;        //标签的value属性    private String value;        private HttpServletRequest request=null;        public String getValue() {        return value;    }    public void setValue(String value) {        this.value = value;    }    public String getImgPath() {        return imgPath;    }    public void setImgPath(String imgPath) {        this.imgPath = imgPath;    }    public String getScriptPaht() {        return scriptPaht;    }        public void setScriptPaht(String scriptPaht) {        this.scriptPaht = scriptPaht;    }    public String getCssPath() {        return cssPath;    }        public void setCssPath(String cssPath) {        this.cssPath = cssPath;    }        public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    /**     * 初始化变量     */    private void initAbttributes()    {        request=(HttpServletRequest)this.pageContext.getRequest();        rootPath=request.getContextPath();        this.imgPath="/images/";        this.scriptPaht="/js/tags/";        this.cssPath="/css/";            }    @Override    public int doStartTag() throws JspException {        initAbttributes();        JspWriter out=pageContext.getOut();        try {            String tName=name;            //引入javascript文件            out.println("<script type='text/javascript' charset='UTF-8' src='"+rootPath+scriptPaht+"multiSelector.js'></script>");                        StringBuilder tag=new StringBuilder("<div style='display:inline;float:left;' ");            tag.append("id='multiParent_").append(id).append("'>");            tag.append("</div>");            tag.append("<script type='text/javascript'>")                .append("showMulti('multiParent_").append(id)                .append("','").append(name)                .append("','").append(id)                .append("',\"").append(value)                .append("\")")                .append("</script>");            out.println(tag.toString());        } catch (IOException e) {            e.printStackTrace();        }        return SKIP_BODY;    }        }

待续。。。。。。。。。。。。。。。