大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> JSP专区 -> JSP中的TagLib应用(4)--zt

JSP中的TagLib应用(4)--zt

时间: 2021-07-31 作者:daque

jsp中的taglib运用(4)作家:false / aspcn ---------------------------------------------------------------------- 底下到了要害局部乐。 对tag举行处置。本来很多情景下咱们是运用仍旧供给的taglib. 旁人/公司仍旧做好了tag和处置局部,打好了包 咱们须要做的不过在咱们的jsp中去运用. 然而当咱们本人做个taglib时, 就须要编写这局部tag handler了. 这边只对准上头文献里提到的insert tag,其余的为了制止反复,就不逐一说领会 ==================== inserttag.java============================== /* * $id: inserttag.java,v 1.13 2000/03/04 02:54:57 brydon exp $ * copyright 1999 sun microsystems, inc. all rights reserved. * copyright 1999 sun microsystems, inc. tous droits réservés. */ package com.sun.estore.taglib; import javax.servlet.jsp.jsptagexception; import javax.servlet.jsp.tagext.tagsupport; import com.sun.estore.util.debug; /** * this class is an easy interface to the jsp template or other * text that needs to be inserted. * @author greg murray */ public class inserttag extends tagsupport { private boolean directinclude = false; private string parameter = null; private string templatename = null; private template template = null; private templateparameter templateparam = null; /** * default constructor */ public inserttag() { super(); } public void settemplate(string templatename){ this.templatename = templatename; } public void setparameter(string parameter){ this.parameter = parameter; } public int dostarttag() { try{ if (templatename != null){ template = (template)pagecontext.getrequest().getattribute("template"); } } catch (nullpointerexception e){ debug.println("error extracting template from session: " + e); } if (parameter != null && template != null) templateparam = (templateparameter)template.getparam(parameter); if (templateparam != null) directinclude = templateparam.isdirect(); return skip_body; } public int doendtag() throws jsptagexception { try{ pagecontext.getout().flush(); } catch (exception e){ // do nothing } try { if (directinclude && templateparam != null) { pagecontext.getout().println(templateparam.getvalue()); } else if (templateparam != null) { if (templateparam.getvalue() != null) pagecontext.getrequest().getrequestdispatcher(templateparam.getvalue()).include(pagecontext.getrequest(), pagecontext.getresponse()); } } catch (throwable ex) { ex.printstacktrace(); } return eval_page; } } 不妨看到。inserttag.java接受了javax.servlet.jsp.tagext.tagsupport类. 由于在tagsupport中设置了少许接口.   咱们在处置自设置的tag时, 对父类的dostarttag() 和doendtag() 要举行重载,即使在tld文献中设置了tag的属性, 就须要在tag handler里对每个属性设置相映的setxxx/getxxx本领. 在dostarttag()中是从template类所设置的hashtable中博得templateparameter东西. 在doendtag()中 pagecontext.getrequest().getrequestdispatcher(templateparam.getvalue()).include(pagecontext.getrequest(), pagecontext.getresponse()); 这是在页面里包括经过jsp页的左右文归来经过tag的属性值指定的资源东西(requestdispatcher)所爆发的实质.. dostarttag()和doendtag()归来值是在tag interface里设置的静态int skip_body隐含0 skip body evaluation. valid return value for dostarttag and doafterbody. 跳过对body的处置。 即是跳过了发端和中断标签之间的代码。 eval_body_include 隐含1 evaluate body into existing out stream. valid return value for dostarttag. this is an illegal return value for dostarttag when the class implements bodytag, since bodytag implies the creation of a new bodycontent. 将body的实质输入到生存的输入流中。囊括是jsp代码,也不妨被输入 skip_page 隐含5 skip the rest of the page. valid return value for doendtag. 忽视剩下的页面。 eval_page 隐含6 continue evaluating the page. valid return value for doendtag(). 连接实行底下的页 在这个类里再有对其余类的援用,我就不列出来了. 诸位不妨本人去接洽. 自设置标签(custom tags)实行了 javax.servlet.jsp.tagext.tag or javax.servlet.jsp.tagext.bodytag interface. 运用javax.servlet.jsp.jspwriter 来输入. tagsupport class 供给了对interface tag的隐含实行. 序列化编辑发表数据. public class tagsupport extends java.lang.object implements tag, java.io.serializable bodytagsupport class供给了对interface bodytag的隐含实行.接受tagsupport public class bodytagsupport extendstagsupport implements bodytag 咱们在编写tag handler时须要接受tagsupport类或bodytagsupport类,而后重载dostarttag()和doendtag(). 还不妨再进一步辨别.将简直实行放到bean里 那些自设置标签的类所应放的场所该当在web-inf/classes或web-inf/lib 结果将custom tag libraries 打包成.war文献.对于.war文献,如次图所示给出了资源构造图。 经过安置刻画符来遏制映照。 安置刻画符是个xml文献。精细的请详见相关文书档案材料。这边只证明 安置taglib的局部。 jsp custom tag libraries (optional) specifies url for locating tag library descriptor … uri path … /**************自设置taglib例子: jsp page ******************* ……… *******************************************************/ 文献场所如次: 这个例子很大略, 不过动作熟习运用.你也不妨本人举行扩充,多熟习几种处置本领.比如说标签带有属性, 标签带有实质, 运用bean处置论理之类 对于将那些文献打包成.war文献.这边就不精细说领会.请按照你运用的application server情景本人实行吧. 

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.