My Java Blog Park

          2006年9月28日 #

          http學習筆記

          一.HTTP請求:
          HTTP請求分為:
          ? 1).請求行
          ? 2).消息頭
          ? 3).空行
          ? 4).正文

          1.請求行
          ? [方法 URI HTTP版本信息]
          ? 如: GET /index.htm HTTP/1.0

          2.方法(全部大寫):
          ? GET????? 請求URI標識的資源
          ? HEAD???? 請求獲取響應消息頭
          ? PUT????? 請求存儲資源,并用URI作為其標識
          ? POST???? 請求服務器接收信息
          ? CONNECT? ?
          ? TRACE???
          ? DELETE
          ? OPTIONS


          二.HTTP響應:
          ? 1).狀態行
          ? 2).消息頭
          ? 3).空行
          ? 4).正文(資源的內容,比如index.htm文件的文本內容)


          1.狀態行
          ? HTTP版本信息 狀態碼 響應碼描述
          ? 例: HTTP/1.1 200 OK

          2.狀態碼(第一位表示響應的類別)
          ? 1xx:
          ? 2xx:
          ? 3xx:
          ? 4xx:
          ? 5xx:
          HTTP協議狀態碼具體意義
          ?? 100? :? Continue
          ?? 101? :? witchingProtocols
          ?? 200? :? OK
          ?? 201? :? Created
          ?? 202? :? Accepted
          ?? 203? :? Non-AuthoritativeInformation
          ?? 204? :? NoContent
          ?? 205? :? ResetContent
          ?? 206? :? PartialContent
          ?? 300? :? MultipleChoices
          ?? 301? :? MovedPermanently
          ?? 302? :? Found
          ?? 303? :? SeeOther
          ?? 304? :? NotModified
          ?? 305? :? UseProxy
          ?? 307? :? TemporaryRedirect
          ?? 400? :? BadRequest
          ?? 401? :? Unauthorized
          ?? 402? :? PaymentRequired
          ?? 403? :? Forbidden
          ?? 404? :? NotFound
          ?? 405? :? MethodNotAllowed
          ?? 406? :? NotAcceptable
          ?? 407? :? ProxyAuthenticationRequired
          ?? 408? :? RequestTime-out
          ?? 409? :? Conflict
          ?? 410? :? Gone
          ?? 411? :? LengthRequired
          ?? 412? :? PreconditionFailed
          ?? 413? :? RequestEntityTooLarge
          ?? 414? :? Request-URITooLarge
          ?? 415? :? UnsupportedMediaType
          ?? 416? :? Requestedrangenotsatisfiable
          ?? 417? :? ExpectationFailed
          ?? 500? :? InternalServerError
          ?? 501? :? NotImplemented
          ?? 502? :? BadGateway
          ?? 503? :? ServiceUnavailable
          ?? 504? :? GatewayTime-out
          ?? 505? :? HTTPVersionnotsupported

          三.HTTP消息頭:
          1. 普通
          2. 請求頭
          3. 響應頭
          4. 實體頭

          格式:(名字大小寫無關)
          <名字>:<空格><值>

          1.普通頭
          ? .Cache-Control? (HTTP1.1,? HTTP1.0:Pragma)
          ????? 緩存指令:
          ????? 請求時: no-cache,no-store,max-age,max-stale,min-fresh,only-if-cached
          ????? 響應時: public,private,no-cache,no-store,no-transform,must-revalidate,proxy-revalidate,max-age,s-maxage.
          ????? 例: Cache-Control: no-cache
          ? .Date
          ????? 客戶端:在發送正文時要包含Date,
          ????? 服務器:在響應時包含Date.
          ? .Connection
          ? .Pragma(1.0用)

          2. 請求頭
          ? .Accept
          ? .Accept-Charset
          ? .Accept-Encoding
          ? .Accept-Language
          ? .Authorization
          ? .Host(必須的)
          ? .User-agent

          3.響應頭
          ? .Location
          ? .Server
          ? .WWW-Authenticate,要包含在401中.

          4.實體頭
          ? .Content-Encoding
          ? .Content-Language
          ? .Content-Length
          ? .Content-Type
          ? .Last-Modified
          ? .Expires

          ?

          posted @ 2006-09-28 15:53 2195113 閱讀(245) | 評論 (0)編輯 收藏

          2006年8月3日 #

          proxool連接池的配置

          proxool連接池的配置(0.8.3)

          1. 配置文件(xml形式,文件名任意)
          --------------------------------
          <?xml version="1.0"?>
          <!-- the proxool configuration can be embedded within your own application's.
          Anything outside the "proxool" tag is ignored. -->

          <something-else-entirely>
          ? <proxool>
          ??? <alias>mypool</alias>? <!-- add "proxool" before alias -- proxool.alias -->
          ??? <driver-url>jdbc:oracle:thin:@localhost:1521:oradb</driver-url>
          ??? <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
          ??? <driver-properties>
          ????? <property name="user"???? value="username"/>
          ????? <property name="password" value="password"/>
          ??? </driver-properties>
          ?? ?<connection-lifetime>60</connection-lifetime>
          ?? ??? ?<maximum-connection-count>50</maximum-connection-count>
          ?? ?<minimum-connection-count>4</minimum-connection-count>
          ??? <house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
          ? </proxool>
          </something-else-entirely>


          2.web.xml配置
          --------------
          <servlet>
          ??? <servlet-name>ServletConfigurator</servlet-name>
          ??????? <servlet-class>
          ?? ???? org.logicalcobwebs.proxool.configuration.ServletConfigurator
          ??????? </servlet-class>
          ?? ?<init-param>
          ?? ???? <param-name>xmlFile</param-name>
          ?? ???? <param-value>WEB-INF/proxool.xml</param-value>
          ??????? </init-param>
          ??? <load-on-startup>1</load-on-startup>
          </servlet>

          <!-- monitor proxool status -->
          <servlet>
          ??? <servlet-name>Admin</servlet-name>
          ??? <servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
          </servlet>
          <servlet-mapping>
          ??? <servlet-name>Admin</servlet-name>
          ??? <url-pattern>/admin</url-pattern>
          </servlet-mapping>


          3. 程序調用
          Connection conn=null;
          try {
          ??? Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
          ??? conn = DriverManager.getConnection("proxool.mypool"); //add "proxool" before "mypool" in proxool.xml
          }catch(ClassNotFountException e){
          ??? e.printStackTrace();
          }catch(SQLException e) {
          ??? e.printStackTrace();
          }



          posted @ 2006-08-03 14:03 2195113 閱讀(638) | 評論 (0)編輯 收藏

          2006年7月25日 #

          線程同步隨記

          1. wait:
          ?? Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object
          ?? This method should only be called by a thread that is the owner of this object's monitor

          ?? 使當前線程放棄對象鎖(等待?),直到其它線程為該對象調用notify()或notifyAll().
          ?? 這個方法只能被擁有對象鎖(監聽器?)的線程執行。
          ??
          ??
          2. notify,notifyAll
          ?? Wakes up a or all threads that are waiting on this object's monitor.
          ??
          ?? 喚醒正在等待指定對象的鎖的一個或所有線程。

          -- 這樣翻譯也不知是否準確,括號內是按直譯過來的意思。

          3. 四種方式?
          ?? 1.static synchronized method(){}
          ?? 2.sychronized(Class)
          ?? 3.sychronized method(){}
          ?? 4.sychronized() {}

          4.? 書上沒說過的: Spin? Lock (旋轉鎖)

          posted @ 2006-07-25 14:53 2195113 閱讀(182) | 評論 (0)編輯 收藏

          2006年7月19日 #

          動態代理的應用一例

          本例以租房子為例:
          一.說明:
          ?? 動態代理可動態為某個類添加代理,以攔截客戶端的調用,在此基礎上進行額外的處理.
          ?? 目前較流行的AOP技術,就有以動態代理為技術基礎進行實現的.

          ?? 本例中,中介作為房子的動態代理,所有調用房子的方法,必須經過中介類(HouseAgency).

          二.源代碼:
          ?? 1.House接口:

          public interface House {
          ??? public void rent();
          ??? public int getPrice();
          }

          ?? 2.House接口實現類ConcreateHouse:

          public class ConcreteHouse implements House{
          ??? private int price;
          ???
          ??? public ConcreteHouse(int price){
          ??? ??? this.price=price;
          ??? }
          ???
          ??? public void rent(){
          ??? ??? System.out.println("rent ok!");
          ??? }
          ???
          ??? public int getPrice(){
          ??? ??? return price;
          ??? }
          }

          ?? 3.實現InvocationHandler接口的中介類:
          ???
          import java.lang.reflect.*;

          public class HouseAgency implements InvocationHandler {
          ??? private Object house;

          ??? public HouseAgency(Object house){
          ??? ??? this.house=house;
          ??? }
          ???
          ??? public? HouseAgency(){}
          ?? ??
          ??? public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

          ??? ??? Object result=null;
          ??? ??? if("getPrice".equals(method.getName())){
          ??? ??? ??? System.out.println("invoking getPrice() to query rent price.");
          ??? ??? }
          ??? ??? if("rent".equals(method.getName())){
          ??? ??? ??? System.out.println("invoking rent() to rent the house.");
          ??? ??? }
          ??? ??? result=method.invoke(house,args);
          ??? ??? return result;
          ??? }
          }

          ?? 4.客戶端

          import java.lang.reflect.*;

          public class HouseClient{

          ??? public static void main(String[] args){
          ??? ??? ConcreteHouse house1=new ConcreteHouse(400);
          ??? ??? HouseAgency ha=new HouseAgency(house1);
          ??? ??? House house=(House)Proxy.newProxyInstance(house1.getClass().getClassLoader(),
          ??? ??? ??? ??? ????????????????????????????????? house1.getClass().getInterfaces(),ha);
          ??? ???
          ??? ??? int price=house.getPrice();
          ??? ???
          ??? ??? System.out.println("the house rent is : "+price);
          ??? ???
          ??? ??? if(price>300){
          ??? ??? ??? house.rent();
          ??? ??? }
          ??? }
          }

          三:打印結果
          invoking getPrice() to query rent price.
          the house rent is : 400
          invoking rent() to rent the house.
          rent ok!


          posted @ 2006-07-19 16:47 2195113 閱讀(184) | 評論 (0)編輯 收藏

          2006年7月14日 #

          JDOM(1.0)的初次接觸

          JDOM(1.0)的初次接觸

          一.源代碼:

          import org.jdom.Element; //代表元素
          import org.jdom.Attribute; //代表元素的屬性
          import org.jdom.Document; //代表整個XML文檔
          import org.jdom.Comment; //注釋
          import org.jdom.output.XMLOutputter; //輸出
          import org.jdom.output.Format; //輸出的格式
          import java.io.FileWriter; // :)

          public class JDomTest {

          public static void main(String[] args) throws Exception{

          Element root=new Element("人員信息");
          Document document=new Document(root); //建立新XML文檔,并以根元素初始化

          root.addContent(new Comment("新進公司職員")); //建立新元素,并將新元素作為根元素的內容.
          root.setAttribute(new Attribute("單位","XXXX軟件公司"));
          root.addContent(new Element("姓名").addContent("XYZ"));
          root.addContent(new Element("年齡").addContent("23")
          .setAttribute("體形","適中"));
          root.addContent(new Element("性別").addContent("男"));
          root.addContent(new Element("身高").addContent("green"));
          root.addContent(new Element("體重").addContent("75KG"));


          //output
          Format format=Format.getPrettyFormat(); //靜態方法,產生兩個空格的縮進格式
          format.setIndent(" "); //變成四個空格的縮進格式,用四個空格字符作參數
          format.setEncoding("gb2312"); //設置編碼格式

          XMLOutputter out=new XMLOutputter(format);
          out.output(document,System.out); //輸出到控制臺

          FileWriter writer=new FileWriter("./jdomtest.xml");
          out.output(document,writer); //輸出到文件
          }
          }


          二.說明:
          以上代碼根據網上文章所寫,總體感覺JDOM使用起來,比SAX,DOM要順手的多(僅為個人觀點)。

          三.程序輸出

          <?xml version="1.0" encoding="gb2312"?>
          <人員信息 單位="XXXX軟件公司">
          <!--新進公司職員-->
          <姓名>XYZ</姓名>
          <年齡 體形="適中">23</年齡>
          <性別>男</性別>
          <身高>green</身高>
          <體重>75KG</體重>
          </人員信息>



          posted @ 2006-07-14 13:20 2195113 閱讀(370) | 評論 (0)編輯 收藏

          僅列出標題  
          主站蜘蛛池模板: 汾阳市| 乐山市| 镇平县| 离岛区| 陈巴尔虎旗| 济源市| 松原市| 年辖:市辖区| 甘肃省| 顺义区| 义乌市| 璧山县| 夹江县| 太康县| 普宁市| 浮梁县| 南陵县| 海门市| 斗六市| 和硕县| 河源市| 德化县| 云和县| 新竹市| 登封市| 泰兴市| 浪卡子县| 苍山县| 新蔡县| 米林县| 密山市| 潢川县| 临猗县| 株洲市| 麟游县| 盈江县| 无极县| 和林格尔县| 和平县| 财经| 黄大仙区|