亚洲综合久久夜AV ,国产AV日韩A∨亚洲AV电影,国产亚洲精品AA片在线观看不加载http://www.tkk7.com/liudawei/category/39773.html暢想的天空zh-cnTue, 05 Aug 2014 04:11:29 GMTTue, 05 Aug 2014 04:11:29 GMT60java發(fā)送http的get、post請(qǐng)求http://www.tkk7.com/liudawei/articles/416574.html孤飛燕孤飛燕Tue, 05 Aug 2014 02:59:00 GMThttp://www.tkk7.com/liudawei/articles/416574.htmlhttp://www.tkk7.com/liudawei/comments/416574.htmlhttp://www.tkk7.com/liudawei/articles/416574.html#Feedback0http://www.tkk7.com/liudawei/comments/commentRss/416574.htmlhttp://www.tkk7.com/liudawei/services/trackbacks/416574.htmlpackage wzh.Http;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
public class HttpRequest {
    /**
     * 向指定URL發(fā)送GET方法的請(qǐng)求
     * 
     * @param url
     *            發(fā)送請(qǐng)求的URL
     * @param param
     *            請(qǐng)求參數(shù),請(qǐng)求參數(shù)應(yīng)該是 name1=value1&name2=value2 的形式。
     * @return URL 所代表遠(yuǎn)程資源的響應(yīng)結(jié)果
     */
    public static String sendGet(String url, String param) {
        String result = "";
        BufferedReader in = null;
        try {
            String urlNameString = url + "?" + param;
            URL realUrl = new URL(urlNameString);
            // 打開和URL之間的連接
            URLConnection connection = realUrl.openConnection();
            // 設(shè)置通用的請(qǐng)求屬性
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 建立實(shí)際的連接
            connection.connect();
            // 獲取所有響應(yīng)頭字段
            Map<String, List<String>> map = connection.getHeaderFields();
            // 遍歷所有的響應(yīng)頭字段
            for (String key : map.keySet()) {
                System.out.println(key + "--->" + map.get(key));
            }
            // 定義 BufferedReader輸入流來讀取URL的響應(yīng)
            in = new BufferedReader(new InputStreamReader(
                    connection.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("發(fā)送GET請(qǐng)求出現(xiàn)異常!" + e);
            e.printStackTrace();
        }
        // 使用finally塊來關(guān)閉輸入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }
    /**
     * 向指定 URL 發(fā)送POST方法的請(qǐng)求
     * 
     * @param url
     *            發(fā)送請(qǐng)求的 URL
     * @param param
     *            請(qǐng)求參數(shù),請(qǐng)求參數(shù)應(yīng)該是 name1=value1&name2=value2 的形式。
     * @return 所代表遠(yuǎn)程資源的響應(yīng)結(jié)果
     */
    public static String sendPost(String url, String param) {
        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        try {
            URL realUrl = new URL(url);
            // 打開和URL之間的連接
            URLConnection conn = realUrl.openConnection();
            // 設(shè)置通用的請(qǐng)求屬性
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 發(fā)送POST請(qǐng)求必須設(shè)置如下兩行
            conn.setDoOutput(true);
            conn.setDoInput(true);
            // 獲取URLConnection對(duì)象對(duì)應(yīng)的輸出流
            out = new PrintWriter(conn.getOutputStream());
            // 發(fā)送請(qǐng)求參數(shù)
            out.print(param);
            // flush輸出流的緩沖
            out.flush();
            // 定義BufferedReader輸入流來讀取URL的響應(yīng)
            in = new BufferedReader(
                    new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("發(fā)送 POST 請(qǐng)求出現(xiàn)異常!"+e);
            e.printStackTrace();
        }
        //使用finally塊來關(guān)閉輸出流、輸入流
        finally{
            try{
                if(out!=null){
                    out.close();
                }
                if(in!=null){
                    in.close();
                }
            }
            catch(IOException ex){
                ex.printStackTrace();
            }
        }
        return result;
    }    
}

public static void main(String[] args) {
        //發(fā)送 GET 請(qǐng)求
        String s=HttpRequest.sendGet("http://localhost:6144/Home/RequestString", "key=123&v=456");
        System.out.println(s);
        
        //發(fā)送 POST 請(qǐng)求
        String sr=HttpRequest.sendPost("http://localhost:6144/Home/RequestPostString", "key=123&v=456");
        System.out.println(sr);
    }



孤飛燕 2014-08-05 10:59 發(fā)表評(píng)論
]]>
Java時(shí)區(qū)的轉(zhuǎn)換http://www.tkk7.com/liudawei/articles/387891.html孤飛燕孤飛燕Mon, 17 Sep 2012 06:15:00 GMThttp://www.tkk7.com/liudawei/articles/387891.htmlhttp://www.tkk7.com/liudawei/comments/387891.htmlhttp://www.tkk7.com/liudawei/articles/387891.html#Feedback0http://www.tkk7.com/liudawei/comments/commentRss/387891.htmlhttp://www.tkk7.com/liudawei/services/trackbacks/387891.htmlJava時(shí)區(qū)的轉(zhuǎn)換
邏輯如下:
    
1.明確你要轉(zhuǎn)的當(dāng)前時(shí)間所在的時(shí)區(qū)

2.明確你要轉(zhuǎn)向時(shí)間所在的時(shí)區(qū)

3.獲取當(dāng)前時(shí)間所在時(shí)區(qū)相對(duì)GMT的偏移量

4.當(dāng)前時(shí)間-相對(duì)GMT的偏移量來獲得當(dāng)前時(shí)間的GMT的值

5.GMT的值+轉(zhuǎn)向時(shí)區(qū)相對(duì)GMT的偏移量獲取轉(zhuǎn)向時(shí)區(qū)的時(shí)間值

例如:你要從GMT+8時(shí)間轉(zhuǎn)向GMT+7時(shí)間
sourceTimeZone 為GMT+8

targetTimeZone為GMT+7

/**
 *
 */
package test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;


public class DateTimeUtil {
 
 static String DEFAULT_TIMEZONE = "GMT+8";
 static String DEFAULT_FORMAT = "d-MMM-yyyy HH:mm (z)";

 /**
  * 轉(zhuǎn)換時(shí)間時(shí)區(qū)
  * @param convertString  需要轉(zhuǎn)的時(shí)間字符串
  * @param format  格式話字符串 例如d-MMM-yyyy HH:mm (z)
  * @param sourceTimeZone 源時(shí)間時(shí)區(qū)
  * @param targetTimeZone 目標(biāo)時(shí)間時(shí)區(qū)
  * @return
  * @throws ParseException
  */
 public static Date ConverDateGMT(String convertString,String format,String sourceTimeZone,String targetTimeZone) throws ParseException
 {
  
  Date date=null;
  

  if(isEmpty(sourceTimeZone)){
   sourceTimeZone = DEFAULT_TIMEZONE;
  }
  
  if(isEmpty(targetTimeZone)){
   targetTimeZone = DEFAULT_TIMEZONE;
  }
  
  if(isEmpty(format)){
   format = DEFAULT_FORMAT;
  }
  
  
  
  SimpleDateFormat sdf = new SimpleDateFormat(format);
  
  //獲取傳入的時(shí)間值
  Long time = new Date(sdf.parse(convertString).getTime()).getTime();
  
  
  //獲取源時(shí)區(qū)時(shí)間相對(duì)的GMT時(shí)間
  Long sourceRelativelyGMT=time-TimeZone.getTimeZone(sourceTimeZone).getRawOffset();
  
  //GMT時(shí)間+目標(biāo)時(shí)間時(shí)區(qū)的偏移量獲取目標(biāo)時(shí)間
  Long targetTime=sourceRelativelyGMT+TimeZone.getTimeZone(targetTimeZone).getRawOffset();
  
  
  date= new Date(targetTime);
  
  return date;
  
 }
 
 
 /**
  * Check empty string
  * <pre>
  *   null: true
  *   "": true
  *   " ":true
  * </>
  *
  * @param value
  * @return
  */
 public static boolean isEmpty(String value) {
  boolean emptyFlg = false;
  if (null == value || value.trim().length() <= 0) {
   emptyFlg = true;
  }
  return emptyFlg;
 }
}
 
 





孤飛燕 2012-09-17 14:15 發(fā)表評(píng)論
]]>
java 頁面url傳值中文編碼&解碼http://www.tkk7.com/liudawei/articles/349990.html孤飛燕孤飛燕Wed, 11 May 2011 02:05:00 GMThttp://www.tkk7.com/liudawei/articles/349990.htmlhttp://www.tkk7.com/liudawei/comments/349990.htmlhttp://www.tkk7.com/liudawei/articles/349990.html#Feedback0http://www.tkk7.com/liudawei/comments/commentRss/349990.htmlhttp://www.tkk7.com/liudawei/services/trackbacks/349990.htmlURL參數(shù)中有中文值,傳到服務(wù)端,在用request.getParameter()方法,得到的常常會(huì)是亂碼。

