亚洲AV无码国产精品色,亚洲美女视频一区,亚洲片国产一区一级在线观看http://m.tkk7.com/secret/zh-cnMon, 12 May 2025 06:51:52 GMTMon, 12 May 2025 06:51:52 GMT60swt Combo 設(shè)置值和顯示內(nèi)容http://m.tkk7.com/secret/archive/2011/08/02/355589.htmlsecret_x15secret_x15Tue, 02 Aug 2011 06:22:00 GMThttp://m.tkk7.com/secret/archive/2011/08/02/355589.htmlhttp://m.tkk7.com/secret/comments/355589.htmlhttp://m.tkk7.com/secret/archive/2011/08/02/355589.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/355589.htmlhttp://m.tkk7.com/secret/services/trackbacks/355589.htmlimport org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ComboTest {

    
public static void main(String[] args) {
        String[] WEEK 
= { "Monday""Tuesday""Wednesday"};
        Display display 
= new Display();
        Shell shell 
= new Shell(display);
        shell.setBounds(
500100500300);
        shell.setText(
"Combo");
        shell.setLayout(
new GridLayout(3true));
        
        
//創(chuàng)建Combo組件,為下拉列表樣式
        final Combo dc = new Combo(shell, SWT.DROP_DOWN);
        dc.setItems(WEEK);
        dc.addSelectionListener(
new SelectionAdapter(){
            @Override
            
public void widgetSelected(SelectionEvent e) {
                String key 
= ""+dc.getSelectionIndex();
                String value 
= dc.getText();
                System.out.println(
"key:"+key+"    value:"+value);
            }
        });
        
        
//創(chuàng)建Combo組件,為下拉列表樣式,且只讀
        final Combo rc = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
        
//在界面中顯示的是123
        rc.add("123");
        
//第一個(gè)值是key從0開始 ,第二個(gè)值為value
        rc.setData("0""321");
        
        rc.add(
"456");
        rc.setData(
"1""654");
        
        rc.addSelectionListener(
new SelectionAdapter(){
            @Override
            
public void widgetSelected(SelectionEvent e) {
                String key 
= ""+rc.getSelectionIndex();
                System.out.println(
"key:"+key);
                String value 
= (String) rc.getData(key);
                System.out.println(
"key:"+key+"    value:"+value);
            }
        });
        
//rc.setItems(MONTHS);
        
//創(chuàng)建Combo組件,為List組件樣式
        Combo sc = new Combo(shell, SWT.SIMPLE);
        sc.setItems(WEEK);
        shell.open();
        
while (!shell.isDisposed()) {
           
if (!display.readAndDispatch()) {
               display.sleep();
          }
     }

     display.dispose();

    }

}


]]>
Eclipse添加DTD文件實(shí)現(xiàn)xml的自動(dòng)提示功能http://m.tkk7.com/secret/archive/2011/06/29/353377.htmlsecret_x15secret_x15Wed, 29 Jun 2011 10:18:00 GMThttp://m.tkk7.com/secret/archive/2011/06/29/353377.htmlhttp://m.tkk7.com/secret/comments/353377.htmlhttp://m.tkk7.com/secret/archive/2011/06/29/353377.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/353377.htmlhttp://m.tkk7.com/secret/services/trackbacks/353377.html Eclipse添加DTD文件實(shí)現(xiàn)xml的自動(dòng)提示功能

1.點(diǎn)擊 window -->Preferences -->XML -->XML Catalog  -->Add..

2.點(diǎn)擊Add 彈出一個(gè)對話框,如圖所示



3.填寫文本框中的內(nèi)容

Location : dtd的路徑。可以是eclipse工作空間的dtd,也可以是文件中的dtd。
Key type:選擇 Public ID
Key:為ibatis xml文件頭中<!DOCTYPE sqlMapConfig PUBLIC 后面的一段。即:-//ibatis.apache.org//DTD SQL Map Config 2.0//EN

