dingfirst

          On the Road

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

          2006年7月26日 #

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

          現(xiàn)在在干啥啊!
          沒有方向,沒有動(dòng)力。
          十年之后會(huì)是什么樣子呢?
          nnd
          郁悶!
          極其郁悶!!!

          改變,
          要改變啊!!

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

          問題:
          ??????直接用URLEncoder.encode(fileName,"UTF-8"),得到的文件名長度會(huì)被截?cái)唷?br />
          解決方法是:
          ??????文件名先用“GB2312”編碼,然后用“ISO8859_1”解碼。當(dāng)然也可以在將文件名保存到數(shù)據(jù)庫之前用“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 閱讀(1178) | 評論 (0)編輯 收藏

          先看一下Proxy的兩種用法:

          public ? interface ?Foo? {
          ????
          int ?doSomthing();
          }
          ???一個(gè)基本的實(shí)現(xiàn):
          public?class?FooImpl?implements?Foo?{
          ????
          public?FooImpl()?{
          ????}


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

          ????
          }
          ???調(diào)用處理類,這也是aop的一種實(shí)現(xiàn)方式,呵呵。
          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);
          ????}

          }
          ???兩種實(shí)現(xiàn)方式:
          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)
          ??????????返回指定代理實(shí)例的調(diào)用處理程序。
          static?Class<?>getProxyClass(ClassLoader?loader, Class<?>...?interfaces)
          ??????????返回代理類的 java.lang.Class 對象,并向其提供類加載器和接口數(shù)組。
          static?booleanisProxyClass(Class<?>?cl)
          ??????????當(dāng)且僅當(dāng)指定的類通過 getProxyClass 方法或 newProxyInstance 方法動(dòng)態(tài)生成為代理類時(shí),返回 true。
          static?ObjectnewProxyInstance(ClassLoader?loader, Class<?>[]?interfaces, InvocationHandler?h)
          ??????????返回一個(gè)指定接口的代理類實(shí)例,該接口可以將方法調(diào)用指派到指定的調(diào)用處理程序。

          沒時(shí)間了,先這樣吧。


          ?

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

          主站蜘蛛池模板: 洛南县| 周至县| 交口县| 台州市| 崇阳县| 许昌市| 南城县| 厦门市| 三都| 泸州市| 宝山区| 商洛市| 隆尧县| 石泉县| 咸丰县| 伊吾县| 本溪市| 淮滨县| 札达县| 河北区| 建平县| 邻水| 水城县| 吉木萨尔县| 原平市| 阿城市| 肇源县| 信丰县| 寿宁县| 玛曲县| 务川| 德阳市| 乌拉特前旗| 嘉定区| 阜康市| 九寨沟县| 绥芬河市| 克拉玛依市| 玉环县| 营山县| 康保县|