這將涉及到字符解碼操作,我們?cè)趹?yīng)用中常常會(huì)用new String(fieldType.getBytes("iso-8859-1"), "UTF-8");等類似的方法去解碼。但這種方式受具體應(yīng)用環(huán)境限制,往往在應(yīng)用部署環(huán)境發(fā)生改變時(shí),還會(huì)出現(xiàn)中文亂碼。

在這里介紹一種解決方法,可以在任何應(yīng)用部署環(huán)境下通用。此方法分兩步:

1、在客戶端用escape(encodeURIComponent(fieldValue))方法編碼,例如:

title=escape(encodeURIComponent(title)); //這是js里的函數(shù)

 url="<%=request.getContextPath()%>/print/printList!printTable.action?title="+title;

2、在服務(wù)端用java.net.URLDecoder.decode(getRequest().getParameter("title"),"UTF-8"),進(jìn)行解碼。

 

-----------------------------------------------------------------------------

parent.window.location.href 和 iframe中src的亂碼問題。

要在這兩個(gè)url地址中傳中文,必須加編碼,然后再解碼。

編碼:encodeURI(encodeURI("包含中文的串"))

解碼:java.net.URLDecoder.decode("需要解碼的串","utf-8");

 

encodeURI方法是正確的,只是需要使用兩次encodeURI方法,例如encodeURI(encodeURI("中文"));第一次是把中文編碼成%xy的格式,第二次是對(duì)%xy中的%進(jìn)行編碼,%編碼成%25。整個(gè)傳參過程大體應(yīng)該是:提交頁面使用encodeURI(encodeURI("中文"))編碼,把最后的編碼結(jié)果%25xy傳遞給處理頁面的過程中,瀏覽器獲取URL地址(注意openModelDialog方法,瀏覽器獲取不到參數(shù)編碼)后解碼成%xy,然后把%xy傳遞給處理頁面,處理頁面使用URLDecoder.decode(request.getParameter("參數(shù)名"),"UTF-8");完成解碼。
總結(jié):
1、漢字出現(xiàn)在URL路徑部分的時(shí)候不需要編碼解碼;
2、使用encodeURI進(jìn)行2次編碼;
3、在openModelDialog()打開的模式窗體里沒辦法用request.getParameter正確獲取參數(shù);



