新网站上线怎么做seo,网站建设中网站图片如何修改,网站添加外链,张家港建设银行网站效果如图#xff1a;1、JSP规范1.1版本后增加了自定义标签库。实现自定义标签的步骤(1)开发自定义标签处理类。(2)建立*.tld文件。(3)在web.xml中增加自定义标签的定义。(4)在jsp中使用自定义标签。2、自定义标签类(1)继承javax.servlet.jsp.tagext.TagSupport(2)标签类属性1、JSP规范1.1版本后增加了自定义标签库。实现自定义标签的步骤(1)开发自定义标签处理类。(2)建立*.tld文件。(3)在web.xml中增加自定义标签的定义。(4)在jsp中使用自定义标签。2、自定义标签类(1)继承javax.servlet.jsp.tagext.TagSupport(2)标签类属性及每个属性的getter和setter方法(3)重写doStartTag或doEndTag方法。当jsp解析这个标签的时候在“”时触发 doEndTag 事件。通常在 doStartTag 里进行初始化,流程选择操作在 doEndTag 里后续页面输出控制。import java.io.IOException;import javax.servlet.jsp.JspException;import javax.servlet.jsp.tagext.TagSupport;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/**** author liuxi*/public class PageThirdTag extends TagSupport {private static final Log log LogFactory.getLog(PageTwoTag.class);private String formName;private String curPage;private String showPages;private String totalPages;private String PREVIOUS_PAGE 上一页;private String NEXT_PAGE 下一页 ;public String getHref(int number) {return Javascript:ToPage( number );;}public String goHref(int number) {return number ;}public int doEndTag() throws JspException {int showPages Integer.parseInt(this.showPages);int curpage Integer.parseInt(this.curPage);int totalPages Integer.parseInt(this.totalPages);StringBuffer strBuf new StringBuffer(512);// 总页数int pagecount totalPages;// 初始化值if (curpage 0) {curpage 1;} else {if (curpage 0) {curpage 1;}if (curpage pagecount) {curpage pagecount;}}strBuf.append(strBuf.append(.pagebox{margin-left:2px;padding:3px 5px 3px 5px; border:1px solid #fff; background-color:#ebebeb;color:#FFFFFF; font-size:12px;});strBuf.append(.cpagebox{margin-left:2px;padding:3px 5px 3px 5px; border:1px gray; background-color:#ebebeb; color:red; font-size:12px;});strBuf.append(.vpagebox{margin-left:2px;padding:3px 5px 3px 5px; background-color:#FFFFFF; color:#000000;font-size:12px;});strBuf.append();strBuf.append(strBuf.append(function ToPage(p) { \n);strBuf.append(window.document. formName .pageNo.valuep;\n);strBuf.append(window.document. formName .submit();\n);strBuf.append(});if (curpage 1) {strBuf.append( PREVIOUS_PAGE );}// 分页if (pagecount showPages 2) {for (int i 1; i pagecount; i) {if (i curpage) {strBuf.append( i );} else {strBuf.append(goHref(i));}}} else {if (curpage showPages) {for (int i 1; i showPages; i) {if (i curpage) {strBuf.append( i );} else {strBuf.append(goHref(i));}}strBuf.append(...);strBuf.append(goHref(pagecount));} else if (curpage pagecount - showPages 1) { // 右边strBuf.append(goHref(1));strBuf.append(...);for (int i pagecount - showPages 1; i pagecount; i) {if (i curpage) {strBuf.append( i );} else {strBuf.append(goHref(i));}}} else { // 中间strBuf.append(goHref(1));//strBuf.append(goHref(2));strBuf.append(...);int offset (showPages - 2) / 2;for (int i curpage - offset; i curpage offset; i) {if (i curpage) {strBuf.append( i );} else {strBuf.append(goHref(i));}}strBuf.append(...);strBuf.append(goHref(pagecount));}}// 显示下-页if (curpage ! pagecount) {// 加上链接 curpage1strBuf.append( NEXT_PAGE );}strBuf.append();try {pageContext.getOut().println(strBuf.toString());} catch (IOException e) {e.printStackTrace();log.debug(e.getMessage());}return EVAL_PAGE;}public String getFormName() {return formName;}public void setFormName(String formName) {this.formName formName;}public String getCurPage() {return curPage;}public void setCurPage(String curPage) {this.curPage curPage;}public String getShowPages() {return showPages;}public void setShowPages(String showPages) {this.showPages showPages;}public String getTotalPages() {return totalPages;}public void setTotalPages(String totalPages) {this.totalPages totalPages;}}说明(1)如何输出到jsp页面调用pageContext.getOut().println()。(2)输出后如何作处理函数会返回几个值之一。EVAL_PAGE 表示tag已处理完毕返回jsp页面。3、建立self.tld 文件xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsdversion2.1TEST Tag libraryTEST Tag1.0test/testPage Infopagethirdcom.test.web.tag.PageThirdTagemptythe name of the current formformNametruefalseShow RecordsshowPagestruetrueCurrent PagecurPagetruetrueTotal PagestotalPagestruetrue说明short-nametaglib的名称。nametag的名字。nametag的名字。body-content指tag之间的内容。required是否必填属性。rtexprvalue是否支持动态传值。4、web.xml中加入自定义标签定义test/WEB-INF/tld/self.tld5、jsp中使用该自定义标签6、over大小: 1.4 KB分享到 2010-07-07 20:39浏览 2889评论