Jsp/Java代码分离.实现页面真正的代码分离 实现框架代码,jxui:page标签

package  JXDO.WebUI;


import  javax.servlet.jsp.JspException;
import  javax.servlet.jsp.tagext.TagSupport;


public   class  PageTag  extends  TagSupport
{
    
public PageTag(){super();}
    
    
/*后端JAVA代码的类名*/
    
private String codeBehind;
    
public String getCodeBehind(){return this.codeBehind;}
    
public void setCodeBehind(String codeBehind){this.codeBehind=codeBehind;}
    

    
public int doStartTag() throws JspException
    
{
        
try
        
{
            String javaName 
= this.codeBehind;            
            
if(!javaName.toLowerCase().endsWith(".java"))
                
throw new JspException(codeBehind + " NotFound...");
            
            javaName 
= javaName.substring(0,javaName.lastIndexOf('.'));
            Class codeCls 
= Class.forName(javaName);
            Object objCls 
= codeCls.newInstance();    //建立实例

            
//强制转换成基类[BasePage]
            BasePage bPage = (BasePage)objCls;
            bPage.writeContextToBasePage(
this.pageContext);    //后台绑定代码的入口
        }

        
catch(Exception ex){throw new JspException(ex.getMessage());}
        
return EVAL_BODY_INCLUDE;
    }

    
    
public int doEndTag() throws JspException
    
{        
        
return EVAL_PAGE;
    }
    
}

 

 写过TAGLIB的一看就明白了,没什么需要解释的
尽请查看下一篇[实现框架代码 BasePage]篇.

你可能感兴趣的:(java,框架,Class,import,include)