4. 點(diǎn)擊OK 按鈕,重啟eclipse.


]]>
關(guān)于js中window.location.href,location.href,parent.location.href,top.location.href的用法http://m.tkk7.com/secret/archive/2011/06/28/353132.htmlsecret_x15secret_x15Tue, 28 Jun 2011 02:25:00 GMThttp://m.tkk7.com/secret/archive/2011/06/28/353132.htmlhttp://m.tkk7.com/secret/comments/353132.htmlhttp://m.tkk7.com/secret/archive/2011/06/28/353132.html#Feedback1http://m.tkk7.com/secret/comments/commentRss/353132.htmlhttp://m.tkk7.com/secret/services/trackbacks/353132.html
"window.location.href"、"location.href"是本頁面跳轉(zhuǎn).
"parent.location.href" 是上一層頁面跳轉(zhuǎn).
"top.location.href" 是最外層的頁面跳轉(zhuǎn).
舉例說明:
    如果A,B,C,D都是html,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js這樣寫
    "window.location.href"、"location.href":D頁面跳轉(zhuǎn)
    "parent.location.href":C頁面跳轉(zhuǎn)
    "top.location.href":A頁面跳轉(zhuǎn)
如果D頁面中有form的話,
    <form>:  form提交后D頁面跳轉(zhuǎn)
    <form target="_blank">:  form提交后彈出新頁面
    <form target="_parent">:  form提交后C頁面跳轉(zhuǎn)
    <form target="_top"> :  form提交后A頁面跳轉(zhuǎn)

如果訪問的是iframe里面的頁面,重新加載最外層的頁面
<html>
<head>
<title></title>
<script language="javascript">
function escapeFrame(){
      
if (window.top.location.href != window.location.href) {
        window.top.location.reload();
      }
}
</script>
</head>

<body onload="escapeFrame()">
<iframe src="b.html" ></iframe>
</body>
</html>


]]>
sort()排序 collections.sort();http://m.tkk7.com/secret/archive/2011/06/22/352813.htmlsecret_x15secret_x15Wed, 22 Jun 2011 08:03:00 GMThttp://m.tkk7.com/secret/archive/2011/06/22/352813.htmlhttp://m.tkk7.com/secret/comments/352813.htmlhttp://m.tkk7.com/secret/archive/2011/06/22/352813.html#Feedback1http://m.tkk7.com/secret/comments/commentRss/352813.htmlhttp://m.tkk7.com/secret/services/trackbacks/352813.htmlmain方法:
public class Test {

    
public static void main(String[] args) {
        
/**
         * 
         * sort()方法詳解
         * 1.Collections.sort(List<T> list) 
         *         根據(jù)元素的自然順序 對指定列表按升序進(jìn)行排序。
         * 2.Collections.sort(List<T> list, Comparator<? super T> c) 
         *         根據(jù)指定比較器產(chǎn)生的順序?qū)χ付斜磉M(jìn)行排序。
         * 
         
*/
        List
<Integer> list = new ArrayList<Integer>();
        list.add(
3);
        list.add(
1);
        list.add(
2);
        
//自然順序
        Collections.sort(list);
        
for(Integer i:list){
            System.out.println(i);
        }
        
        System.out.println(
"===============================================");
        
        Point point2 
= new Point(2,2,2);
        Point point1 
= new Point(1,1,1);
        Point point3 
= new Point(3,1,2);
        
        List
<Point> points = new ArrayList<Point>();
        points.add(point2);
        points.add(point1);
        points.add(point3);
        
        System.out.println(
"===============================================");
        
//根據(jù)point中的升序輸出
        Collections.sort(points, new SortByXdesc());
        
for(Point point:points){
            System.out.println(
"x:"+point.getX()+" y:"+point.getY()+" z:"+point.getZ());
        }
        
        System.out.println(
"===============================================");
        
//根據(jù)point中的x降序輸出
        Collections.sort(points, new SortByXasc());
        
for(Point point:points){
            System.out.println(
"x:"+point.getX()+" y:"+point.getY()+" z:"+point.getZ());
        }
    }

}

降序輸出類SortByXdesc:

public class SortByXdesc implements Comparator<Object> {

    
//根據(jù)point中的x降序輸出
    @Override
    
public int compare(Object o1, Object o2) {
        Point point1 
=(Point)o1;
        Point point2 
=(Point)o2;
        
if(point1.getX()>point2.getX()){
            
return 1;
        }
else{
            
return 0;
        }
    }

}

