Float定位问题详解

mikel阅读(605)

不帖了,直接链接吧
http://css-class.com/articles/explorer/floats/floatandcleartest1.htm

CSS的兼容问题

mikel阅读(1089)

在由表格作为架构做网站到DIV架构,这段时间碰到的问题不少,在这里总结一下,以备不时之需.
用DIV+CSS架构网站以来,用到的标签无非就是以下几个:DIV、UL、LI、H1=、SPAN、OL、FORM、LABEL==、A、INPUT。
用到的标签属性也没有多少:width(宽度)、height(高度)、float(浮动)、margin(外边距)、padding(内边距)、 line-height(行间距)、overflow(溢出)、backgroud(背景)、border(边框)、text-align(对齐方式)、 display(显示方式)、flont-family(字体)、font-size(字体大小)、color(字体颜色)、cursor(光标)、 font-weight(字体重量-粗体)、text-indent(文本缩进)、text-style(文字属性-斜体等)、text- decoretion(下划线)、list-style(列表样式)、clear(浮动清除)。
我用过的所有标签和属性也大致这些了,感觉除了定位以外,其它想要得到的样式都不算太难,还可以,连HACK也没用多少。所以在这里只说说定位的问题,包括常用的几个浏览器之间的差异(IE-7、IE-6、FireFox、遨游用的IE的内核、GreenBrowser也一样所以你的操作系统的IE 版本就决定了你的显示状况)
一、Float对定位的影响。
一般说来,DIV是块级元素,与按内容占据空间不同的是,DIV在无任何属性下是占用整行的空间,在一个DIV结束之后,另起一行显示另一些内容。如果不对DIV使用Float属性,放在同一个已经设定宽度的容器内是自动换行显示DIV的,而如果对一个DIV使用FLOAT属性而不设定宽度的话,其后的DIV则会在同一行尾随,直到总宽度达到为止。
符合标准的CSS是需要加FLOAT属性的,不设定的话,在FF下有可能会出现故障。
二、IE-6的双边距BUG。
对两个块张元素的嵌套,如果都使用FLOAT属性,在IE-6下会出现双边距现象,比如明明设置margin-left为5px,在IE-6下会显示10px; 这时需要对被嵌套的块级元素使用display:inline;告知此为内联对象。
图示:
在IE7中

在ie6中
这是样式:

