dingfirst

          On the Road

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            8 隨筆 :: 2 文章 :: 3 評論 :: 0 Trackbacks

          2006年7月26日 #

          勵精圖治
          posted @ 2007-09-11 16:29 dingfirst 閱讀(179) | 評論 (0)編輯 收藏

          現在在干啥啊!
          沒有方向,沒有動力。
          十年之后會是什么樣子呢?
          nnd
          郁悶!
          極其郁悶!!!

          改變,
          要改變啊!!

          posted @ 2007-04-25 17:13 dingfirst 閱讀(221) | 評論 (0)編輯 收藏

          問題:
          ??????直接用URLEncoder.encode(fileName,"UTF-8"),得到的文件名長度會被截斷。

          解決方法是:
          ??????文件名先用“GB2312”編碼,然后用“ISO8859_1”解碼。當然也可以在將文件名保存到數據庫之前用“GB2312”編碼。

          代碼如下:

          ?1conn?=?DBUtil.getConnection();
          ?2????????????ps?=?conn.prepareStatement("SELECT?FILE_NAME,?CONTENT_TYPE,?CONTENT?FROM?PUB_JOB_ATTACHMENTS?WHERE?ATTACHID?=??");
          ?3????????????ps.setString(1,getAttachId());
          ?4????????????rs?=?ps.executeQuery();
          ?5????????????if(rs.next())
          ?6????????????{
          ?7????????????????//java.net.URLEncoder.encode(rs.getString("FILE_NAME"),?"UTF-8")
          ?8????????????????response.setContentType(rs.getString("CONTENT_TYPE"));
          ?9????????????????String?fileName=rs.getString("FILE_NAME");
          10????????????????fileName=URLEncoder.encode(fileName,"GB2312");
          11????????????????fileName=URLDecoder.decode(fileName,?"ISO8859_1");
          12????????????????response.addHeader("Content-Disposition",?"attachment;?filename=\""?+?fileName?+?"\"");
          13????????????????Blob?content?=?rs.getBlob("CONTENT");
          14????????????????InputStream?ins?=?content.getBinaryStream();
          15????????????????byte?buffer[]?=?new?byte[1024];
          16????????????????int?length?=?-1;
          17????????????????outs?=?response.getOutputStream();
          18????????????????while((length?=?ins.read(buffer))?!=?-1)
          19????????????????????outs.write(buffer,?0,?length);
          20????????????????ins.close();
          21????????????????outs.flush();
          22????????????}

          posted @ 2006-11-27 18:59 dingfirst 閱讀(1176) | 評論 (0)編輯 收藏

          先看一下Proxy的兩種用法:

          public ? interface ?Foo? {
          ????
          int ?doSomthing();
          }
          ???一個基本的實現:
          public?class?FooImpl?implements?Foo?{
          ????
          public?FooImpl()?{
          ????}


          ????
          public?int?doSomthing()?{
          ????????System.out.println(
          "FooImpl?doSomthing");
          ????????
          return?10;
          ????}

          ????
          }
          ???調用處理類,這也是aop的一種實現方式,呵呵。
          public?class?MyInvocationHandler?implements?InvocationHandler{
          ????Object?proxyObject;
          ????
          ????
          public?MyInvocationHandler(Object?_proxyObject)?{
          ????????
          this.proxyObject=_proxyObject;
          ????}


          ????
          public?Object?invoke(Object?proxy,?Method?method,?Object[]?args)?throws?Throwable?{
          ????????System.out.println(
          "in?proxy?instance");
          ????????
          return?method.invoke(proxyObject,args);
          ????}

          }
          ???兩種實現方式:
          public?class?ProxyUse?{
          ????
          public?ProxyUse()?{
          ????}


          ????
          public?void?useProxy1()?throws?SecurityException,?NoSuchMethodException,?InvocationTargetException,
          ????????????IllegalArgumentException,?IllegalAccessException,?InstantiationException?
          {
          ????????FooImpl?obj?
          =?new?FooImpl();
          ????????InvocationHandler?handler?
          =?new?MyInvocationHandler(obj);
          ????????Class?proxyClass?
          =?Proxy.getProxyClass(
          ????????????????Foo.
          class.getClassLoader(),?new?Class[]?{Foo.class});
          ????????Foo?f?
          =?(Foo)?proxyClass.
          ????????????????getConstructor(
          new?Class[]?{InvocationHandler.class}).
          ????????????????newInstance(
          new?Object[]?{handler});
          ????????System.out.println(f.doSomthing());
          ????}

          ????
          ????
          public?void?useProxy2()?throws?SecurityException,?NoSuchMethodException,?InvocationTargetException,
          ????????????IllegalArgumentException,?IllegalAccessException,?InstantiationException?
          {
          ????????FooImpl?obj?
          =?new?FooImpl();
          ????????InvocationHandler?handler?
          =?new?MyInvocationHandler(obj);
          ????????Foo?f?
          =?(Foo)?Proxy.newProxyInstance(
          ????????????Foo.
          class.getClassLoader(),
          ????????????
          new?Class[]?{?Foo.class?},
          ????????????handler
          ????????????);
          ????????System.out.println(f.doSomthing());
          ????}

          ????
          ????
          public?static?void?main(String?[]?args){
          ????????ProxyUse?use
          =new?ProxyUse();
          ????????
          try{
          ????????????use.useProxy1();
          ????????????use.useProxy2();
          ????????}
          catch(Exception?ex){
          ????????????ex.printStackTrace();
          ????????}

          ????}


          }

          看一下java api doc

          static?InvocationHandlergetInvocationHandler(Object?proxy)
          ??????????返回指定代理實例的調用處理程序。
          static?Class<?>getProxyClass(ClassLoader?loader, Class<?>...?interfaces)
          ??????????返回代理類的 java.lang.Class 對象,并向其提供類加載器和接口數組。
          static?booleanisProxyClass(Class<?>?cl)
          ??????????當且僅當指定的類通過 getProxyClass 方法或 newProxyInstance 方法動態生成為代理類時,返回 true。
          static?ObjectnewProxyInstance(ClassLoader?loader, Class<?>[]?interfaces, InvocationHandler?h)
          ??????????返回一個指定接口的代理類實例,該接口可以將方法調用指派到指定的調用處理程序。

          沒時間了,先這樣吧。


          ?

          posted @ 2006-07-26 17:48 dingfirst 閱讀(267) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 丽江市| 蓝田县| 富锦市| 远安县| 普兰店市| 剑阁县| 惠来县| 银川市| 河东区| 邯郸市| 息烽县| 通江县| 忻州市| 康马县| 武陟县| 宣化县| 天峻县| 大悟县| 保亭| 莲花县| 黔南| 巴彦县| 富顺县| 贺兰县| 图们市| 盐津县| 罗城| 辽阳市| 芦山县| 铜川市| 云南省| 陆良县| 安塞县| 定西市| 凯里市| 石门县| 寻乌县| 喀喇沁旗| 方城县| 义乌市| 若羌县|