愚僧

          贏與輸?shù)牟顒e通常是--不放棄

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            23 Posts :: 0 Stories :: 2 Comments :: 0 Trackbacks

          2013年2月27日 #



          步驟:
          1. 定義tld標(biāo)簽描述文件
          2. 新建class繼承SimpleTagSupport或者BodyTagSupport
          3. taglib命令聲明
          4. 使用自定義標(biāo)簽

          1. 定義tld標(biāo)簽描述文件custom_tag.tld
          <?xml version="1.0" encoding="UTF-8"?>
          <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation
          ="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
              version
          ="2.0">
              <description>JSTL 1.1 core library</description>
              <display-name>JSTL core</display-name>
              <tlib-version>1.1</tlib-version>
              <short-name>ct</short-name>
              <!-- 與 taglib 的 uri 對(duì)應(yīng) -->
              <uri>http://www.customtag.com/custom_tag</uri>
              <!-- 定義一個(gè)標(biāo)簽 -->
              <tag>
                  <!-- 標(biāo)簽的名稱 -->
                  <name>date</name>
                  <!-- 標(biāo)簽類 -->
                  <tag-class>com.customtag.tags.DateTag</tag-class>
                  <!-- 標(biāo)簽體 -->
                  <body-content>empty</body-content>
                  <attribute>
                      <!-- 屬性名稱 -->
                      <name>format</name>
                      <!-- 是否必選 true:必選 -->
                      <required>false</required>
                      <!-- 是否允許使用表達(dá)式(EL), false:不能使用 -->
                      <rtexprvalue>false</rtexprvalue>
                  </attribute>
                  <attribute>
                      <name>value</name>
                      <required>false</required>
                      <rtexprvalue>true</rtexprvalue>
                  </attribute>
              </tag>
          </taglib>
          注:
          可參考jstl-[version].jar中META-INF下的c.tld文件

          2. 新建DateTag繼承SimpleTagSupport或者BodyTagSupport
          package com.customtag.tags;

          import java.io.IOException;
          import java.text.SimpleDateFormat;
          import java.util.Date;

          import javax.servlet.jsp.JspException;
          import javax.servlet.jsp.JspWriter;
          import javax.servlet.jsp.PageContext;
          import javax.servlet.jsp.tagext.SimpleTagSupport;

          public class DateTag extends SimpleTagSupport {
              
              @Override
              public void doTag() throws JspException, IOException {
                  SimpleDateFormat sdf = new SimpleDateFormat(format);
                  PageContext pc = (PageContext) getJspContext();
                  JspWriter out = pc.getOut();
                  try{
                      if(null != this.getValue()){
                          out.print(sdf.format(new Date(this.getValue())));
                      }else{
                          out.print(sdf.format(new Date()));
                      }
                  }catch(IOException e){
                      throw e;
                  }catch(Exception e){
                      out.print("");
                  }
              }
              
              private String format="yyyy-MM-dd HH:mm:ss";
              
              private Long value = null;
              
              public String getFormat() {
                  return format;
              }

              public void setFormat(String format) {
                  this.format = format;
              }

              public Long getValue() {
                  return value;
              }

              public void setValue(Long value) {
                  this.value = value;
              }
              
          }

          3. taglib命令聲明
          <%@taglib prefix="ct" uri="http://www.customtag.com/custom_tag"%>

          4. 使用自定義標(biāo)簽
          <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
          <%
              
          String path = request.getContextPath();
              
          String basePath = request.getScheme() + "://"
                      
          + request.getServerName() + ":" + request.getServerPort()
                      
          + path + "/";
          %>
          <%@taglib prefix="ct" uri="http://www.customtag.com/custom_tag"%>

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
              <head>
                  <base href="<%=basePath%>">

                  <title>My JSP 'index.jsp' starting page</title>
                  <meta http-equiv="pragma" content="no-cache">
                  <meta http-equiv="cache-control" content="no-cache">
                  <meta http-equiv="expires" content="0">
                  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
                  <meta http-equiv="description" content="This is my page">
                  <!--
                  <link rel="stylesheet" type="text/css" href="styles.css">
                  
          -->
              </head>

              <body>
                  自定義標(biāo)簽測(cè)試 : 
                  <br>
                  <ct:date/><br/>
                  <ct:date format="MM/dd/yyyy"/><br/>
                  <ct:date format="yyyy年MM月dd日 HH時(shí)mm分ss秒" value="<%=new Date().getTime() %>"/><br/>
              </body>
          </html>

          [運(yùn)行結(jié)果]
          自定義標(biāo)簽測(cè)試:
          2013-03-04 16:18:29
          03/04/2013
          2013年03月04日 16時(shí)18分29秒
          posted @ 2013-03-04 16:35 ywm 閱讀(122) | 評(píng)論 (0)編輯 收藏


          以下情況被認(rèn)為 false :
          • boolean類型的FALSE
          • int類型的0
          • 浮點(diǎn)類型的0.0
          • 字符串"" 或者 "0"
          • 空的數(shù)組
          • 空的對(duì)象null
          其他情況都認(rèn)為是true






          posted @ 2013-03-01 17:51 ywm 閱讀(133) | 評(píng)論 (0)編輯 收藏


          用于執(zhí)行控制臺(tái)命令

          $output = `ls -al`;
          echo "<pre>$output</pre>";

          有對(duì)平臺(tái)依賴性, 降低了php跨平臺(tái)能力
          posted @ 2013-03-01 16:30 ywm 閱讀(99) | 評(píng)論 (0)編輯 收藏

          用于忽略掉錯(cuò)誤信息

          <?php
          //忽略包含文件時(shí)產(chǎn)生的錯(cuò)誤
          @include("inc.php");
          //忽略連接mysql數(shù)據(jù)庫(kù)出錯(cuò)產(chǎn)生的錯(cuò)誤信息
          $conn = @mysql_connect("localhost","username","password");
          //忽略打開文件產(chǎn)生的錯(cuò)誤信息
          $fp  = @fopen("user.xml","w");
          function test(){
          return 10;
          }
          //忽略調(diào)用函數(shù)失敗產(chǎn)生的錯(cuò)誤信息
          $number = @test();
          ?>
          posted @ 2013-03-01 16:25 ywm 閱讀(108) | 評(píng)論 (0)編輯 收藏


          serialize : 序列表表格內(nèi)容為字符串, 返回的是一個(gè)字符串
          var serializeStr = $("form").serialize();
          result : username=forrest&passwd=1234&gender=0&interest=swimming&interest=running&interest=readBook

          serializeArray : 序列化表格元素 (類似 '.serialize()' 方法) 返回 JSON 數(shù)據(jù)結(jié)構(gòu)數(shù)據(jù)
          var fields = $("select, :radio").serializeArray();
          jQuery.each( fields, function(i, field){
            $("#results").append(field.name + "=" +field.value + "; ");
          });
          result : username=forrest; passwd=1234; gender=0; interest=swimming; interest=running; interest=readBook; 
          posted @ 2013-03-01 15:42 ywm 閱讀(644) | 評(píng)論 (2)編輯 收藏


          Class.forName("binary name");
          加載并對(duì)類變量進(jìn)行初始化
          等價(jià)cl.loadClass("binary name").newInstance();

          ClassLoader.loadClass("binary name");
          ClassLoader cl = this.getClass().getClassLoader();
          Class c = cl.loadClass("binary name");
          Object obj = c.newInstance();
          在newInstance時(shí)初始化
          初始化時(shí)會(huì)比f(wàn)orName多產(chǎn)生一個(gè)obj對(duì)象

          From : http://waryist.iteye.com/blog/131983
          posted @ 2013-02-27 15:57 ywm 閱讀(127) | 評(píng)論 (0)編輯 收藏


          escape/unescape : 不能對(duì)uri編碼, 會(huì)把 / ? @ 進(jìn)行編碼
          encodeURIComponet/decodeURIComponent : 對(duì)URI參數(shù)編碼, 會(huì)把 / 進(jìn)行編碼
          encodeURI/decodeURI : 對(duì)URI編碼

          From : http://blog.163.com/free_for_all/blog/static/6871811201192441843281/
          From : http://www.cnblogs.com/qiantuwuliang/archive/2009/07/19/1526687.html
          posted @ 2013-02-27 11:44 ywm 閱讀(120) | 評(píng)論 (0)編輯 收藏


          uri : Uniform Resource Identifier 統(tǒng)一資源標(biāo)識(shí)
          url : Uniform Resource Locator   統(tǒng)一資源定位

          異:
          url是uri的一個(gè)子集
          url可以用相對(duì)路徑表示, url 只能用絕對(duì)路徑表示

          同:
          url,uri 都能定位唯一資源

          注:
          [scheme:][//authority][path][?query][#fragment]
          authority為[user-info@]host[:port]
          相對(duì)路徑和絕對(duì)路徑看是否使用"scheme:"開頭

          From : http://www.cnblogs.com/gaojing/archive/2012/02/04/2413626.html
          From : http://rebecca.iteye.com/blog/234724


          posted @ 2013-02-27 10:59 ywm 閱讀(132) | 評(píng)論 (0)編輯 收藏

          主站蜘蛛池模板: 昆明市| 湖北省| 巴彦县| 天峨县| 松潘县| 唐河县| 锡林郭勒盟| 闽清县| 万全县| 吕梁市| 平果县| 石泉县| 郴州市| 鄂托克旗| 武宁县| 临城县| 大名县| 报价| 修水县| 丹东市| 临夏县| 澄城县| 且末县| 上栗县| 兰考县| 平乡县| 安康市| 九江县| 两当县| 万山特区| 三亚市| 垣曲县| 苍梧县| 鸡西市| 平昌县| 彭阳县| 浠水县| 江孜县| 汾西县| 阜城县| 米脂县|