三、ID和CLASS的权重问题。
在初期使用ID和CLASS时,我并不以为然,感觉以为在同一页面没有重复出现可能的元素就用DIV,可以重用的样式则用Class,在后来的一次做划动门时,才真正了解ID权重的真正意义。例如下:
#text1 a{font-size:16px; color:#000; font-weight:normal;}
.text1 a{font-size:12px; color:#FFF; font-weight:bold;}

你会发现,虽然我们遵循了CSS的覆盖原则,以后在后来的链接样式上将会覆盖前面的链接样式,但显示情况完全不是这样,你会发现不论怎么修改,“12号字 Class样式”的链接都会显示前面所定义的样式。而我们是将使用ID的DIV内用的是class的元素。而如果反过来用class嵌套div,则不会出现“覆盖失效”的问题。
问题就在于ID的权位是高于Class的,在拥有不同样式的时候,优先使用ID内的样式。特别是在大的元素使用时,更要注意这一点,要不然你都不知道问题出在哪。
四、块级元素居右问题。
在一个DIV容器内如果同时要放置块级元素和非块级元素(比如说文字)时,会遇到一些小问题,如下:
我们想要的是这种效果:

但得到的却是这种效果(CSS如下):

.test1{width:500px; background: #00CCFF; margin:0 auto; height:500px;}
.test2{float:left;background: #00FF66;}
.test2 span{float:right; width:100px; background: #993366;}
<div class="test1">
<div class="test2">Content for class "test2" Goasd<span>Content for  class "test2span"</span></div>
</div>

为什么会出现这种情况呢,我们试一下如果把放在文字前面:

Content for class “test2span”Content for class “test2” Goasd

那就会得到我们想要的结果了。
不只,所有的块级元素比如说DIV、H1、IMG(图片)如果设置了align为right的话,都会出现这种情况,对于这个问题为什么会出现,我也想知道…
五、清除浮动
对于清除浮动我自己的理解是:对于在FF里包含容器不会随着其中的内容高度改变而改变,对于这块还不太熟悉,只知道如何解决简单的浮动。这种状况在你给包含容器设置背景颜色或边框时会出现,这里需要加入:
overflow:auto; 难道FF默认:overflow:hidden的?也不对,hidden的话里面的内容也不会显示,像clear:both和zoom:1;等不大懂,

Firefox与IE的浏览器兼容性问题

mikel阅读(781)

相对来说,FF对CSS要求更严格一些。对FF来说,一般在属性后加!important就可以了,这样就对FF等浏览器重新定义了。有以下方面,都是从网上找的:
FF(firefox): 设置 padding 后, div 会增加 height 和 width, 但 IE 不会, 故需要用 !important 多设一个 height 和 widthFF: 支持 !important, IE 则忽略, 可用 !important 为 FF 特别设置样式cursor: pointer 可以同时在 IE FF 中显示游标手指状, hand 仅 IE 可以FF: 链接加边框和背景色,需设置 display: block, 同时设置 float: left 保证不换行。
参照 menubar, 给 a 和 menubar 设置高度是为了避免底边显示错位, 若不设 height, 可以在 menubar 中插入一个空格
在firefox和IE中的BOX模型解释不一致导致相差2px解决方法:{margin:30px!important;margin:28px;}注意这两个margin的顺序一定不能写反。
!important这个属性IE不能识别,但别的浏览器可以识别。所以在IE下其实解释成这样:
div{maring:30px;margin:28px}
1、IE与Firefox下对CSS解析的区别
对高度的解析
IE:将根据内容的高度变化,包括未定义高度的图片内容,即使定义了高度,当内容超过高度时,将使用实际高度
Firefox:没有定义高度时,如果内容中包括了图片内容,MF的高度解析是根据印刷标准,这样就会造成和实际内容高度不符合的情况;当定义了高度,但是内容超过高度时,内容会超出定义的高度,但是区域使用的样式不会变化,造成样式错位。
结论:大家在可以确定内容高度的情况下最好定义高度,如果真的没有办法定义高度,最好不用使用边框样式,否则样式肯定会出现混乱!
img对象alt和title的解析
alt:当照片不存在或者load错误时的提示;
title:照片的tip说明。
在IE中如果没有定义title,alt也可以作为img的tip使用,但是在MF中,两者完全按照标准中的定义使用
结论:大家在定义img对象时,最后将alt和title对象都写全,保证在各种浏览器中都能正常使用
其他的细节差别
当你在写css的时候,特别是用float: left(或right)排列一窜图片时,会发现在firefox里面正常而IE里面有问题。无论你用margin:0,还是border: 0来约束,都无济于事。
其实这里还有另外一个问题,就是IE对于空格的处理,firefox是忽略的而IE对于块与块之间的空格是处理的。也就是说一个div结束后要紧接着一个div写,中间不要有回车或者空格。不然也许会有问题,比如3px的偏差,而且这个原因很难发现。
非常不走运的是我又碰到了这样的问题,多个img标签连着,然后定义的float: left,希望这些图片可以连起来。但是结果在firefox里面正常而IE里面显示的每个img都相隔了3px。我把标签之间的空格都删除都没有作用。
后来的解决方法是在img外面套li,并且对li定义margin: 0,这样就解决了IE和firefox的显示偏差。IE对于一些模型的解释会产生很多错误问题,只有多多尝试才能发现原因。
2、嵌套DIV:父DIV的高度不能根据子DIV自动变化的解决方案

当Content内容多时,即使parent设置了高度100%或auto,在不同浏览器下还是不能完好的自动伸展。 解决方案

在层的最下方产生一个高度为1的空格,可解除这个问题
3、CSS DIV
一、基本上每个区块的div 都要有自己的id,杜绝不同功能的区块用同一个id/class
二、每个稍大的区块div 后面都跟一个 标记开始、结束
三、隐藏文字的又一种方法 TEXT-INDENT: -9999px; LINE-HEIGHT: 0
四、巧妙地处理并列的两列:
1)
右列为P, width=44.5%, float=left
左列为P.first, border-right: #a7a7a7 1px solid, width=45%
2)
右列#right, margin-left:50%
左列#left, float=left,width=50% border-right:#a7a7a7 1px solid
以上两种方法关键点在于选择其中一个为float=left
4、关于div的高度自适应
  在一个父级div中嵌套一左一右两个子div,右边的子div内容可无限扩展,而可以使得父级div的高度能被无限拉长,用一般的布局方法,在IE中可以正确浏览,在Mozilla中父级div的高度就固定在10px左右,无法自适应高度,height:auto也不行,怎么办呢。网上参考到一篇资料,要实现自适应高度,div层必须具有float属性,于是我开始动手试验,float:left的话,div就跑到页面最左边去了,这好办,我在它的外面再套一层div,把位置定好,那么里面的就算float:left也不会被移动位置了。
xhtml:

test
test
test

CSS
#container_father {
margin-left: auto;
margin-right: auto;
padding: 0px;
width: 750px;
}
#container {
width: 750px;
border: 1px solid #cccccc;
padding: 8px;
margin: 0px;
background-color: #F1F3F5;
float: left;
}
5、深入标准 ~ The IE Doubled Float-Margin Bug(IE双倍浮动边界Bug)什么发生故障?
一段无错的代码把一个居左浮动(float:left)的元素放置进一个容器盒(box),并在浮动元素上使用了左边界(margin-left)来令它和容器的左边产生一段距离。看起来相当的简单,对吗?但直至它被在IE/Win中浏览为止,在浏览器中居左浮动元素的边界长度被神秘地翻了一倍!
情况应该如何?
下面的图释展示了一个简单的div(茶色的盒子)包含着一个居左浮动的div(绿色的盒子)。浮动元素有一个100px的左边界,使容器盒与它的左边缘之间产生了一个100px的间隙。到现在为止,一直都还不错。
.floatbox {
float: left;
width: 150px;
height: 150px;
margin: 5px 0 5px 100px;
/*This last value applies the 100px left margin */
}
陈旧的IE“双倍占据”
原样的相同代码被在IE/Win中浏览时以些微不同的方式显示,下面的图释展示了IE/Win在布局上所做的。
这为什么会发生?别问这种傻问题!这就是IE,记得吗?符合标准只是理想的状况,不指望实现,这个简单的事实正验证了。
重点
这个Bug仅当浮动边界和浮动元素的方向相同时出现在浮动元素和容器盒的内边缘之间,在这之后的任意有着相似边界的浮动元素不会呈现双倍边界。只有特定的浮动行的第一个浮动元素会遭遇这个Bug。像居左的情况一样,双倍边界同样神秘地显示在居右的相同方式。
最后,修复办法!
直到现在(04年1月)这个Bug一直被认为是无法修复的,通常用来替代错误的边界的控制方法如:一个不可视浮动元素的左边距,连同一个内嵌的盒子一起,可视的盒子装在不可视浮动元素里;或者使用技巧仅对IE/Win设定边界的1/2值。这办法生效了,但是是混乱的而且搞糟了干净的源代码。不过现在全部结束了。
Steve Clason发现了一个修复办法,描述在他的Guest Demo里,修复了双倍边界和围绕文字缩进Bug。这是一个经典的IE的Bug修复办法,使用一个属性来修复影响不相关属性的Bug。
现在如何来做?
研究它,简单地将{display: inline;}设置给浮动元素就是全部所需做的!是的,听起来太简单了,不是吗?不过这是真的,仅仅一个display的”inline”声明已经能够胜任了。
熟悉规则的人知道浮动元素自动设置为”block”元素,而不管他们之前是什么。就如Steve从W3C里指出:
9.5.1 Positioning the float: the ‘float’ property
“This property specifies whether a box should float to the left, right, or not at all. It may be set for elements that generate boxes that are not absolutely positioned. The values of this property have the following meanings:
left
The element generates a block box that is floated to the left. Content flows on the right side of the box, starting at the top (subject to the ‘clear’ property). The ‘display’ is ignored, unless it has the value ‘none’.
right
Same as ‘left’, but content flows on the left side of the box, starting at the top.
none
The box is not floated. ”
这说明浮动元素上的{display: inline;}会被忽略,事实上所有的浏览器没有呈现任何改变,包括IE。但是,它不知何故让IE停止将浮动元素的边界翻倍。因而,这个修复办法可以被直接应用,而没有任何繁琐的隐藏方法。如果将来的一款浏览器决定对这个修复办法抱恙,只要把这个修复装入IE独用的Tan Hack里,细节如同IE Three Pixel Text-Jog Demo。
下面是两个使用了前面相同代码的生动演示,第一个照常显示了IE的Bug,下一个对浮动元素使用了”inline”修复。
.floatbox {
float: left;
width: 150px;
height: 150px;
margin: 5px 0 5px 100px;
display: inline;
}
附:FF和IE对CSS的不同理解
FF: 设置 padding 后, div 会增加 height 和 width, 但 IE 不会, 故需要用 !important 多设一个 height 和 width
FF: 支持 !important, IE 则忽略, 可用 !important 为 FF 特别设置样式
cursor: pointer 可以同时在 IE FF 中显示游标手指状, hand 仅 IE 可以
FF: 链接加边框和背景色,需设置 display: block, 同时设置 float: left 保证不换行。参照 menubar, 给 a 和 menubar 设置高度是为了避免底边显示错位, 若不设 height, 可以在 menubar 中插入一个空格
在firefox和IE中的BOX模型解释不一致导致相差2px解决方法:
{margin:30px!important;margin:28px;}
注意这两个margin的顺序一定不能写反。!important这个属性IE不能识别,但别的浏览器可以识别。所以在IE下其实解释成这样:
div{maring:30px;margin:28px}
发现一个ie和firefox的不同处,就是对于a的visited的判断,前者是对a而言的,比如所有多个相同hrel的a,但是ie是分别处理的,即使这个url访问过,但是只要这个a没有点击,就不会挂上visited的伪类;对于ff的这点特性我就有点郁闷,个人觉得ie在这个问题处理上更加人性化,也更加现代一点,但是转念一想ff也没有错,因为a存在的意义就是url,若不是通过url判断,还能够通过什么呢(转)

