• taglib block


    新建文件

    package com.augmentum.oes.taglib;
    
    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.JspWriter;
    import javax.servlet.jsp.tagext.TagSupport;
    
    import org.springframework.context.ApplicationContext;
    
    import com.augmentum.oes.common.BlockAbstract;
    import com.augmentum.oes.util.SpringUtil;
    
    public class BlockTaglib extends TagSupport{
    
        private static final long serialVersionUID = -1485358775043610324L;
        private String name;
    
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
    
        @Override
        public int doStartTag() throws JspException {
            return SKIP_BODY;
        }
        @Override
        public int doEndTag() throws JspException {
            ApplicationContext ctx = SpringUtil.getApplicationContext();
            BlockAbstract block = (BlockAbstract) ctx.getBean(name);
    
            String content = block.dispalyBlock(pageContext);
    
            JspWriter out = pageContext.getOut();
    
            try {
                out.println(content);
    
            } catch (Exception e) {
                e.printStackTrace();
            }
            return EVAL_PAGE;  
        }
    
        @Override
        public void release() {
            super.release();
        }
    }
    

      新建tld文件

    <?xml version="1.0" encoding="UTF-8"?>  
    <taglib xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1"> 
      
        <description>oes 1.0 </description> 
        <display-name>mxz</display-name>  
        <tlib-version>1.0</tlib-version>  
        <short-name>block</short-name> 
        <uri>http://www.oes.com/tag/mxz</uri> 
        <tag>             
            <name>display</name>
            <tag-class>com.augmentum.oes.taglib.tagl</tag-class>
            <body-content>empty</body-content> 
            <attribute>
                <name>name</name>
                <required>true</required>
                <rtexprvalue>true</rtexprvalue>
            </attribute>
        </tag> 
        
     </taglib>  

    在页面中引入

    <%@taglib prefix="block" uri="http://www.oes.com/tag/mxz" %>

    对于block页面分块

    公共类

    package com.augmentum.oes.common;
    
    import java.io.IOException;
    import java.io.StringWriter;
    import java.io.Writer;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.jsp.PageContext;
    
    public abstract class BlockAbstract {
    
        public String template;
    
        public String getTemplate() {
            return template;
        }
    
        public void setTemplate(String template) {
            this.template = template;
        }
    
        public String dispalyBlock(PageContext pagecontext) {
            execute(pagecontext);
            HttpServletRequest request = (HttpServletRequest) pagecontext.getRequest();
            Writer body = new StringWriter();
            try {
                if (template != null && !template.trim().equals("")) {
                    pagecontext.pushBody(body);
                    pagecontext.include(template);
                    pagecontext.popBody();
                    return body.toString();
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    body.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return "";
        }
    
        abstract protected void execute(PageContext pagecontext) ;
    
    
    }
    BlockAbstract

    要实现的传数据类

    package com.augmentum.oes.block;
    
    import javax.servlet.jsp.PageContext;
    
    import com.augmentum.oes.common.BlockAbstract;
    
    public class QuestionInfoBlock extends BlockAbstract{
    
        @Override
        protected void execute(PageContext pagecontext) {
            //get data;
        }
    
    
    }
    QuestionInfoBlock

    通过spring获得

        <bean id="questionInfoBlock" class="com.augmentum.oes.block.QuestionInfoBlock">
            <property name="template" value="/WEB-INF/jsp/questions/question_list.jsp"></property>
        //这里可以注入其他需要的service
        </bean>
    applicationcontext.xml

    页面中调用

  • 相关阅读:
    win7下DS、KS、ASIO、WASAPI输出比较
    什么叫时钟漂移(Wander)?时钟漂移与时钟抖动(jitter)的区别
    常见编译/链接错误及其解决办法
    理解 Visual C++ 应用程序的依赖项(msdn)
    初识windows语音采集和回放
    依赖关系、概况关系、关联关系等概念
    VS2010工程转VS2005工程的方法
    speech codec (G.711, G.723, G.726, G.729, iLBC)
    【转】深入剖析iLBC的丢包补偿技术(PLC)
    CSS优先级问题
  • 原文地址:https://www.cnblogs.com/mxz1994/p/7270250.html
Copyright © 2020-2023  润新知