文件结束[置顶] javaweb框架--自定义标签与freemaker结合
題記:寫這篇博客要主是加深自己對文件結(jié)束的認(rèn)識和總結(jié)實(shí)現(xiàn)算法時(shí)的一些驗(yàn)經(jīng)和訓(xùn)教,如果有錯誤請指出,萬分感謝。
????
很有效但是不不知道怎么說,寫個(gè)例子,總之方便多了,并且容易管理,重復(fù)利用強(qiáng)
????
????1、自定一個(gè)類,實(shí)現(xiàn) javax.servlet.jsp.tagext.Tag;(PageTag.java)
????2、建立一個(gè)tld文件(myfTag.tld)
????3、建立一個(gè)freemaker文件*.ftl(page.ftl)
????4、建立jsp頁面,導(dǎo)入標(biāo)簽(<%@taglib prefix="myf" uri="/muyunfei"%>)
????5、jsp中使用(?<myf:page action="/ftlhelloword" curpage="1"></myf:page>)
????6、效果,當(dāng)前使用很方便,如果需要修改直接改freemaker就能夠
?
????---------------------------------tag類開始------------------------------------------
?
public class PageTag implements Tag {public PageContext pagecontex;public JspWriter out;//自定義屬性,當(dāng)前頁private String curpage;//自定義屬性,跳轉(zhuǎn)路徑private String action;//設(shè)置頁面內(nèi)容public void setPageContext(PageContext pc) {pagecontex = pc;out = pc.getOut();//再次方法中不能獲得屬性值}//結(jié)束@SuppressWarnings("unchecked")public int doEndTag() throws JspException {/*freemarker生成模板...開始*/Configuration cfg = new Configuration();//指定freemarker模板位置cfg.setServletContextForTemplateLoading( pagecontex.getServletContext(), "WEB-INF/templates");try {Map root = new HashMap();root.put("curpage", curpage);root.put("action", action);root.put("path",pagecontex.getServletContext().getContextPath());//得到模板Template templ = cfg.getTemplate("page.ftl");//輸出模板templ.process(root, out);} catch (TemplateException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} /*freemarker生成模板...結(jié)束*/return 0;}//開始public int doStartTag() throws JspException {return 0;}public Tag getParent() {return null;}//釋放控件public void release() {}public void setParent(Tag t) {}//-----------get setpublic String getCurpage() {return curpage;}public void setCurpage(String curpage) {this.curpage = curpage;}public String getAction() {return action;}public void setAction(String action) {this.action = action;}}????---------------------------------tag類結(jié)束------------------------------------------
?
????---------------------------------tld文件開始------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?><taglib xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"version="2.1"><description>JSTL tagTest core library</description><display-name>myTag</display-name><tlib-version>1.1</tlib-version><short-name>myf</short-name><!-- 用來引入時(shí)的名字--><uri>/muyunfei</uri><!-- 用來引入時(shí)的地址--><tag><description>pageTag<!--描述 --></description><name>page</name><!--標(biāo)簽的名字--><tag-class>tag.mytag.page.PageTag</tag-class><!-- 對應(yīng)的java類,要寫全--><body-content>JSP</body-content><attribute><!-- 屬性,可以多個(gè)--><name>curpage</name><!-- 自己在java文件中定義的私有變量 --><required>true</required> <!-- 標(biāo)簽是不是必須該屬性 --><rtexprvalue>false</rtexprvalue> <!-- 是不是支撐表達(dá)式 --></attribute><attribute><name>action</name><!-- 自己在java文件中定義的私有變量 --><required>true</required> <!-- 標(biāo)簽是不是必須該屬性 --><rtexprvalue>true</rtexprvalue> <!-- 是不是支撐表達(dá)式 --></attribute></tag></taglib> 每日一道理生活中受傷難免,失敗跌倒并不可怕,可怕的是因此而一蹶不振,失去了對人生的追求與遠(yuǎn)大的理想。沒有一個(gè)人的前進(jìn)道路是平平穩(wěn)穩(wěn)的,就算是河中穿梭航行的船只也難免顛簸,生活中所遇上的坎坷磨難不是偶爾給予的為難,而是必然所經(jīng)受的磨練。
????---------------------------------tld文件結(jié)束------------------------------------------
?
????---------------------------------freemaker文件*.ftl(page.ftl)???? 開始------------------------------------------
<div class="grid-outPagerImg" οnclick="endpage()" style="float:right;padding-top: 0px"><img alt="最后頁" border="0" src="${path}/images/last.png" style="cursor:hand;" οnmοuseοut="this.src='${path}/images/last.png'" οnmοuseοver="this.src='${path}/images/lasth.png'"></img> </div> <div class="grid-inPagerImg " οnclick="next()" style="float:right;padding-top: 1px"> <img alt="后一頁" border="0" src="${path}/images/next.png" style="cursor:hand;" οnmοuseοut="this.src='${path}/images/next.png'" οnmοuseοver="this.src='${path}/images/nexth.png'"></img> </div> <div class="grid-pagerText" style="float:right;padding-top: 2px">?頁/共<label id="totilepage"></label>頁</div> <input type="text" id="curpage" style="width: 20px;float:right"/> <div class="grid-pagerText" style="float:right;padding-top: 2px">?第?</div> <div class="grid-inPagerImg " οnclick="javascript:alert('${action}?curpage=${curpage}')"" style="float:right;padding-top: 1px"> <img alt="前一頁" border="0" src="${path}/images/prev.png" style="cursor:hand;" οnmοuseοut="this.src='${path}/images/prev.png'" οnmοuseοver="this.src='${path}/images/prevh.png'"></img> </div><div class="grid-outPagerImg" οnclick="javascript:alert('${action}?curpage=${curpage}')" style="float:right;padding-top: 0px"><img alt="第一頁" border="0" src="${path}/images/first.png" style="cursor:hand;" οnmοuseοut="this.src='${path}/images/first.png'" οnmοuseοver="this.src='${path}/images/firsth.png'"></img> </div><div class="grid-fnCreatePagerInnerHtml" id="ajaxtablefnCreatePagerInnerHtml"> <div class="grid-allNumberImg grid-pagerText" style="color:#09f;width:85px;float:right;padding-top: 2px"> 共有記錄<label id="totilerecode">${curpage}</label>條</div></div>????---------------------------------freemaker文件*.ftl(page.ftl)???? 結(jié)束------------------------------------------
?
????---------------------------------jsp頁面???? 開始------------------------------------------
?
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@taglib prefix="myf" uri="/muyunfei"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>My JSP 'myftag.jsp' starting page</title></head><body>自定義控件使用: <br><myf:page action="/ftlhelloword" curpage="1"></myf:page></body> </html>????
????---------------------------------jsp頁面???? 結(jié)束------------------------------------------
?
文章結(jié)束給大家分享下程序員的一些笑話語錄: 面試官:熟悉哪種語言
應(yīng)聘者:JAVA
面試官:知道什么叫類么
應(yīng)聘者:我這人實(shí)在,工作努力,不知道什么叫累
面試官:知道什么是包?
應(yīng)聘者:我這人實(shí)在 平常不帶包 也不用公司準(zhǔn)備了
面試官:知道什么是接口嗎?
應(yīng)聘者:我這個(gè)人工作認(rèn)真。從來不找借口偷懶
面試官:知道什么是繼承么
應(yīng)聘者:我是孤兒沒什么可以繼承的
面試官:知道什么叫對象么?
應(yīng)聘者:知道,不過我工作努力,上進(jìn)心強(qiáng),暫時(shí)還沒有打算找對象。
面試官:知道多態(tài)么?
應(yīng)聘者:知道,我很保守的。我認(rèn)為讓心愛的女人為了自已一時(shí)的快樂去墮胎是不道德的行為!請問這和C#有什么關(guān)系??
總結(jié)
以上是生活随笔為你收集整理的文件结束[置顶] javaweb框架--自定义标签与freemaker结合的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: balanced binary sear
- 下一篇: IT人士有哪些保健建议