升序輸出類SortByXasc:

public class SortByXasc implements Comparator<Object> {

    
//根據(jù)point中的x升序輸出
    @Override
    
public int compare(Object o1, Object o2) {
        Point point1 
=(Point)o1;
        Point point2 
=(Point)o2;
        
if(point1.getX()>point2.getX()){
            
return 0;
        }
else{
            
return 1;
        }
    }
}



]]>
jquery 取值http://m.tkk7.com/secret/archive/2011/06/21/352738.htmlsecret_x15secret_x15Tue, 21 Jun 2011 07:00:00 GMThttp://m.tkk7.com/secret/archive/2011/06/21/352738.htmlhttp://m.tkk7.com/secret/comments/352738.htmlhttp://m.tkk7.com/secret/archive/2011/06/21/352738.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/352738.htmlhttp://m.tkk7.com/secret/services/trackbacks/352738.html

jquery radio取值,checkbox取值,select取值,radio選中,checkbox選中,select選中,及其相關(guān)
獲取一組radio被選中項(xiàng)的值
    var item = $('input[@name=items][@checked]').val();
獲取select被選中項(xiàng)的文本
    var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個(gè)元素為當(dāng)前選中值
    $('#select_id')[0].selectedIndex = 1;
radio單選組的第二個(gè)元素為當(dāng)前選中值
    $('input[@name=items]').get(1).checked = true;

獲取值:

文本框,文本區(qū)域:
    $("#txt").attr("value");
多選框checkbox:
    $("#checkbox_id").attr("value");
單選組radio:  
     $("input[@type=radio][@checked]").val();
下拉框select: $('#sel').val();

控制表單元素:
文本框,文本區(qū)域:
    $("#txt").attr("value",'');//清空內(nèi)容
    $("#txt").attr("value",'11');//填充內(nèi)容

多選框checkbox:
                 $("#chk1").attr("checked",'');//不打勾
                 $("#chk2").attr("checked",true);//打勾
                 if($("#chk1").attr('checked')==undefined) //判斷是否已經(jīng)打勾

單選組radio:   
     $("input[@type=radio]").attr("checked",'2');//設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
下拉框select:  
                $("#sel").attr("value",'-sel3');//設(shè)置value=-sel3的項(xiàng)目為當(dāng)前選中項(xiàng)
                $("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option
                $("#sel").empty();//清空下拉框



]]>
struts2的s:checkboxlist標(biāo)簽換行http://m.tkk7.com/secret/archive/2011/06/14/352278.htmlsecret_x15secret_x15Tue, 14 Jun 2011 04:18:00 GMThttp://m.tkk7.com/secret/archive/2011/06/14/352278.htmlhttp://m.tkk7.com/secret/comments/352278.htmlhttp://m.tkk7.com/secret/archive/2011/06/14/352278.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/352278.htmlhttp://m.tkk7.com/secret/services/trackbacks/352278.htmlstruts2里增加了一個(gè)新的UT標(biāo)簽s:checkboxlist,下面介紹下使用方法。
s:checkboxlist用于畫面上顯示一組復(fù)選框,缺省是橫排輸出,后面將介紹如何修改ftl文件使得它能按任意方式輸出。
標(biāo)簽格式:
    <s:checkboxlist name="" list="" listKey="" listValue="" value="" />
    name-定義標(biāo)簽名,用于接收畫面上選中的復(fù)選框,故應(yīng)與Action里定義的屬性一致,且多為數(shù)組;
    list-定義集合變量,用于輸出復(fù)選框到畫面上,一般在Action里定義一個(gè)List或Map屬性;
    listKey-如果在Action里定義的是一個(gè)List,則往往會(huì)在List里定義一個(gè)Bean,它只有兩個(gè)屬性,其中一個(gè)(比如id)就在這里設(shè)置;
                如果在Action里定義的是一個(gè)Map,則Map的key就在這里設(shè)置;
    listValue-如果在Action里定義的是一個(gè)List,則往往會(huì)在List里定義一個(gè)Bean,它只有兩個(gè)屬性,另外一個(gè)(比如name)就在這里設(shè)置;
                  如果在Action里定義的是一個(gè)Map,則Map的value就在這里設(shè)置;
    value-用于回顯畫面上被選中的復(fù)選框,假如畫面有輸入檢查,如果有錯(cuò)則返回原畫面并顯示出錯(cuò)信息,這時(shí)候就需要使用它。
             一般把它設(shè)成和name一致就可以了。
