第一步:首先创建一个tld;
第二步:a.jsp引用tld文件并使用某个标签
第三步:taglib.DTag继承TagSupport 拦截该标签,并把获得的数据库数据放到b.jsp
//b.jsp获得request中set的数据
public String Path()
{
return “/WEB-INF/taglib/b.jsp”;
}
public int doStartTag() throws JspException
{
//1,从数据库加载数据
Service Service = (Service)SpringContextHolder.getBean(“Service”);
List dicItemBeanList =T.query(…);
//2、将标签信息设置到页面
getRequest().setAttribute("", );
return SKIP_BODY;
}
第四步:把b.jsp加载到a.jsp
public int doEndTag() throws JspException
{
try
{
ServletContext servletContext = pageContext.getServletContext();
//加载b.jsp
RequestDispatcher dispatcher = servletContext.getRequestDispatcher(Path());
TagPageResponseWrapper wrapper = new TagPageResponseWrapper(getResponse());
dispatcher.include(getRequest(), wrapper);
JspWriter jspWriter = pageContext.getOut();
jspWriter.write(wrapper.getContent());
}
catch(Exception e)
{
e.printStackTrace();
}
return EVAL_PAGE;
}
OVER…
版权所有,请勿转载,谢谢