CSS实现DIV表格圆角

mikel阅读(820)

<style>
<!--
.xtop, .xbottom {display:block; background:transparent; font-size:1px;}
.xb1, .xb2, .xb3, .xb4 {display:block; overflow:hidden;background: #DFE6EF;}
.xb1, .xb2, .xb3 {height:1px;}
.xb2, .xb3, .xb4 {border-left:1px solid #0088CC; border-right:1px solid #0088CC;}
.xb1 {margin:0 5px; background:#0088CC;}
.xb2 {margin:0 3px; border-width:0 2px;}
.xb3 {margin:0 2px;}
.xb4 {height:2px; margin:0 1px;}
.xboxcontent {display:block; border:0 solid #0088CC; border-width:0 1px; padding: 4px; background: #DFE6EF;}
-->
</style>
<b class="xtop">
<b class="xb1"></b>
<b class="xb2"></b>
<b class="xb3"></b>
<b class="xb4"></b>
</b>
<div class="xboxcontent">
不用图片<br/>不用表格实现圆角</div>
<b class="xbottom">
<b class="xb4"></b>
<b class="xb3"></b>
<b class="xb2"></b>
<b class="xb1"></b>
</b>

Response出的中文FireFox出现乱码问题

mikel阅读(799)

Setting @CODEPAGE explicitly affects literal strings in a single response. Response.CodePage affects dynamic strings in a single response, and Session.CodePage affects dynamic strings in all responses in a session.
这句话解释清楚了@CODEPAGE,Response.CodePage,Session.CodePage 分别的作用是什么。
@CODEPAGE作用于所有静态的字符串,比如某文件中的 const blogname=”我的家”
Response.CodePage,Session.CodePage作用于所有动态输出的字符串,比如<%=blogname%>
这句话很关键的是说明了Response.CodePage的作用范围是a single response,而SXNA中声明的Session.CodePage的作用范围是all responses in a session。
再看另外一句话。
If Response.CodePage is not explicitly set in a page, it is implicitly set by Session.CodePage, if sessions are enabled. If sessions are not enabled, Response.CodePage is set by @CodePage, if @CodePage is present in the page. If there is no @CodePage in the page, Response.CodePage is set by the AspCodePage metabase property. If the AspCodePage metabase property is not set, or set to 0, Response.CodePage is set by the system ANSI code page.
这句话我乍一看,把意思理解成了这样:在sessions are enabled的时候,如果Response.CodePage没有声明,则Response.CodePage会被Session.CodePage赋值。如果sessions are not enabled的时候, 如果@CodePage已声明,则Response.CodePage会被@CodePage赋值,等等………….
这句话 解释了为什么从SXNA中出来以后进入一些别的页面比如oblog,z-blog等等容易出现乱码,因为其他程序没有声明 Response.CodePage而恰巧SXNA声明了Session.CodePage,因此一进入SXNA,Session.CodePage立即被赋值(版本不同,有的版本赋了936有的版本赋了65001),而后进入其他程序的时候Response.CodePage马上被 Session.CodePage赋值,如果这时Response.CodePage与页面本身编码不一样的话,页面就会出现乱码。所以进入z-blog 出现乱码的时候我查了当时的Session.CodePage和Response.CodePage都是936,而进入oblog出现乱码的时候 Session.CodePage和Response.CodePage都是65001.就是说要想保证叶面不出现乱码,应该声明 Response.CodePage,否则他就会按照Session.CodePage来解释网页(而不是按照@codepage解释网页).
如 果仅仅按照上面的解释的话,我实际上是很糊涂的,因为我们都是用的中文操系统,当每一次进入浏览器的时候你可以尝试输出 Session.CodePage,能看到他都是936!为什么进入Z-blog的时候他不把默认的Session.CodePage的936赋给 Response.CodePage呢?反而把@CodePage给了Response.CodePage?什么情况下Session.CodePage 才赋值给Response.CodePage呢?原文的sessions are enabled应该如何理解呢?
也许上面的话应该这样理解:
在Session.CodePage 被任何程序声明的时候,如果Response.CodePage没有声明,则Response.CodePage会被Session.CodePage赋值。如果Session.CodePage没有被任何程序声明的时候, 如果@CodePage已声明,则Response.CodePage会被@CodePage赋值,….,最后的页面动态内容部分按照 Response.CodePage的值解释。
因为Zblog和Oblog都声明了@CodePage,所以,用户刚刚启动完机器然后进入浏览器浏览Zblog和Oblog的时候Response.CodePage会被@CodePage赋值,于是叶面显示正常。
这句话进一步解释了产生乱码的原因
If you set Response.CodePage or Session.CodePage explicitly, do so before sending non-literal strings to the client. If you use literal and non-literal strings in the same page, make sure the code page of @CODEPAGE matches the code page of Response.CodePage, or the literal strings are encoded differently from the non-literal strings and display incorrectly.
其中比较有用的一句话是说如果Response.CodePage和 @CODEPAGE不一样的话会产生乱码。也就是说当Z-blog的@CODEPAGE=65001而Z-blog的Response.CodePage 被Session.CodePage赋为936的时候就会出现乱码,oblog反之亦然。
不知道上面说了这么多解释清楚没有-_-||
下面解释一下为什么SXNA有时会把Session.CodePage赋为936,我有一个版本是这样写的:
<% originalCodePage=Session.CodePage %>
…….
<% Session.CodePage=OriginalCodePage %>
当 用户进入浏览器的时候Session.CodePage默认为936,这个时候的默认936不是程序声明的,因此不会赋给 Response.CodePage,当进入SXNA的时候,Session.CodePage被上面那段代码一折腾就变成了程序声明的 Session.CodePage=936,因此再进入Zblog的时候就把936给了Response.CodePage。
至此,全部原因已经分析清楚了。
因此说,保证asp叶面一定不会出现乱码的代码应该是这样的:(假定是UTF-8的叶子)
<%@ CODEPAGE=65001 %>
<% Response.CodePage=65001%>
<% Response.Charset="UTF-8" %>
进一步说明为什么要加Response.Charset,因为MSDN说应该加…呵呵
If the code page is set in a page, then Response.Charset should also be set.
另外,文件的编码格式应该与@CODEPAGE一样:
The file format of a Web page must be the same as the @CODEPAGE used in the page.
这就是为什么zblog,pjblog等一些程序要吧文件存成UTF8编码格式的原因.
综上,如果所有的程序都声明了Response.CodePage就不会被Session.CodePage干扰而出现乱码了。所以Session.CodePage还是不能轻易用的!

Spring and Hibernate with BlazeDS

mikel阅读(731)

Problem Summary
You want to use Spring and Hibernate with BlazeDS.
Solution Summary
This cookbook entry describes how you can update the store/inventory management example from Christophe Coenraets article Using BlazeDS with Spring with orM data access with Hibernate.
Explanation
Introduction
In his article Using BlazeDS with Spring Christophe Coenraets describes how you can build internet applications with a Flex front-end and a Spring back-end. The article contains a store/inventory management example with database connectivity using the Spring JDBC abstraction framework. This cookbook entry describes how you can update the store/inventory management example with orM data access with Hibernate. Hibernate is one of the most popular persistency frameworks. Since this entry extends the store/inventory management example, it assumes you successfully completed Example 2: Store/inventory management using Flex Remoting.
Step 1: Add the Hibernate libraries
First download Hibernate from http://www.hibernate.org and add the following libraries to /blazeds/tomcat/webapps/blazeds/WEB-INF/lib:

antlr.jar
cglib.jar
asm.jar
asm-attrs.jars
commons-collections.jar
commons-logging.jar
hibernate3.jar
jta.jar
dom4j.jar
log4j.jar

Step 2: Create the mapping file
Since Hibernate needs to know how to load and store objects of the Product class, we need a mapping file to tell Hibernate what table and properties to use. Create a file Product.hbm.xml in /flex-spring/samples/store/java and add the following mapping:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
&#91;&#93;>
<hibernate-mapping package="flex.samples.spring.store">
<class name="Product" table="PRODUCT">
<id name="productId" type="long" column="PRODUCT_ID" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="name" column="NAME" length="40"/>
<property name="category" column="CATEGORY" length="40"/>
<property name="image" column="IMAGE" length="40"/>
<property name="price" column="PRICE" type="double"/>
<property name="description" column="DESCRIPTION" length="255"/>
<property name="qtyInStock" column="QTY_IN_STOCK" type="integer"/>
</class>
</hibernate-mapping>

Step 3: Create the Hibernate ProductDAO implementation
Now that Hibernate knows how to store our objects, we can implement the ProductDAO interface to use Hibernate persistency. Create a new class HibernateProductDAO in the /flex-spring/samples/store/java directory and add the following lines:

package flex.samples.spring.store;
import java.util.Collection;
import o&#114;g.hibernate.HibernateException;
import o&#114;g.hibernate.Session;
import o&#114;g.hibernate.SessionFactory;
import o&#114;g.springframework.orm.hibernate3.SessionFactoryUtils;
public class HibernateProductDAO implements ProductDAO {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public SessionFactory getSessionFactory() {
return this.sessionFactory;
}
public void cr&#101;ateProduct(Product product) {
Session session = SessionFactoryUtils.getSession(getSessionFactory(),
false);
try {
session.save(product);
} catch (HibernateException e) {
throw SessionFactoryUtils.convertHibernateAccessException(e);
}
}
public void del&#101;teProduct(Product product) {
Session session = SessionFactoryUtils.getSession(getSessionFactory(),
false);
try {
session.del&#101;te(product);
} catch (HibernateException e) {
throw SessionFactoryUtils.convertHibernateAccessException(e);
}
}
public Collection findAll() {
Session session = SessionFactoryUtils.getSession(getSessionFactory(),
false);
try {
return session.cr&#101;ateQuery("from Product").list();
} catch (HibernateException e) {
throw SessionFactoryUtils.convertHibernateAccessException(e);
}
}
public void up&#100;ateProduct(Product product) {
Session session = SessionFactoryUtils.getSession(getSessionFactory(),
false);
try {
session.up&#100;ate(product);
} catch (HibernateException e) {
throw SessionFactoryUtils.convertHibernateAccessException(e);
}
}
}

Step 4: Register the Spring beans
We need to register the new productDAOBean and a Hibernate sessionFactory in the Spring configuration. Transaction supported is added using the HibernateTransactionManager. Register the beans in the applicationContext.xml as follows:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>flex/samples/spring/store/Product.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
</props>
</property>
<property name="dataSource"><ref bean="dataSource"/></property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="productDAOBeanTarget" class="flex.samples.spring.store.HibernateProductDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="productDAOBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="txManager" />
<property name="target" ref="productDAOBeanTarget" />
<property name="transactionAttributes">
<props>
<prop key="cr&#101;ate*">PROPAGATION_REQUIRED</prop>
<prop key="up&#100;ate*">PROPAGATION_REQUIRED</prop>
<prop key="del&#101;te*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>

Remove the original productDAOBean configuration.
Step 5: Update the build file
Navigate to /flex-spring/samples/store and open the file build.xml. Update the compile-java target to include the Hibernate library and to copy the mapping file:

<target name="compile-java">
<javac srcdir="java" destdir="${DEPLOY_DIR}/WEB-INF/classes"
classpath="${DEPLOY_DIR}/WEB-INF/lib/spring.jar;${DEPLOY_DIR}/WEB-INF/lib/hibernate3.jar"/>
<copy todir="${DEPLOY_DIR}/WEB-INF/classes/flex/samples/spring/store">
<fileset dir="java" includes="**/*hbm.xml"/>
</copy>
</target>

Step 6: Build the project
* Navigate to /flex-spring/samples/store.
* Execute the following command to compile and deploy the client-side and the server side of the application: ant
Step 7: Run the client application
* Restart Tomcat
* Open a browser, access http://localhost:8400/blazeds/storeadmin/index.html, and test the storeadmin application.
* Open a browser, access http://localhost:8400/blazeds/store/index.html, and test the store application.

[转]javascript 操作cookies 存(设置)、读取、删除函数实例详解

mikel阅读(617)

以前一般没想过要在JavaScript里进行COOKIES操作,不过今天碰到了,所以也发一下,作为收藏吧,以下是将这几个功能分别写成了函数.方便使用

<SCRIPT LANGUAGE="JavaScript">
//写cookies函数
function SetCookie(name,value)//两个参数,一个是cookie的名子,一个是值
{
var Days = 30; //此 cookie 将被保存 30 天
var exp  = new Date();    //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//读取cookies函数
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
function delCookie(name)//删除cookie
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

//简单例子

//SetCookie ("name", www.buslfy.cn)
//alert(getCookie(name));
</script>
<SCRIPT LANGUAGE="JavaScript">
function  GetCookieVal(offset)
//获得Cookie解码后的值
{
var  endstr  =  documents.cookie.indexOf  (";",  offset);
if  (endstr  ==  -1)
endstr  =  documents.cookie.length;
return  unescape(documents.cookie.substring(offset,  endstr));
}

如果点了确定,只要不清cookie,以后访问都不会再提示,如果不点确定则每次都会提示。放在js文件里,全站包含

<!--
var the_cookie = document.cookie;
var broken_cookie = the_cookie.split(":");
var the_visiteraccepted = unescape(broken_cookie&#91;1&#93;);
//
if (the_visiteraccepted=="undefined"){
var tmp=confirm(&#39;中国人何时何地。&#39;);
if(tmp==false){
window.close();
}else{
var the_visiteraccepted = 1;
var the_cookie = "ILoveChina=visiteraccepted:" + escape(the_visiteraccepted);
document.cookie = the_cookie;
}
}
//-->
</SCRIPT>

1. Cookie的兼容性问题
Cookie 的格式有2个不同的版本,第一个版本,我们称为Cookie Version 0,是最初由Netscape公司制定的,也被几乎所有的浏览器支持。而较新的版本,Cookie Version 1,则是根据RFC 2109文档制定的。为了确保兼容性,JAVA规定,前面所提到的涉及Cookie的操作都是针对旧版本的Cookie进行的。而新版本的Cookie目前还不被Javax.servlet.http.Cookie包所支持。
2. Cookie的内容
同样的 Cookie的内容的字符限制针对不同的Cookie版本也有不同。在Cookie Version 0中,某些特殊的字符,例如:空格,方括号,圆括号,等于号(=),逗号,双引号,斜杠,问号,@符号,冒号,分号都不能作为Cookie的内容。这也就是为什么我们在例子中设定Cookie的内容为”Test_Content”的原因。
虽然在Cookie Version 1规定中放宽了限制,可以使用这些字符,但是考虑到新版本的Cookie规范目前仍然没有为所有的浏览器所支持,因而为保险起见,我们应该在Cookie的内容中尽量避免使用这些字符

读取cookie的正则表达式

mikel阅读(965)

表达式

\w+=[^;]*

示例

ohkoo=Password=mikel&User=mikel; ASPSESSIONIDCCATCBCA=PLALKMLBOAJPBDCDEEHHJJNJ; ASPSESSIONIDQADCTCCC=EPNHNPMBIOFIOCCKHDABBJCL