注意點(diǎn):
    為了能正確顯示已被選中的復(fù)選框,一定要使得name的數(shù)組類型與listKey的類型一致。
    比如,name設(shè)成String[] users,則listKey就要設(shè)成String id;如果name設(shè)成Integer[] users,則listKey就要設(shè)成Integer id;
修改ftl文件改變輸出方式:
    1.搜索struts2-core-xxx.jar,找到checkboxlist.ftl文件,拷貝出來;
    2.在自己的工程的src下新建template.simple包,放置上述文件;
    3.用文本編輯器打開該文件,修改成自己希望輸出的格式,保存,OK;
例子:
    希望畫面上每3個(gè)復(fù)選框輸出為一行。
<#--
/*
 * $Id: checkboxlist.ftl 804072 2009-08-14 03:16:35Z musachy $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
-->
<#assign itemCount = 0/>
<#if parameters.list?exists>
     <@s.iterator value="parameters.list">
         <#assign itemCount = itemCount + 1/>
         <#if parameters.listKey?exists>
             <#assign itemKey = stack.findValue(parameters.listKey)/>
         <#else>
             <#assign itemKey = stack.findValue('top')/>
         </#if>
         <#if parameters.listValue?exists>
             <#assign itemValue = stack.findString(parameters.listValue)/>
         <#else>
             <#assign itemValue = stack.findString('top')/>
         </#if>
 <#assign itemKeyStr=itemKey.toString() />
 <#if (itemCount-1)%3 == 0>
 <tr>
 </#if>
 <td>

 <input type="checkbox" name="${parameters.name?html}" value="${itemKeyStr?html}" id="${parameters.name?html}-${itemCount}"<#rt/>
         <#if tag.contains(parameters.nameValue, itemKey)>
  checked="checked"<#rt/>
         </#if>
         <#if parameters.disabled?default(false)>
  disabled="disabled"<#rt/>
         </#if>
         <#if parameters.title?exists>
  title="${parameters.title?html}"<#rt/>
         </#if>
         <#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
         <#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
 />
 <label for="${parameters.name?html}-${itemCount}" class="checkboxLabel">${itemValue?html}</label>
 </td>
 <#if itemCount%3 == 0>
 </tr>

 </#if>
     </@s.iterator>
</#if>
<input type="hidden" id="__multiselect_${parameters.id?html}" name="__multiselect_${parameters.name?html}" value=""<#rt/>
<#if parameters.disabled?default(false)>
 disabled="disabled"<#rt/>
</#if>
 />

]]>
BodyTagSupporthttp://m.tkk7.com/secret/archive/2011/06/14/352277.htmlsecret_x15secret_x15Tue, 14 Jun 2011 04:16:00 GMThttp://m.tkk7.com/secret/archive/2011/06/14/352277.htmlhttp://m.tkk7.com/secret/comments/352277.htmlhttp://m.tkk7.com/secret/archive/2011/06/14/352277.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/352277.htmlhttp://m.tkk7.com/secret/services/trackbacks/352277.html
BodyTagSupport類的方法:
編寫標(biāo)簽對應(yīng)的實(shí)現(xiàn)類時(shí),需要重載BodyTagSupport類幾個(gè)方法:doStartTag(), setBodyContent(), doInitBody(), doAfterBody(), doEndTag();

他們執(zhí)行順序如下:
doStartTag()→doInitBody()→setBodyContent()→doAfterBody()→doEndTag()

doStartTag()方法可返回EVAL_BODY_INCLUDE或SKIP_BODY,
如果返回EVAL_BODY_INCLUDE則繼續(xù)執(zhí)行;
如果返回SKIP_BODY則接下來的doInitBody(),setBodyContent(), doAfterBody()三個(gè)方法不會(huì)被執(zhí)行,
而直接執(zhí)行doEndTag()方法。

setBodyContent()方法用于設(shè)置標(biāo)簽體內(nèi)容,如果在此之前要作一些初始化工作,則在doInitBody()方法中完成。
標(biāo)簽體內(nèi)容執(zhí)行完后,會(huì)調(diào)用doAfterBody()方法,此方法可返回EVAL_BODY_TAG, SKIP_BODY,
EVAL_PAGE或SKIP_PAGE。
如果返回EVAL_BODY_TAG則會(huì)再次設(shè)置標(biāo)簽體內(nèi)容,直到返回SKIP_BODY;
如果返回EVAL_PAGE則標(biāo)簽體執(zhí)行完后會(huì)繼續(xù)執(zhí)行JSP頁面中接下來的部分;
如果返回SKIP_PAGE,則JSP頁面的后續(xù)內(nèi)容將不再執(zhí)行。

標(biāo)簽中靜態(tài)常量:

EVAL_BODY_INCLUDE:告訴服務(wù)器正文的內(nèi)容,并把這些內(nèi)容送入輸出流
SKIP_BODY:告訴服務(wù)器不要處理正文內(nèi)容
EVAL_PAGE:讓服務(wù)器繼續(xù)執(zhí)行頁面
SKIP_PAGE:讓服務(wù)器不要處理剩余的頁面
EVAL_BODY_AGAIN:讓服務(wù)器繼續(xù)處理正文內(nèi)容,只有doAfterBody方法可以返回
EVAL_BODY_BUFFERED:BodyTag接口的字段,在doStartTag()返回
EVAL_BODY_INCLUDE、SKIP_BODY一般由doStartTag()返回,而EVAL_PAPGE、SKIP_PAGE由doEndTag()返回。


]]>
TagSupport與BodyTagSupport的區(qū)別http://m.tkk7.com/secret/archive/2011/06/14/352262.htmlsecret_x15secret_x15Tue, 14 Jun 2011 01:54:00 GMThttp://m.tkk7.com/secret/archive/2011/06/14/352262.htmlhttp://m.tkk7.com/secret/comments/352262.htmlhttp://m.tkk7.com/secret/archive/2011/06/14/352262.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/352262.htmlhttp://m.tkk7.com/secret/services/trackbacks/352262.htmlTagSupport與BodyTagSupport的區(qū)別 
標(biāo)簽: TagSupport與BodyTagSupport的區(qū)別 
1、 TagSupport與BodyTagSupport的區(qū)別

 TagSupport與BodyTagSupport的區(qū)別主要是標(biāo)簽處理類是否需要與標(biāo)簽體交互,如果不需要交互的就用TagSupport,否則如果需要交互就用BodyTagSupport。
    交互就是標(biāo)簽處理類是否要讀取標(biāo)簽體的內(nèi)容和改變標(biāo)簽體返回的內(nèi)容。
    用TagSupport實(shí)現(xiàn)的標(biāo)簽,都可以用BodyTagSupport來實(shí)現(xiàn),因?yàn)锽odyTagSupport繼承了TagSupport。
 2 、doStartTag(),doEndTag(),doAfterBody(),
    doStartTag()方法是遇到標(biāo)簽開始時(shí)會(huì)呼叫的方法,其合法的返回值是EVAL_BODY_INCLUDE與SKIP_BODY,前者表示將顯示標(biāo)簽間的文字,后者表示不顯示標(biāo)簽間的文字;
    doEndTag()方法是在遇到標(biāo)簽結(jié)束時(shí)呼叫的方法,其合法的返回值是EVAL_PAGE與 SKIP_PAGE,前者表示處理完標(biāo)簽后繼續(xù)執(zhí)行以下的JSP網(wǎng)頁,后者是表示不處理接下來的JSP網(wǎng)頁
    doAfterBody()這個(gè)方法是在顯示完標(biāo)簽間文字之后呼叫的,其返回值有EVAL_BODY_AGAIN與SKIP_BODY,前者會(huì)再顯示一次標(biāo)簽間的文字,后者則繼續(xù)執(zhí)行標(biāo)簽處理的下一步。
EVAL_BODY_INCLUDE:把Body讀入存在的輸出流中,doStartTag()函數(shù)可用
EVAL_PAGE:繼續(xù)處理頁面,doEndTag()函數(shù)可用
SKIP_BODY:忽略對Body的處理,doStartTag()和doAfterBody()函數(shù)可用
SKIP_PAGE:忽略對余下頁面的處理,doEndTag()函數(shù)可用
EVAL_BODY_TAG:已經(jīng)廢止,由EVAL_BODY_BUFFERED取代
EVAL_BODY_BUFFERED:申請緩沖區(qū),由setBodyContent()函數(shù)得到的BodyContent對象來處理tag的body,如果類實(shí)現(xiàn)了BodyTag,那么doStartTag()可用,否則非法
EVAL_BODY_BUFFERED 要將BodyContent的內(nèi)容輸出 如:
JspWriter w = pageContext.getOut();
  if (bodyContent != null) {
   if (w instanceof BodyContent) {
    w = ((BodyContent) w).getEnclosingWriter();
   }
  }
  String cnt = this.bodyContent.getString();
  try {
   w.write(cnt);
  } catch (IOException e) {
   e.printStackTrace();
  }

   預(yù)定的處理順序是:doStartTag()返回SKIP_BODY,doAfterBodyTag()返回SKIP_BODY,doEndTag()返回EVAL_PAGE.
   如果繼承了TagSupport之后,如果沒有改寫任何的方法,標(biāo)簽處理的執(zhí)行順序是:

   doStartTag() ->不顯示文字 ->doEndTag()->執(zhí)行接下來的網(wǎng)頁

  如果您改寫了doStartTag(),則必須指定返回值,如果指定了EVAL_BODY_INCLUDE,則執(zhí)行順序是

   doStartTag()->顯示文字->doAfterBodyTag()->doEndTag()->執(zhí)行下面的網(wǎng)頁
display.tld 源碼
xml 代碼:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
    
<tlibversion>1.0</tlibversion>
    
<jspversion>1.1</jspversion>
    
<shortname>bean</shortname>
    
<uri>/WEB-INF/tld/display.tld</uri>
    
<tag>
        
<name>display</name>
        
<tagclass>com.liuzhe.common.DisplayTag</tagclass>
        
<bodycontent>JSP</bodycontent>
        
<info>display content</info>
        
<attribute>
            
<name></name>
            
<required></required>
            
<rtexprvalue></rtexprvalue>
        
</attribute>
    
</tag>
</taglib>

DisplayTag.java 源碼
java 代碼:

package com.liuzhe.common;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class DisplayTag extends TagSupport {

    
private static final long serialVersionUID = 4540106083884185193L;

    @Override
    
public int doStartTag() throws JspException {
        System.out.println(
"doStartTag()");
        
return EVAL_BODY_INCLUDE;
    }

    @Override
    
public int doAfterBody() throws JspException {
        System.out.println(
"doAfterBody()");
        
return SKIP_BODY;
    }
    
    @Override
    
public int doEndTag() throws JspException {
        System.out.println(
"doEndTag()");
        JspWriter out 
= this.pageContext.getOut();
        
try {
            out.print(
"hello!");
        } 
catch (IOException e) {
            e.printStackTrace();
        }
        
return super.doEndTag();
    }

}
index.jsp 源碼


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/display.tld" prefix="test" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<test:display>test<br></test:display>
</body>
</html>

注意:這里的“test” 顯示在 hello 前面證明啦 它是先執(zhí)行index.jsp 中標(biāo)簽中的內(nèi)容后才執(zhí)行doEndTag()



]]>
JAVA編程思想 13.5.4 java 字符串> 格式化字符> 購物收據(jù)http://m.tkk7.com/secret/archive/2011/05/24/350909.htmlsecret_x15secret_x15Tue, 24 May 2011 04:47:00 GMThttp://m.tkk7.com/secret/archive/2011/05/24/350909.htmlhttp://m.tkk7.com/secret/comments/350909.htmlhttp://m.tkk7.com/secret/archive/2011/05/24/350909.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/350909.htmlhttp://m.tkk7.com/secret/services/trackbacks/350909.html
import java.util.Formatter;
public class Receipt {
    
private double total = 0;
    
private Formatter f = new Formatter(System.out);
    
    
public void printTitle(){
         f.format(
"%-15s   %5s   %10s\n""Item","Qty","Price");
         f.format(
"%-15s   %5s   %10s\n""----","---","-----");
    }
    
    
public void print(String name,int qty,double price){
         f.format(
"%-15.15s   %5d   %10.2f\n", name,qty,price);
         total 
+= price;
    }
    
    
public void printTotal(){
     f.format(
"%-15.15s   %5s   %10.2f\n""Tax","",total*0.06);
     f.format(
"%-15.15s   %5s   %10s\n""","","-----");
     f.format(
"%-15s   %5s   %10.2f\n""Total","",total*1.06);
    }
    
    
public static void main(String[] args) {
         Receipt receipt 
= new Receipt();
         receipt.printTitle();
         receipt.print(
"Jack's Magic Beans"44.25);
         receipt.print(
"Princess Peas"35.1);
         receipt.print(
"Three Bears Porridge"114.29);
         receipt.printTotal();
    }
    
    
/*
    %[argument_index$][flag][width][.precision]conversion
    在默認(rèn)的情況下,數(shù)據(jù)是右對齊,通過“-”標(biāo)志來改變對齊方向
    width可以用于各種類型的數(shù)據(jù)轉(zhuǎn)換
    precision不是所有類型的數(shù)據(jù)都能使用precision,用于不同數(shù)據(jù)時(shí)的意義不同。
         1.應(yīng)用于String時(shí),它表示打印String時(shí)輸出字符的最大數(shù)量。
         2.應(yīng)用于浮點(diǎn)數(shù)時(shí),它表示小數(shù)部分顯示出來的位數(shù)(默認(rèn)是6位小數(shù)),如果小數(shù)位數(shù)過多四舍五入,太少尾部補(bǔ)零。
         3.應(yīng)用于整數(shù)時(shí),由于整數(shù)沒有小數(shù)部分,則會(huì)觸發(fā)異常。
    
     
*/
    
}

  類型轉(zhuǎn)換字符
