探索与发现

研究java技术

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  83 随笔 :: 0 文章 :: 109 评论 :: 0 Trackbacks

#

http://www.blogjava.net/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 蜘蛛 阅读(906) | 评论 (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 蜘蛛 阅读(357) | 评论 (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 蜘蛛 阅读(2644) | 评论 (1)编辑 收藏

为他方便大家更快的学习Spring,特整理了第一个实例,
做成了pdf格式,还附带源代码,欢迎下载
开发平台
myeclipse 4.1.1GA
eclipse 3.1.2
你也可以选择其它开发工具,并不影响你阅读此教程.
http://www.blogjava.net/Files/zhaijianhui/spring
入门.rar
posted @ 2006-06-01 01:37 蜘蛛 阅读(1959) | 评论 (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.blogjava.net/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 蜘蛛 阅读(2358) | 评论 (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 蜘蛛 阅读(1177) | 评论 (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 蜘蛛 阅读(817) | 评论 (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 蜘蛛 阅读(2133) | 评论 (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 蜘蛛 阅读(7581) | 评论 (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 蜘蛛 阅读(1530) | 评论 (1)编辑 收藏

仅列出标题
共9页: 上一页 1 2 3 4 5 6 7 8 9 下一页