孤飛燕 2011-05-11 10:05 發(fā)表評(píng)論
]]>
利用Java形成的隨機(jī)抽取http://www.tkk7.com/liudawei/articles/340982.html孤飛燕孤飛燕Fri, 17 Dec 2010 06:45:00 GMThttp://www.tkk7.com/liudawei/articles/340982.htmlhttp://www.tkk7.com/liudawei/comments/340982.htmlhttp://www.tkk7.com/liudawei/articles/340982.html#Feedback0http://www.tkk7.com/liudawei/comments/commentRss/340982.htmlhttp://www.tkk7.com/liudawei/services/trackbacks/340982.html//抽取隨機(jī)數(shù)邏輯方法
   int maxSize = listZxsl.size();//listZxsl 假設(shè)為已經(jīng)得到的list值 想從中隨機(jī)抽取幾個(gè)
   HashSet<Integer> set = new HashSet<Integer>();
   
    int xysl=5;//假設(shè)需要抽取的數(shù)量為5個(gè)
   
   //產(chǎn)生的個(gè)數(shù)
   inttempMaxSize=null;
   if(xysl>maxSize)
   {
    tempMaxSize=maxSize ;
   }
   else
   {
    tempMaxSize=xysl;
   }
   
   
   while (true) {
    //產(chǎn)生的索引值
    int randNumber = (int) (Math.random() * maxSize + 1) - 1;
    set.add(randNumber);
    if (set.size() >= tempMaxSize) {
    break;
    }
   }
   
   for(int number:set)
   {
    templist.add(listZxsl.get(number));//templist為返回出去的
   }



孤飛燕 2010-12-17 14:45 發(fā)表評(píng)論
]]>
C3po連接池http://www.tkk7.com/liudawei/articles/305652.html孤飛燕孤飛燕Fri, 11 Dec 2009 14:33:00 GMThttp://www.tkk7.com/liudawei/articles/305652.htmlhttp://www.tkk7.com/liudawei/comments/305652.htmlhttp://www.tkk7.com/liudawei/articles/305652.html#Feedback0http://www.tkk7.com/liudawei/comments/commentRss/305652.htmlhttp://www.tkk7.com/liudawei/services/trackbacks/305652.htmljdbc.properties配置文件

jdbc.driverClassName=com.ibm.db2.jcc.DB2Driver

#---------------------------------------------------

DEVELOP DATABASE

jdbc.url=jdbc:db2://10.10.0.163:50000/MACRODB