d 整數(shù)類型
e 浮點(diǎn)數(shù)(科學(xué)計(jì)數(shù))
c Unicode字符
x 整數(shù)(十六進(jìn)制)
b Boolean值
h 散列碼(十六進(jìn)制)
s String % 字符%
f 浮點(diǎn)數(shù)(十進(jìn)制)        



]]>
主站蜘蛛池模板: 亚洲AV无码一区二区一二区| 亚洲乱码一区二区三区在线观看 | 亚洲视频一区二区三区四区| 337p日本欧洲亚洲大胆精品555588| 亚洲欧洲另类春色校园网站| 久久久久亚洲AV无码专区体验| 亚洲一区二区三区日本久久九| 7777久久亚洲中文字幕蜜桃| 中文字幕亚洲综合久久2| 亚洲影院在线观看| 亚洲精品美女在线观看| 亚洲国产成人久久精品app| 亚洲制服丝袜一区二区三区| 亚洲午夜福利在线视频| 国产精品亚洲专区无码不卡| 亚洲妇熟XXXX妇色黄| 国产精品免费视频一区| 又爽又黄无遮挡高清免费视频| 免费人成无码大片在线观看| 亚洲国产一成久久精品国产成人综合 | 亚洲男人的天堂网站| 香蕉视频亚洲一级| 亚洲AV日韩AV天堂久久| 亚洲国产成人VA在线观看| 美女被cao免费看在线看网站| 在线观看免费人成视频色| 日本免费观看网站| 亚洲综合色在线观看亚洲| 亚洲第一区香蕉_国产a| 77777午夜亚洲| 搜日本一区二区三区免费高清视频 | 亚洲爽爽一区二区三区| 亚洲高清国产拍精品26U| 亚洲人成网站看在线播放| 美女黄网站人色视频免费| 久久精品免费一区二区三区| 99爱免费观看视频在线| 在线观看免费污视频| 久久精品国产亚洲一区二区三区| 国产精品成人无码免费| 亚洲熟妇中文字幕五十中出|