探索與發現

          研究java技術

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            83 隨筆 :: 0 文章 :: 109 評論 :: 0 Trackbacks

          #

          http://www.aygfsteel.com/Files/zhaijianhui/ejb插刪改查.rar

          /*
          對表的修改
          */
          public void updateNode(UseInfoDto dto) {
          ??? UseInfo useinfo;
          ?? try {
          ???? System.out.println("===========");
          ??? useinfo=home.findByPrimaryKey(dto.getName());
          ??? useinfo.setPassword(dto.getPassword());
          ??? System.out.println("用戶名"+dto.getName()+"修改后的記錄密碼"+dto.getPassword());
          ?? }
          ?? catch (Exception ex) {
          ???? ex.printStackTrace();
          ???? System.out.println("修改記錄出現異常");
          ?? }
          ? }
          因為name作為主鍵,所以不可能再在這里調用setName("xxxxxw")方法了,,
          否則會產生錯誤:
          javax.ejb.TransactionRolledbackLocalException: EJB Exception: ; nested exception
          ?is: java.lang.IllegalStateException: [EJB:010144]The setXXX method for a primar
          y key field may only be called during ejbCreate.
          java.lang.IllegalStateException: [EJB:010144]The setXXX method for a primary key
          ?field may only be called during ejbCreate.
          想一想有沒有必要修改主鍵的值呢,很顯然是沒有必要的,看看當今的一些應用就知道,電信,銀行這些部門只提供注冊用戶的一般資料驗證,不會允許你去改用戶名的..
          /*
          對表增加一條記錄
          */
          ?public void addNode(UseInfoDto dto) {
          ??? UseInfo useinfo;
          ?try {
          ?? System.out.println("home=========="+home);
          ??? useinfo = home.create(dto.getName());
          ??? //useinfo.setName(dto.getName());
          ??? useinfo.setPassword(dto.getPassword());
          ??? System.out.println("調用 了addNode");
          ??? System.out.println("創建了新記錄為"+dto.getName()+":"+dto.getPassword());
          ?}
          ?catch (CreateException ex) {
          ?? ex.printStackTrace();
          ?? System.out.println("創建遠程接口實例時出異常");

          ?}
          這也和上面的一個道理,因為主鍵字段不允許暴露給客戶setXXX方法,所以我們要創建一個create(主鍵)給客戶調用,這樣我們就可依我上面所做的方式創建一條記錄了,,
          注意在ejbCreate(XXX)方法里要加上一句? setXXX(XXX);否則會報錯的喲
          因為ejbCreate在服務器本地調用所以可以調用setXXX方法.
          ok,祝旅途愉快!

          posted @ 2006-07-14 23:12 蜘蛛 閱讀(925) | 評論 (0)編輯 收藏

          今天還真的是郁悶的了,,在網上終于找到最好的解決辦法
          就是
          在命令行中,依次執行以下命令:

          ftype exefile="%1" %*? ?[包含引號]
          assoc .exe=exefile
          但這樣子,cmd都不認了,,
          這時
          你可以去c:\windows\system32\
          找到cmd.exe
          rename cmd.exe cmd.com
          再運行可以執行了,,可是第二天重啟還是老樣子,,,,

          后來拿出原來備份的注冊表,,導入到現在注冊表里(開始--->運行--->regedit-->然后導入原來的注冊表備份,后來裝的軟件沒有什么影響,只會覆蓋原來的設置),終于ok搞定了...

          posted @ 2006-06-04 00:55 蜘蛛 閱讀(367) | 評論 (0)編輯 收藏

          在讀spring in aciton 時,他用的BeanFactory factory = new XmlBeanFactory(new FileInputStream("hello.xml"));
          可是現在的用的1.2.6版本的構造器(XmlBeanFactory)只能接收Resource接口了,所以調不出來是正常的事情,假設現在有一個文件hello.xml
          讀取方法

          1:ApplicationContext cx=new FileSystemXmlApplicationContext("hello.xml");//指定的路徑去找文件
          2:ApplicationContext factory = new ClassPathXmlApplicationContext("hello.xml");//還會在classpath去找
          3:Resource fa = new FileSystemResource("hello.xml");
          ? ?BeanFactory factory=new XmlBeanFactory(fa);
          4:這個要設制classpath了,麻煩
           ?Resource res = new ClassPathResource("com/springinaction/chapter01/hello/hello.xml");
           ?BeanFactory factory=new XmlBeanFactory(res);
          好了,用了上面那種方法都可以調用getBean("your bean name")了,
          eg:?BeanFactory factory=new XmlBeanFactory(fa);
          ????? hello he=(hello)factory.getBean("hello");
          ????????????? he.getHello();
          posted @ 2006-06-03 11:24 蜘蛛 閱讀(2682) | 評論 (1)編輯 收藏

          為他方便大家更快的學習Spring,特整理了第一個實例,
          做成了pdf格式,還附帶源代碼,歡迎下載
          開發平臺
          myeclipse 4.1.1GA
          eclipse 3.1.2
          你也可以選擇其它開發工具,并不影響你閱讀此教程.
          http://www.aygfsteel.com/Files/zhaijianhui/spring
          入門.rar
          posted @ 2006-06-01 01:37 蜘蛛 閱讀(1977) | 評論 (5)編輯 收藏

          現在感覺sun的netbean5.5,它吸取了eclipse的精華,本來是eclipse的用戶,但到sun公司的網站上下載了netbean的flash教學看了看就被它的易用和eclipse的相似給吸引住了http://www.netbeans.org/files/documents/4/753/netbeans_50.zip
          當然還有更多的ejb3.0開發的flash可以下載,作為學習之用是再好不過了,
          這個是我錄制一個簡單的demo
          http://www.aygfsteel.com/Files/zhaijianhui/netbean5.5ejb.rar
          下載netbean地址:
          http://us1.mirror.netbeans.org/download/5_5/beta/200605090801/netbeans-5_5-beta-windows.exe

          下載jboss地址:
          http://jaist.dl.sourceforge.net/sourceforge/jboss/jboss-4.0.4.GA.zip
          它對ejb3.0支持是最好的,雖現在ejb3.0不斷的完善當中,還收補了不少的bug了,但它那簡單易用還是吸引人去研究它.
          jboss4.04有jar,和zip格式的,建議下載jar安裝上就不要安裝ejb3.0.jar了,
          如下載的是zip格式的話,還不能支持ejb3.0所以還要下載http://nchc.dl.sourceforge.net/sourceforge/jboss/jboss-EJB-3.0_RC7-FD.zip
          看一下它的說明就可以安裝上去的,如果你不知道了話你就下載一個
          EJB3Trail可以當教程用,我現在研究不中..
          現在這個地址我找不到了,你可以到google去搜,如真的找不到請留下email
          下面是2005看到的比較好的中文教程,不過對現在來說,顯得太老了,不過主體看起來還行,起碼比書市里的書看起來要好一些..
          http://edu.uuu.com.tw/data_seminar/doc/Java_20050527_slide.pdf
          http://www.softleader.com.tw/javatwo2005/Java2005-EJB3-jini_FR.pdf
          j2ee1.5最終規范已經確定下來的.其中的ejb3.0規范下載 
          http://192.18.108.235/ECom/EComTicketServlet/BEGINC0098FFB7ED15FBFC205C643AD41C96E/-2147483648/1495423407/1/728570/728534/1495423407/2ts+/westCoastFSEND/ejb-3_0-fr-eval-oth-JSpec/ejb-3_0-fr-eval-oth-JSpec:1/ejb-3_0-fr-spec-ejbcore.pdf
          如果你用netbean5.05的話,還可以用sun自己的服務器
          http://192.18.108.238/ECom/EComTicketServlet/BEGIN2AD2AFC100299F9169C2B71DE5B12318/-2147483648/1496225499/1/725978/725942/1496225499/2ts+/westCoastFSEND/sjsas_pe-9.0-oth-JPR/sjsas_pe-9.0-oth-JPR:3/sjsas_pe-9_0-windows.exe
          最近還看到bea網站上有一篇講解ejb3.0的好文章,建議去看看,有中文和英文的..

          posted @ 2006-05-26 08:45 蜘蛛 閱讀(2368) | 評論 (2)編輯 收藏

          Interviews from JavaOne 2006: Day 1
          http://www.artima.com/lejava/articles/javaone_2006_tue_ideas.html
          Interviews from JavaOne 2006: Day 2
          http://www.artima.com/lejava/articles/javaone_2006_wed_ideas.html
          Interviews from JavaOne 2006: Day 3
          http://www.artima.com/lejava/articles/javaone_2006_thu_ideas.html

          Interviews from JavaOne 2006: Day 4
          http://www.artima.com/lejava/articles/javaone_2006_fri_ideas.html
          posted @ 2006-05-23 21:59 蜘蛛 閱讀(1194) | 評論 (0)編輯 收藏

          1)不使用Validator靜態產生js,直接在客戶端使用js
          <%@ page language="java" pageEncoding="UTF-8"%>

          <%@ taglib uri="/tags/struts-bean" prefix="bean"%>
          <%@ taglib uri="/tags/struts-html" prefix="html"%>
          <html:html>
          <HEAD>
          ?<TITLE>New Account Registration</TITLE>
          <script type="text/javascript">
          function runMyJavascript() {
          alert ("Hello from function");
          }
          function add()
          {
          alert("Hello this add");
          }
          </script>
          </HEAD>
          <BODY BGCOLOR="#FDF5E6">
          <html:form action="/login.do">
          Password : <html:text property="password" /><br>
          <html:button property="butType" value="Edit" onclick ="runMyJavascript()" />??
          <html:button property="addButton" value ="Add" onclick ="add()"/>
          </html:form>
          </BODY>
          </html:html>
          2)
          jstl的一些常用web開源組件(如xtree,樹型菜單等),
          http://www.husted.com/central/Resources/

          posted @ 2006-05-21 13:21 蜘蛛 閱讀(827) | 評論 (1)編輯 收藏

          閱讀struts MailReader文檔筆記:
          MailReader應用程序基于struts 1.2.0開發。
          1:主頁是index.jsp。由于struts的Action不能指定歡迎頁面
          ,而首次會從服務器配置的歡迎列表去查找出相應的頁面返回給用戶,
          那么我們怎么來用struts的actions而不是普通的jsp頁面返回給用戶呢,
          一個解決方案是在一個頁面寫上要轉發到我們的歡迎頁面,代碼:
          <%@ taglib uri="/tags/struts-logic" prefix="logic" %>
          <logic:redirect action="/Welcome"/>
          在相應的struts-config.xml配置文件加上
          <!-- Display welcome page -->
          <action path="/Welcome" forward="/welcome.jsp" />
          但其它頁面還不能保證用戶不能訪問到,我們在應用當中一般會把所有的
          jsp頁面放到WEB-INF目錄下面,然后在struts-config.xml做一下映射就可以了,以保證用戶不能直接訪問到。

          2:<message-resources parameter="org.apache.struts.webapp.example.MessageResources" />
          在同一個struts里面只能有一個默認的存放本地化的消息文本(Resource Bundle)
          那很我們指定多個的時候可以用它的一個屬性key指定
          例如:
          <message-resources parameter="org.apache.struts.webapp.example.AlternateMessageResources" key="alternate" />
          那么我們在頁面用的時候這樣出別
          <bean:message key="key0"/>;
          <bean:message key="key1" bundle="alternate"/>

          3:<html:link>有兩個優點:
          (1)允許在url中以多種方式包含請求。
          (2)當用戶關閉cookie時,會自動重寫url,把sessionid作為請求參數包含在url當中,用于跟蹤用戶的session狀態,而不像servlet,jsp還要
          自己硬編碼實現
          它有幾個重要的屬性:
          *forward:指定全局轉發鏈接(只適用于(flobal-forwards>forward,而不能引用action forward子元素)
          *href:指定完整的url鏈接(<html:link url="http//www.sina.com"/>)
          *page:指定相對于當前網頁的url(<html:link page="/test.do"/>

          4:PlugIn(struts插件)
          在struts-config.xml要加上相應的描述語句
          <plug-in className="org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn">
          ? <set-property property="pathname" value="/WEB-INF/database.xml"/>
          </plug-in>
          其中MemoryDatabaseplugIn是自己開發的一個插件,它必須org.paache.struts.action.PlugIn接口,包含兩個方法init,destroy
          init在struts加載時自動被調用,destroy當應用關閉時調用,可以放一些釋放資源的語句(如關閉數據庫連接的語句等)
          并且這個里面還包含屬性pathname,也要相應的get,set方法,以便在struts框架在加載插件時,會自動調用setPathname()方法,把
          <set-property>子元素的pathname設置成MemoryDatabasePlugIn里對應屬性的值value="/WEB-INF/database.xml"
          還要注意就是<plug-in>必須位于其它配置元素后面,出現多個按順序加載

          5:
          <!-- Process a user logon -->
          <action??? path="/SubmitLogon"
          ????????????????? type="org.apache.struts.webapp.example.LogonAction"
          ????????????????? name="LogonForm"
          ???????????????? scope="request"
          ???????????????? input="logon">
          ?<exception
          ?????????????????? key="expired.password"
          ????????????????? type="org.apache.struts.webapp.example.ExpiredPasswordException"
          ????????????????? path="/ExpiredPassword.do"/>
          ?????? </action>
          scope推薦使用request,當然也可以用session,一個ActionForm只對應一次請求,不要越過request,
          如果我們使用type="org.apache.struts.validator.DynaValidatorForm"
          那么它會自動創建一個ActionForms與之對應
          exception子元素,當一個用戶登錄以后,有可能 "ExpiredPasswordException"(超時) 會拋出.
          ?如果發生了的話 Struts 會捕獲exception 并發送到 "ExpiredPassword" action.

          6:
          自己開發一個定制標記<app:checkLogon/>用戶檢查用戶是否登錄
          package org.apache.struts.webapp.example;
          import ...

          public final class CheckLogonTag extends TagSupport {

          ??? private String name = Constants.USER_KEY;
          ??? private static String LOGIN_PATH = "/Logon.do";
          ??? private String page = LOGIN_PATH;

          ??? public int doStartTag() throws JspException {
          ??? return (SKIP_BODY);
          ??? }

          ??? public int doEndTag() throws JspException {
          ??? ?boolean valid = false;
          ??? ?HttpSession session = pageContext.getSession();
          ??? ?if ((session != null) && (session.getAttribute(name) != null)) {
          ??? ???? valid = true;
          ??????? }
          ??????? if (valid) {
          ??????????? return (EVAL_PAGE);
          ??????? } else {
          ??????????? ModuleConfig config =
          ??????????????? (ModuleConfig) pageContext.getServletContext().getAttribute(
          ??????????????????? org.apache.struts.Globals.MODULE_KEY);

          ??????????????? try {
          ??????????????????? pageContext.forward(config.getPrefix() + page);
          ??????????????? } catch (ServletException e) {
          ??????????????????? throw new JspException(e.toString());
          ??????????????? } catch (IOException e) {
          ??????????????????? throw new JspException(e.toString());
          ??????????????? }

          ??????????? return (SKIP_PAGE);
          ??????? }
          ??? }

          ??? public void release() {
          ??????? super.release();
          ??????? this.name = Constants.USER_KEY;
          ??????? this.page = LOGIN_PATH;
          ??? }
          }
          但如果比較大的應用還是用標準的jaas驗證

          7
          <html:link action="/EditRegistration?action=Edit">
          -------
          ///////////////////////////////////
          <logic:equal
          name="RegistrationForm"
          property="action"
          scope="request"
          value="Edit"
          >
          <app:checkLogon/><!--如果action與Edit相等就執行這里,否則不會執行-->
          </logic:equal>
          1)////
          <logic:present name="test">
          如果在action中設置了test就執行到這兒。如:request.setAttribute("test","test")或session.setAttribute("test","test")
          <bean:write name="test"/>
          </logic:present>

          package org.apache.struts.webapp.example;
          public final class EditSubscriptionAction extends Action
          {

          ??? public EditSubscriptionAction()
          ??? {
          ??????? log = LogFactory.getLog("org.apache.struts.webapp.Example");
          ??? }

          ??? public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
          ??????? throws Exception
          ??? {
          ??????? HttpSession session = request.getSession();
          ??????? String action = request.getParameter("action");
          ??????? if(action == null)
          ??????????? action = "Create";
          ??????? String host = request.getParameter("host");
          ??????? if(log.isDebugEnabled())
          ??????????? log.debug("EditSubscriptionAction:? Processing " + action + " action");
          ??????? User user = (User)session.getAttribute("user");
          ??????? if(subscription == null && !action.equals("Create"))///create
          ??????? {
          ??????????? if(log.isTraceEnabled())
          ??????????????? log.trace(" No subscription for user " + user.getUsername() + " and host " + host);
          ??????????? return mapping.findForward("failure");
          ??????? }
          ??????? else //edit
          ?????? --------------------
          }
          8 MailReader源碼<struts 1.2 webapps下struts-mailreader.war并且包含說明文檔,是每一個初學者和有經驗的,應該要看的文章

          posted @ 2006-05-21 01:33 蜘蛛 閱讀(2146) | 評論 (5)編輯 收藏

          什么是Cookie
          Cookie是一種在客戶端保持HTTP狀態信息的技術,它好比商場發放的優惠卡。顧客在一個商場購物結賬離開時,商場可以決定是否贈送給顧客一張優惠卡,不同顧客的優惠卡上記載的信息可以不同,例如,記載該顧客累計購物的金額和有效期限。顧客可以決定是否接受這張優惠卡,一旦顧客接受了這張優惠卡,那么他在以后每次光顧該商場時,都將攜帶這張優惠卡,商場也將根據這張優惠卡上記載的信息進行一些特殊的事務處理,例如,計算折扣率和累加本次購物金額。Cookie是在瀏覽器訪問WEB服務器的某個資源時,由WEB服務器在HTTP響應消息頭中附帶傳送給瀏覽器的一片數據,WEB服務器傳送給各個客戶端瀏覽器的數據是可以各不相同的。瀏覽器可以決定是否保存這片數據,一旦WEB瀏覽器保存了這片數據,那么它在以后每次訪問該WEB服務器時,都應在HTTP請求頭中將這片數據回傳給WEB服務器。顯然,Cookie最先是由WEB服務器發出的,是否發送Cookie和發送的Cookie的具體內容,完全是由WEB服務器決定的。
          WEB服務器通過在HTTP響應消息中增加Set-Cookie響應頭字段將Cookie信息發送給瀏覽器,瀏覽器則通過在HTTP請求消息中增加Cookie請求頭字段將Cookie回傳給WEB服務器。一個Cookie只能標識一種信息,它至少含有一個標識該信息的名稱(NAME)和設置值(value)。一個WEB站點可以給一個WEB瀏覽器發送多個Cookie,這樣,在WEB瀏覽器和WEB服務器之間就可以使用多個Cookie來傳遞多種信息,例如,用一個Cookie來標識訪問者的姓名,用另外一個Cookie來標識該用戶登錄站點的次數。一個Cookie除了有名稱和設置值外,它還可以有一些其他的附加屬性,例如,Cookie的有效時間。如果設置了Cookie的有效時間,接受它的瀏覽器進程將該Cookie保存在計算機硬盤中,只有該Cookie超出有效時間后才被刪除,這樣的Cookie將被同一臺計算機上啟動的多個瀏覽器進程共享。正如一個顧客可以有多家商場提供的優惠卡一樣,一個WEB瀏覽器也可以存儲多個WEB站點提供的Cookie。為了防止Cookie塞滿客戶機的硬盤,瀏覽器一般只允許存放300個Cookie,每個站點最多存放20個Cookie,每個Cookie的大小限制為4KB。如果沒有設置Cookie的有效時間,接受它的瀏覽器進程只將該Cookie保存在自己的內存空間中,在該瀏覽器進程關閉時,它里面保存的所有Cookie也將隨之消失。
          Cookie實現了一種在瀏覽器和服務器之間產生有狀態會話的方式,它可以把一個瀏覽器訪問的同一個服務器上的所有程序貫連起來,在這些程序之間傳遞數據。例如,當用戶使用瀏覽器訪問某個網站的登錄程序進行登錄后,無論這個瀏覽器再訪問該網站的哪個程序,其他程序都能知道訪問者的身份信息,這是在WEB站點中非常普遍的一個應用。這種應用通常就是采用Cookie技術來實現的,當WEB服務器程序驗證登錄請求中的用戶名和密碼后,產生一個標識該用戶身份的標識號,然后在響應消息中將該標識號以Cookie的形式傳遞給瀏覽器,瀏覽器在以后每次訪問該WEB服務器時,都自動在請求消息頭中將標識號又以Cookie的形式返回給WEB服務器,憑借瀏覽器返回的標識號,WEB服務器的其他程序就能分辨出當前請求是由哪個用戶發出的。但是,有一點要注意,不保存在硬盤中的Cookie信息是否可以被同一臺計算機上啟動的多個瀏覽器進程共享,不同的瀏覽器有不同的處理方式。對于IE瀏覽器來說,保存在其中一個瀏覽器進程的內存空間中的Cookie是不能被其他瀏覽器進程共享的,這就會出現同一臺計算機上的每個瀏覽器進程都會與服務器形成各自獨立的會話;而對于Mozilla ?Firefox瀏覽器來說,所有的進程和標簽頁都共享cookie信息。另外,在IE瀏覽器中按Ctrl-N鍵(或者單擊“文件”?;;“新建”?;;“窗口”菜單)打開的窗口或者是用javascript的window.open語句打開的窗口,都會共享原窗口的Cookie信息,因為它們屬于同一個瀏覽器進程內部的多個窗口(出自張孝祥老師的<深入體驗JavaWeb開發內幕>手稿很期待這本書的面世)
          ///
          我們學習了可以用jsp Cookie類來創建cookie,當然其它語言也可以創建包括客戶端腳本語言javascript,vbscript同在我們主要談談用javascript,和html來創建cookie
          1 Creating a Cookie that Is Valid Until a Certain Date
          <HTML>
          <HEAD>
          <TITLE>Creating a cookie that is valid until a certain date</TITLE> <META
          HTTP-EQUIV="Set-Cookie" CONTENT="userId=678;expires=Wednesday, 26-Dec-01 16:00:00 GMT;
          path=/">
          </HEAD>
          <BODY>
          Unless you set your browser to not accept cookies, a cookie called userId with a value of
          678 has been created for you.
          </BODY>
          </HTML>
          /////
          2 Creating Cookies with document.cookiess
          document.cookiess = "cookieName=cookievalue
          ?[; expires=timeInGMTString]
          ?[; path=pathName]
          ?[; domain=domainName]
          ?[; secure]"
          Listing 25.3 Creating a Cookie with document.cookiess
          <HTML>
          <HEAD>
          <TITLE>Creating a cookie with document.cookiess</TITLE>
          <SCRIPT LANGUAGE="javascript">
          document.cookiess="Quantity=7";
          </SCRIPT>
          </HEAD>
          <BODY>
          This page creates a cookie on the client side.
          Make sure that your browser is set to accept cookies.
          </BODY>
          </HTML>
          Creating Cookies with the setCookie Function
          For example, you'll want to create a cookie when your user chooses to buy something in your online store web application
          Listing 25.4 The setCookie Function
          <SCRIPT LANGUAGE="javascript">
          function setCookie(name, value, expires, path, domain, secure) {
          ?document.cookiess = name + "=" + escape(value) +
          ? ?((expires) ? "; expires=" + expires.toGMTString() : "") +
          ? ?((path) ? "; path=" + path : "") +
          ? ?((domain) ? "; domain=" + domain : "") +
          ? ?((secure) ? "; secure" : "");
          }
          </SCRIPT>
          Listing 25.7 An Example that Creates a Cookie with an Expiration Date
          <HTML>
          <HEAD>
          <TITLE>Using the setCookie function</TITLE>
          <SCRIPT LANGUAGE="javascript"> ?
          function setCookie(name, value, expires, path, domain, secure) {
          ?document.cookiess = name + "=" + escape(value) +
          ? ?((expires) ? "; expires=" + expires.toGMTString() : "") +
          ? ?((path) ? "; path=" + path : "") +
          ? ?((domain) ? "; domain=" + domain : "") +
          ? ?((secure) ? "; secure" : "");
          }

          function fixDate(date) {
          ? ?var base = new Date(0);
          ? ?var skew = base.getTime();
          ? ?if (skew > 0) date.setTime(date.getTime() - skew);
          }

          var expiryDate = new Date();
          fixDate(expiryDate);
          expiryDate.setTime(expiryDate.getTime() + 365 * 24 * 60 * 60 * 1000);
          setCookie("authorizationLevel", 2, expiryDate);

          </SCRIPT>
          </HEAD>
          <BODY>
          A cookie which is valid for a year has been created for this page.
          </BODY>
          </HTML>
          Listing 25.9 Writing and Reading Cookies
          <HTML>
          <HEAD>
          <TITLE>Writing and Reading Cookies</TITLE>
          <SCRIPT LANGUAGE="javascript">

          function setCookie(name, value, expires, path, domain, secure) {
          ?document.cookiess = name + "=" + escape(value) +
          ? ?((expires) ? "; expires=" + expires.toGMTString() : "") +
          ? ?((path) ? "; path=" + path : "") +
          ? ?((domain) ? "; domain=" + domain : "") +
          ? ?((secure) ? "; secure" : "");
          }

          function getCookie(name) {
          ?var cName = name + "=";
          ?var dc = document.cookiess;
          ?if (dc.length>0) {
          ? ?begin = dc.indexOf(cName);
          ? ?if (begin != -1) {
          ? ? ?begin += cName.length;
          ? ? ?end = dc.indexOf(";", begin);
          ? ? ?if (end == -1) end = dc.length;
          ? ? ? ?return unescape(dc.substring(begin,end));
          ? ?}
          ?}
          ?return null;
          }

          </SCRIPT>
          </HEAD>
          <BODY>
          Type in your user id, and then click the Create Cookie button.
          A cookie will be created for you.
          <BR>
          <FORM>
          User ID: <INPUT TYPE=TEXT NAME=UserID>
          <BR>
          <INPUT TYPE=BUTTON value="Create Cookie"
          onClick='setCookie("UserID", document.FORMs[0].UserID.value)'>
          <BR>
          Click the Read Cookie button to display the cookie.
          <INPUT TYPE=BUTTON value="Read Cookie"
          onClick='alert(getCookie("UserID"))'>
          </FORM>
          </BODY>
          </HTML>
          Listing 25.10 Deleting a Cookie
          <SCRIPT LANGUAGE="javascript">
          function deleteCookie (name, path, domain) {
          ?if (getCookie(name)) {
          ? ?document.cookiess = name + "=" +
          ? ?((path==null) ? "" : "; path=" + path) +
          ? ?((domain==null) ? "" : "; domain=" + domain) +
          ? ?"; expires=Thu, 01-Jan-70 00:00:01 GMT";
          ?}
          }

          function getCookie(name) {
          ?var cName = name + "=";
          ?var dc = document.cookiess;
          ?if (dc.length>0) {
          ? ?begin = dc.indexOf(cName);
          ? ?if (begin != -1) {
          ? ? ?begin += cName.length;
          ? ? ?end = dc.indexOf(";", begin);
          ? ? ?if (end == -1) end = dc.length;
          ? ? ? ?return unescape(dc.substring(begin,end));
          ? ?}
          ?}
          ?return null;
          }
          </SCRIPT>
          Checking If the Browser Can Accept Cookies Using javascript
          用javascript來檢查用戶瀏覽器是否支持cookie技術
          Listing 25.11 Checking If the Browser Can Accept Cookies Using javascript
          <HTML>
          <HEAD>
          <SCRIPT LANGUAGE="javascript">
          document.cookiess="test=OK";

          function getCookie(name) {
          ?var cName = name + "=";
          ?var dc = document.cookiess;
          ?if (dc.length>0) {
          ? ?begin = dc.indexOf(cName);
          ? ?if (begin != -1) {
          ? ? ?begin += cName.length;
          ? ? ?end = dc.indexOf(";", begin);
          ? ? ?if (end == -1) end = dc.length;
          ? ? ? ?return unescape(dc.substring(begin,end));
          ? ?}
          ?}
          ?return null;
          }

          if (getCookie('test')==null)
          ?alert("Please change your browser to accept cookies.");
          else
          ?alert("Browser accepts cookies");

          </SCRIPT>
          </HEAD>

          <BODY>
          The page content
          </BODY>
          </HTML>
          Checking If the Browser Accepts Cookies Without javascript
          不用javascript來檢查用戶瀏覽器是否支持cookie技術!!!
          Another way to check if the browser is willing to accept cookies is by creating a cookie on one page and then immediately redirecting the user to a second page. In the second page you can then try to read the cookies. The code in Listing 25.12 uses the <META> tag to create a cookie called "test" and then redirects the browser to a second page called checkCookie.jsp (in Listing 25.13).
          Listing 25.12 Checking Browser Cookie Acceptance with Redirection
          <HTML>
          <HEAD>
          <META HTTP-EQUIV="Set-Cookie" CONTENT="test=ok;">
          <META HTTP-EQUIV="Refresh" CONTENT="0;URL=checkCookie.jsp">
          </HEAD>
          </HTML>
          In the second page, implemented using ASP in this example, you try to read the same cookie using the code in Listing 25.13.
          Listing 25.13 Reading the Cookies in the Browser Cookie Acceptance Test
          <%
          ?If Request.cookiesss("test") <> "" Then
          ? ?Response.Write "Cookies accepted."
          ?Else
          ? ?Response.Write "Cookies not accepted."
          ?End If
          %>
          Even though the code in this example only sends a message to the user telling him or her whether or not his or her browser accepts cookies, you can modify it to suit your needs. For instance, you can transfer the user to a warning page if the cookies are not accepted.
          了解一個cookie文件里面的內容的含義!!!!!!!
          3.5 What are all those entries in my cookies.txt file?

          The layout of Netscape's cookies.txt file is such that each line contains one name-value pair. An example cookies.txt file may have an entry that looks like this:
          .netscape.com ? ? TRUE ? / ?FALSE ?946684799 ? NETSCAPE_ID ?100103
          Each line represents a single piece of stored inFORMation. A tab is inserted between each of the fields.

          From left-to-right, here is what each field represents:

          domain - The domain that created AND that can read the variable.
          flag - A TRUE/FALSE value indicating if all machines within a given domain can access the variable. This value is set automatically by the browser, depending on the value you set for domain.
          path - The path within the domain that the variable is valid for.
          secure - A TRUE/FALSE value indicating if a secure connection with the domain is needed to access the variable.
          expiration - The UNIX time that the variable will expire on. UNIX time is defined as the number of seconds since Jan 1, 1970 00:00:00 GMT.
          name - The name of the variable.
          value - The value of the variable.
          好現在還看看其它方面的,有趣的一面!
          在window當中cookie一般存放在C:\Documents and Settings\wwwfox\Cookies
          wwwfox為我登錄xp的賬號,當然由于ie版本不同存放的位置也有所不同,你可以到微軟官方網站上去查看,當然最好的方法就是搜一下Cookie文件就可以知道具體在存放在那里了,
          下面是Cookies下面的一個Cookie文件wwwfox@cgi-bin.txt內容是:
          advpost
          0
          219.239.245.203/cgi-bin/
          1536
          1276665728
          29789832
          2326352352
          29783688
          對應方法
          advpost--->cookie
          .getName
          0--->cookie
          .getvalue()
          1536-->cookie
          .getMaxAge()如返回為-1表示關閉瀏覽器cookie就失效
          ? 后面就是創建日期,失效日期
          ? 創建時間,失效時間
          現在教你怎么用jsp編程查看上網時網站給你創建的cookie文件,
          問題一.cookiess只能由它創建的網站訪問,那么我們怎么能夠在自己的電腦是運行自己的服務器查看出來呢,如果能成那就是cookie欺騙。侵入別人網站的根源。
          好通過示例來演示:, wwwfox@csdn[2].txt當然它的命名是
          你的用戶電腦帳號@產生的COOKIE的網頁文件所在的WEB目錄[COOKIE改變的次數].txt
          wwwfox電腦帳號在訪問csdn網站時是不會發送到csdn網站上去的,也就是只能在我的電腦wwwfox帳號上使用這個cookie其人(帳號)是不能用的。。
          在C:\Documents and Settings\wwwfox\Cookies下我有一個登錄csdn網站時由它創建的cookie
          wwwfox@csdn[2].txt的內容是:
          ABCDEF
          hbWhkUhCWfRTUyeAVO5k79qTBFZXtGV2qfwAROv%252fvVk9qF3rfkcZQbl1IdMsBxhy15Y%252fqwN2XiLyTy%252fDGuW4LY7zZll16huuVbnJ0CEun26I%252f2bynXLPd2Ymq%252bn2Mt11pSP5w3%252fZNXt9ZJEp79VMCw%253d%253d
          csdn.net/
          1536
          3743055744
          29786511
          2555961280
          29783695
          ////////////////////////////
          在C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\test新建一個文件checkCookie.jsp
          <%@page pageEncoding="gb2312" %>
          <%
          Cookie[] cookie=request.getCookies();
          out.println("this is
          www.csdn.net/<br>");
          out.println("<br>");
          for(int i=0;i<cookie.length;i++)
          {
          if(cookie
          .getName().equals("ABCDEF"))
          {
          String name=cookie
          .getName();
          String value=cookie
          .getvalue();
          int maxage=cookie
          .getMaxAge();
          out.println("name="+cookie
          .getName()+"<br>");
          out.println("value="+cookie
          .getvalue()+"<br>");
          out.println("maxage="+cookie
          .getMaxAge()+"<br>");
          //out.println("setMaxAge為30");
          //cookie
          .setMaxAge(30);
          //out.println("之后為maxage="+cookie
          .getMaxAge()+"<br>");
          out.println("domain="+cookie
          .getDomain()+"<br>");
          out.println("secure="+cookie
          .getSecure()+"<br>");
          out.println("path="+cookie
          .getPath()+"<br>");
          }
          }
          %>
          好現在訪問一下
          http://localhost:8080/test/checkCookie.jsp是不是顯示:
          this is
          www.csdn.net
          而沒有取到值:因為只能在它的domain下能訪問到這個cookie
          好現在我們來
          把C:\WINDOWS\SYSTEM32\DRIVERS\etc下面的hosts.sam打開修改其中的
          127.0.0.1 ?hostname
          為127.0.0.1 ? ? ?
          www.csdn.net
          在這里你還可以再添加多行和上面相訪的鍵值對,這個比外網的dsn優先級高所以它先把www.csdn.net解釋成本地的127.0.0.1所以你就可以由這個訪問了,這也可以解釋為什么我們可以在ie敲http://localhsot的原因,這里localhost你可隨便改成你喜歡的名稱.
          保存
          修改conf/servlet.xml當中的端口為80端口
          <Connector port="80" maxHttpHeaderSize="8192"
          ? ? ? ? ? ? ? maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
          ? ? ? ? ? ? ? enableLookups="false" redirectPort="8443" acceptCount="100"
          ? ? ? ? ? ? ? connectionTimeout="20000" disableUploadTimeout="true" />
          好現在啟動tomcat訪問http://www.csdn.net/test/checkCookie.jsp
          得到結果啦:
          this is
          www.csdn.net

          name=ABCDEF
          value=hbWhkUhCWfRTUyeAVO5k79qTBFZXtGV2qfwAROv%252fvVk9qF3rfkcZQbl1IdMsBxhy15Y%252fqwN2XiLyTy%252fDGuW4LY7zZll16huuVbnJ0CEun26I%252f2bynXLPd2Ymq%252bn2Mt11pSP5w3%252fZNXt9ZJEp79VMCw%253d%253d
          maxage=-1
          domain=null
          secure=false#一般為默認值false不然為true就表示在像ssl驗證時才能訪問些cookie
          path=null
          由于在本機不能創建cookie所以不能演示修改cookie值給大家看.
          達內的論壇cookie
          存放用戶名和密碼沒有經過加密的如
          amembernamecookie
          javazhai#這里是我的用戶名
          219.239.245.203/cgi-bin/
          1536
          2476861952
          29789838
          3517958576
          29783694
          *
          apasswordcookies
          xxxxxx#這里是我的密碼
          219.239.245.203/cgi-bin/
          1536
          2476861952
          29789838
          3517958576
          29783694
          而csdn是經過加密方式存儲的如
          ABCDEF
          hbWhkUhCWfRTUyeAVO5k79qTBFZXtGV2qfwAROv%252fvVk9qF3rfkcZQbl1IdMsBxhy15Y%252fqwN2XiLyTy%252fDGuW4LY7zZll16huuVbnJ0CEun26I%252f2bynXLPd2Ymq%252bn2Mt11pSP5w3%252fZNXt9ZJEp79VMCw%253d%253d
          這一串肯定包含了用戶名和密碼的,它經過某種方式取得原始用戶名和密碼

          posted @ 2006-05-19 08:42 蜘蛛 閱讀(7594) | 評論 (5)編輯 收藏

          ?MySQL Connector/J下載地址
          http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.1.12.zip/
          主要新增功能是:
          The driver now also supports "streaming" result sets, which allows users to retrieve large numbers of rows without using a large memory buffer. With newly added large-packet protocol support, the driver can send rows and BLOBs up to 2 gigabytes in size.

          New features from the JDBC-3.0 API in the latest production version of MySQL Connector/J include getGeneratedKeys which allows users to retrieve auto-increment fields in a non-database-specific way. Auto-increment fields now work with object-relational mapping tools, as well as Enterprise Java Beans (EJB) servers with Container Managed Persistence (CMP) that support JDBC-3.0.

          The development version is being refactored to support new features in conjunction with version 4.1 of the MySQL database server, including server-side prepared statements and improved handling of multiple simultaneous character sets, including Unicode in the UCS2 and UTF8 encodings.

          Retrieval of Auto Generated Keys:
          主要針對自動增長類型的數據取值的問題:
          比如我們插入一條數據:
          像原來jdbc2.0時我們這樣干的:
          Int rowcount = stmt.executeUpdate (
          "insert into LocalGeniusList (name) values ('Karen')"); // insert row
          
          // now get the disk address – rowid – for the newly inserted row
          ResultSet rs = stmt.executeQuery (
          
          "select rowid from LocalGeniusList where name = 'Karen'");
          jdbc3.0時我們可以在插入一條記錄時同時得到行數,
          還可以訪問到自動增長的數據如:
          Int rowcount = stmt.executeUpdate (
          
          "insert into LocalGeniusList (name) values ('Karen'),
          Statement.RETURN_GENERATED_KEYS); // insert row AND return key
          
          ResultSet rs = stmt.getGeneratedKeys (); // key is automatically available
          而有些數據庫不支持自動增長類型的數據,jdbc3.0也給出相應的支持:
          // insert the row and specify that you want the employee ID returned as the key Int rowcount = stmt.executeUpdate ( "insert into LocalGeniusList (name) values ('Karen'), "employeeID");
          ResultSet rs = stmt.getGeneratedKeys (); // Karen's employeeID value is now available
          要想了解更多的jdbc3.0可以參考下面的網站:
          http://www.datadirect.com/developer/jdbc/topics/jdbc30/index.ssp
          http://www-128.ibm.com/developerworks/java/library/j-jdbcnew/
          http://www.onjava.com/pub/a/onjava/synd/2001/08/21/jdbc.html?page=3
          jdbc4.0參考網站
          http://www.theserverside.com/news/thread.tss?thread_id=34465
          http://weblogs.java.net/blog/lancea/archive/2006/05/jdbc_40_sqlxml.html
          http://java.sys-con.com/read/111252.htm
          下載jdbc4.0規范
          http://192.18.108.135/ECom/EComTicketServlet/BEGIN747810F695946413098EEF45230B1F12/-2147483648/1488530847/1/686798/686786/1488530847/2ts+/westCoastFSEND/jdbc-4.0-pr-spec-oth-JSpec/jdbc-4.0-pr-spec-oth-JSpec:2/jdbc4.0-pd-spec.pdf
          posted @ 2006-05-19 08:33 蜘蛛 閱讀(1545) | 評論 (1)編輯 收藏

          僅列出標題
          共9頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 
          主站蜘蛛池模板: 客服| 临夏市| 绥棱县| 渝北区| 屏东市| 克什克腾旗| 枝江市| 宜都市| 威远县| 南投市| 镇远县| 马边| 金湖县| 潢川县| 静安区| 滦南县| 吐鲁番市| 哈密市| 长治市| 应用必备| 红桥区| 西昌市| 乌拉特中旗| 商丘市| 常山县| 大埔区| 民丰县| 平原县| 娱乐| 广昌县| 腾冲县| 辽宁省| 贵德县| 濮阳市| 玛多县| 武功县| 搜索| 克山县| 滨海县| 乌兰浩特市| 诸城市|