#jdbc.url=jdbc:db2://10.10.0.154:50000/SAMPLE

#---------------------------------------------------

#TEST DATABASE

#jdbc.url=jdbc:oracle:thin:@192.168.1.100:1521:orcl

#---------------------------------------------------

#LOCALHOST DATABASE

#jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl

#jdbc.username=db2inst1

#jdbc.password=db2inst1

jdbc.username=db2inst1

jdbc.password=123456

c3p0.acquireIncrement=3

c3p0.initialPoolSize=3

c3p0.minPoolSize=10

c3p0.maxPoolSize=15

c3p0.maxIdleTime=30

c3p0.idleConnectionTestPeriod=30

c3p0.maxStatements=100

c3p0.numHelperThreads=50

c3p0.checkoutTimeout=0

c3p0.validate=true

讀取配置文件:

package com.nci.macrodb.core.sql;

import java.util.ResourceBundle;

/**

 *取得資源文件

 *

 *@authorldw

 *

 */

publicclass C3P0SystemConfig {

    static String configFile = "spring/jdbc";//根據(jù)具體配置文件名稱配置

    /**

     *根據(jù)屬性名得到資源屬性

     *

     *@paramitemIndex

     *@return

     */

    publicstatic String getConfigInfomation(String itemIndex) {

       try {

           ResourceBundle resource = ResourceBundle.getBundle(configFile);

           return resource.getString(itemIndex);

       } catch (Exception e) {

           return"";

       }

    }

}



獲得連接:

package com.nci.macrodb.core.sql;

import java.sql.Connection;
import java.sql.SQLException;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * 編程調(diào)用c3p0
 *
 * @author xuhua
 *
 */
public class C3P0DBConnectionManager {
 private static ComboPooledDataSource cpds = null;

 /**
  * 初始化
  */
 public static void init() {
  // 建立數(shù)據(jù)庫連接池
  String DRIVER_NAME = C3P0SystemConfig
    .getConfigInfomation("jdbc.driverClassName"); // 驅(qū)動(dòng)器
  String DATABASE_URL = C3P0SystemConfig.getConfigInfomation("jdbc.url"); // 數(shù)據(jù)庫連接url
  String DATABASE_USER = C3P0SystemConfig
    .getConfigInfomation("jdbc.username"); // 數(shù)據(jù)庫用戶名
  String DATABASE_PASSWORD = C3P0SystemConfig
    .getConfigInfomation("jdbc.password"); // 數(shù)據(jù)庫密碼
  int Min_PoolSize = 5;
  int Max_PoolSize = 50;
  int Acquire_Increment = 5;
  int Initial_PoolSize = 10;
  // 每隔3000s測(cè)試連接是否可以正常使用
  int Idle_Test_Period = 3000;
  // 每次連接驗(yàn)證連接是否可用
  String Validate = C3P0SystemConfig.getConfigInfomation("c3p0.validate");
  if (Validate.equals("")) {
   Validate = "false";
  }
  // 最小連接數(shù)
  try {
   Min_PoolSize = Integer.parseInt(C3P0SystemConfig
     .getConfigInfomation("c3p0.minPoolSize"));
  } catch (Exception ex) {
   ex.printStackTrace();
  }
  // 增量條數(shù)
  try {
   Acquire_Increment = Integer.parseInt(C3P0SystemConfig
     .getConfigInfomation("c3p0.acquireIncrement"));
  } catch (Exception ex) {
   ex.printStackTrace();
  }
  // 最大連接數(shù)
  try {
   Max_PoolSize = Integer.parseInt(C3P0SystemConfig
     .getConfigInfomation("c3p0.maxPoolSize"));
  } catch (Exception ex) {
   ex.printStackTrace();
  }
  // 初始化連接數(shù)
  try {
   Initial_PoolSize = Integer.parseInt(C3P0SystemConfig
     .getConfigInfomation("c3p0.initialPoolSize"));
  } catch (Exception ex) {
   ex.printStackTrace();
  }
  // 每隔Idle_Test_Period s測(cè)試連接是否可以正常使用
  try {
   Idle_Test_Period = Integer.parseInt(C3P0SystemConfig
     .getConfigInfomation("c3p0.idleConnectionTestPeriod"));
  } catch (Exception ex) {
   ex.printStackTrace();
  }

  try {
   cpds = new ComboPooledDataSource();
   cpds.setDriverClass(DRIVER_NAME); // 驅(qū)動(dòng)器
   cpds.setJdbcUrl(DATABASE_URL); // 數(shù)據(jù)庫url
   cpds.setUser(DATABASE_USER); // 用戶名
   cpds.setPassword(DATABASE_PASSWORD); // 密碼
   cpds.setInitialPoolSize(Initial_PoolSize); // 初始化連接池大小
   cpds.setMinPoolSize(Min_PoolSize); // 最少連接數(shù)
   cpds.setMaxPoolSize(Max_PoolSize); // 最大連接數(shù)
   cpds.setAcquireIncrement(Acquire_Increment); // 連接數(shù)的增量
   cpds.setIdleConnectionTestPeriod(Idle_Test_Period); // 測(cè)連接有效的時(shí)間間隔
   cpds.setTestConnectionOnCheckout(Boolean.getBoolean(Validate)); // 每次連接驗(yàn)證連接是否可用
  } catch (Exception ex) {
   ex.printStackTrace();
  }
 }

