jsp自定義標籤2

2021-09-24 02:07:15 字數 3349 閱讀 2364

1.1 助手類

1.2 tld

1.3 taglib

資料標籤開發乙個set標籤

開發乙個ui標籤中的out標籤

應用一下,結果如下:

控制標籤

開發乙個if標籤和foreach 標籤

select標籤

public class selecttag extends bodytagsupport  catch (ioexception e)  catch (exception e) 

return super.dostarttag(); }

private string tohtml() throws exception

string value;

string html;

for (object obj : items)

return sb.tostring();

} public string getid()

public void setid(string id)

public string getname()

public void setname(string name)

public listgetitems()

public void setitems(listitems)

public string gettextkey()

public void settextkey(string textkey)

public string gettextval()

public void settextval(string textval)

public string getselectval()

public void setselectval(string selectval)

public string getheadertextkey()

public void setheadertextkey(string headertextkey)

public string getheadertextval()

public void setheadertextval(string headertextval)

}

在tld裡:

如果要預設選中bbb的話,加上這些

開發乙個checkbox標籤

public class checkboxtag extends bodytagsupport 

public void settextkey(string textkey)

public string gettextval()

public void settextval(string textval)

public listgetcheckedval()

public void setcheckedval(listcheckedval)

public listgetitem()

public void setitem(listitem)

public checkboxtag(string textkey, string textval, listcheckedval, listitem)

public checkboxtag()

@override

public int dostarttag() throws jspexception catch (ioexception e) catch (exception e)

return super.dostarttag();

} public string tohtml() throws exception

else

} return sb.tostring();

}}

checkbox

com.tags.checkboxtag

jsptextkey

true

true

textval

true

true

item

true

true

checkedval

false

true

應用一下:

JSP自定義標籤

1.jsp自定義標籤組成部分 web.xml載入標籤庫,標籤庫描述檔案 tld 標籤處理程式類。2.在自定義標籤的起始和結束標籤之間的部分為標籤體 body 3.分別介紹一下jsp自定義標籤的三個組成部分,以輸出經典的 helloworld為例。修改web.xml載入標籤庫 描述標籤庫檔案 tld ...

JSP自定義標籤

1 開發自定義標籤庫 繼承父類 tagsupport重寫dotag 方法 2 建立tld檔案 1.0mytaglib web inf tlds diego.tld hellotag hellotag empty 3 使用標籤庫 taglib uri web inf tlds diego.tld pr...

JSP自定義標籤

測試環境 tomcat5.5 新增的jar包 jstl.jar standard.jar 自定義jsp標籤的處理過程 來自網上 1 在jsp中引入標籤庫 taglib prefix taglibprefix uri tagliburi 2 在jsp中使用標籤庫標籤 3 web容器根據第二個步驟中的p...