Struts+Hibernate模板開發筆記—自訂標籤

來源:互聯網
上載者:User
 

  

1.自訂標籤庫(DateTag.tld)

<?xml version="1.0" encoding="GB2312" ?> <!DOCTYPE taglibPUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN""http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd"><taglib><tlibversion>1.0</tlibversion><jspversion>1.2</jspversion><shortname>Date Tag Library</shortname><info>日期錄入標籤庫</info><tag><name>inputButton</name><tagclass>com.company.demo.tags.DateTag</tagclass><bodycontent>empty</bodycontent><attribute><name>name</name><required>true</required><rtexprvalue>true</rtexprvalue></attribute><attribute><name>type</name><required>true</required><rtexprvalue>true</rtexprvalue></attribute></tag></taglib>

2.Tag類(DateTag.java)

package com.company.demo.tags; import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;import javax.servlet.*;/*** <p>Title: </p>* <p>Description: </p>* <p>Copyright: Copyright (c) 2003</p>* <p>Company: </p>* @author 段洪傑* @version 1.0* 產生日期錄框*/public class DateTag extends TagSupport{String type,name; //類型和參數名public void setType(String type)throws JspException {this.type=type;}public void setName(String name)throws JspException {this.name=name;}public int doStartTag() throws JspException {String string,dialogHeight,dialogWidth,size;if(type=="date") {dialogHeight="290";dialogWidth="240";size="10";}else if(type=="datetime") {dialogHeight="315";dialogWidth="240";size="18";}else {throw new JspTagException("型別參數錯誤,只能選擇date或datetime!");}string="<SCRIPT language=javascript>"+"function selectDate"+name+"(oSource){"+"window.showModalDialog('content/dtpicker.jsp?rn='+Math.random(),oSource,
'dialogHeight:"+dialogHeight+"px; dialogWidth: "+dialogWidth+"px;center: Yes;
help: No; resizable: No;scroll:No;status: No;')"+"}"+"</script>"+"<INPUT readOnly size="+size+" name="+name+" DataType=/"date/" comparer=/"compareToLastUsedOn/" dateTimeType="+type+">"+"<IMG src=/"images/select.gif/" width=/"23/" height=/"23/" align=absMiddle"+" onclick=selectDate"+name+"(document.all(this.sourceIndex-1))> ";try{JspWriter out=pageContext.getOut();out.println(string);}catch(Exception ex){throw new JspTagException("程式調用標籤時出錯: "+ex.getMessage());}return SKIP_BODY;}public int doEndTag() throws JspException {return EVAL_PAGE;}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.