 /**
  * 取得鏈接
  *
  * @return
  */
 public static Connection getConnection() {
  Connection connection = null;
  try {// 保證只進(jìn)行一次初始化
   if (cpds == null) {
    init();
   }
   // 取得connection
   connection = cpds.getConnection();
  } catch (SQLException ex) {
   ex.printStackTrace();
  }
  return connection;
 }

 /**
  * 釋放連接
  */
 public static void release() {
  try {
   if (cpds != null) {
    cpds.close();
   }
  } catch (Exception ex) {
   ex.printStackTrace();
  }
 }

}




孤飛燕 2009-12-11 22:33 發(fā)表評(píng)論
]]>
J2EE路徑的通用解決方案http://www.tkk7.com/liudawei/articles/283657.html孤飛燕孤飛燕Mon, 22 Jun 2009 15:49:00 GMThttp://www.tkk7.com/liudawei/articles/283657.htmlhttp://www.tkk7.com/liudawei/comments/283657.htmlhttp://www.tkk7.com/liudawei/articles/283657.html#Feedback0http://www.tkk7.com/liudawei/comments/commentRss/283657.htmlhttp://www.tkk7.com/liudawei/services/trackbacks/283657.html

Web.xml配置:

<servlet>  

    <servlet-name>MainServlet</servlet-name>  

    <servlet-class>com.wes.controller.MainServlet</servlet-class>  

    <init-param>  

       <param-name>param1</param-name>  

       <param-value>avalible in servlet init()</param-value>  

    </init-param>  

    <load-on-startup>0</load-on-startup>  

</servlet>

 

配置一個(gè)Servlet 名稱為:MainServlet

 

MainServlet

 

    package com.wes.controller;  

 

import javax.servlet.ServletException;  

import javax.servlet.http.HttpServlet;  

 

 public class MainServlet extends HttpServlet{  

 

  

     public void init(){  

 

     

     String webAppRootKey = getServletContext().getRealPath("/");

     

     System.setProperty("webapp.root" , webAppRootKey);

     

       } 

}

 

已經(jīng)配置完畢

這樣可以在java普通類或者其他地方可以System.getProperty("webapp.root"),得到項(xiàng)目的根路徑




孤飛燕 2009-06-22 23:49 發(fā)表評(píng)論
]]>
主站蜘蛛池模板: 亚洲婷婷第一狠人综合精品| 国产高清在线免费视频| 麻豆精品不卡国产免费看| 一级特级女人18毛片免费视频| 亚洲第一成年免费网站| 亚洲高清毛片一区二区| 亚洲成在人线aⅴ免费毛片| 亚洲一区二区无码偷拍 | 波多野结衣中文字幕免费视频| 久久免费公开视频| 亚洲精品免费视频| 最刺激黄a大片免费网站| 国产国产人免费视频成69堂| 24小时在线免费视频| 精品久久久久成人码免费动漫| 一二三四免费观看在线视频中文版| 国产免费不卡v片在线观看| 久久这里只有精品国产免费10| 天天拍拍天天爽免费视频| 精品久久免费视频| 亚洲成A∨人片天堂网无码| 国产亚洲精品资在线| 亚洲第一精品在线视频| 亚洲精品免费在线视频| 国产亚洲sss在线播放| 亚洲AV无码AV吞精久久| 久青草国产免费观看| 十八禁在线观看视频播放免费| 久久久久久久久久国产精品免费| 100部毛片免费全部播放完整| 成年男女免费视频网站| 国产一级一片免费播放i| 亚洲中文字幕在线第六区| 亚洲精品福利视频| 亚洲人成色在线观看| 免费看内射乌克兰女| 成人A片产无码免费视频在线观看| 91人成网站色www免费下载| 妞干网手机免费视频| 国产亚洲成人在线播放va| 99亚洲精品高清一二区|