?Acegi安全系統的配置
????????
Acegi 的配置看起來非常復雜,但事實上在實際項目的安全應用中我們并不需要那么多功能,清楚的了解Acegi配置中各項的功能,有助于我們靈活的運用Acegi于實踐中。
2.1 在Web.xml中的配置
1)? FilterToBeanProxy
Acegi通過實現了Filter接口的FilterToBeanProxy提供一種特殊的使用Servlet Filter的方式,它委托Spring中的Bean -- FilterChainProxy來完成過濾功能,這好處是簡化了web.xml的配置,并且充分利用了Spring IOC的優勢。FilterChainProxy包含了處理認證過程的filter列表,每個filter都有各自的功能。
? ? <filter>
??????? <filter-name>Acegi Filter Chain Proxy</filter-name>
??????? <filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
??????? <init-param>
??????????? <param-name>targetClass</param-name>
??????????? <param-value>org.acegisecurity.util.FilterChainProxy</param-value>
??????? </init-param>
??? </filter>
2) filter-mapping
<filter-mapping>限定了FilterToBeanProxy的URL匹配模式,只有*.do和*.jsp和/j_acegi_security_check 的請求才會受到權限控制,對javascript,css等不限制。
?? <filter-mapping>
????? <filter-name>Acegi Filter Chain Proxy</filter-name>
????? <url-pattern>*.do</url-pattern>
??? </filter-mapping>
???
??? <filter-mapping>
????? <filter-name>Acegi Filter Chain Proxy</filter-name>
????? <url-pattern>*.jsp</url-pattern>
??? </filter-mapping>
???
??? <filter-mapping>
????? <filter-name>Acegi Filter Chain Proxy</filter-name>
????? <url-pattern>/j_acegi_security_check</url-pattern>
</filter-mapping>
3) HttpSessionEventPublisher
<listener>的HttpSessionEventPublisher用于發布HttpSessionApplicationEvents和HttpSessionDestroyedEvent事件給spring的applicationcontext。
??? <listener>
??????? <listener-class>org.acegisecurity.ui.session.HttpSessionEventPublisher</listener-class>
??? </listener>
2.2 在applicationContext-acegi-security.xml中
2.2.1 FILTER CHAIN
FilterChainProxy會按順序來調用這些filter,使這些filter能享用Spring ioc的功能, CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON定義了url比較前先轉為小寫, PATTERN_TYPE_APACHE_ANT定義了使用Apache ant的匹配模式
<bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy">
??????? <property name="filterInvocationDefinitionSource">
??????????? <value>
??????????????? CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
??????????????? PATTERN_TYPE_APACHE_ANT
?????????????? /**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,
basicProcessingFilter,rememberMeProcessingFilter,anonymousProcessingFilter,
exceptionTranslationFilter,filterInvocationInterceptor
??????????? </value>
??????? </property>
??? </bean>
2.2.2 基礎認證
1) authenticationManager
起到認證管理的作用,它將驗證的功能委托給多個Provider,并通過遍歷Providers, 以保證獲取不同來源的身份認證,若某個Provider能成功確認當前用戶的身份,authenticate()方法會返回一個完整的包含用戶授權信息的Authentication對象,否則會拋出一個AuthenticationException。
Acegi提供了不同的AuthenticationProvider的實現,如:
??????? DaoAuthenticationProvider 從數據庫中讀取用戶信息驗證身份
??????? AnonymousAuthenticationProvider 匿名用戶身份認證
??????? RememberMeAuthenticationProvider 已存cookie中的用戶信息身份認證
??????? AuthByAdapterProvider 使用容器的適配器驗證身份
??????? CasAuthenticationProvider 根據Yale中心認證服務驗證身份, 用于實現單點登陸
??????? JaasAuthenticationProvider 從JASS登陸配置中獲取用戶信息驗證身份
??????? RemoteAuthenticationProvider 根據遠程服務驗證用戶身份
??????? RunAsImplAuthenticationProvider 對身份已被管理器替換的用戶進行驗證
??????? X509AuthenticationProvider 從X509認證中獲取用戶信息驗證身份
??????? TestingAuthenticationProvider 單元測試時使用
??????? 每個認證者會對自己指定的證明信息進行認證,如DaoAuthenticationProvider僅對UsernamePasswordAuthenticationToken這個證明信息進行認證。
<bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">
??????? <property name="providers">
??????????? <list>
??????????????? <ref local="daoAuthenticationProvider"/>
??????????????? <ref local="anonymousAuthenticationProvider"/>
??????????????? <ref local="rememberMeAuthenticationProvider"/>
??????????? </list>
??????? </property>
</bean>
2) daoAuthenticationProvider
進行簡單的基于數據庫的身份驗證。DaoAuthenticationProvider獲取數據庫中的賬號密碼并進行匹配,若成功則在通過用戶身份的同時返回一個包含授權信息的Authentication對象,否則身份驗證失敗,拋出一個AuthenticatiionException。
??? <bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
??????? <property name="userDetailsService" ref="jdbcDaoImpl"/>
??????? <property name="userCache" ref="userCache"/>
??????? <property name="passwordEncoder" ref="passwordEncoder"/>
?? </bean>
3) passwordEncoder
使用加密器對用戶輸入的明文進行加密。Acegi提供了三種加密器:
PlaintextPasswordEncoder—默認,不加密,返回明文.
ShaPasswordEncoder—哈希算法(SHA)加密
Md5PasswordEncoder—消息摘要(MD5)加密
<bean id="passwordEncoder" class="org.acegisecurity.providers.encoding.Md5PasswordEncoder"/>
4) jdbcDaoImpl
用于在數據中獲取用戶信息。 acegi提供了用戶及授權的表結構,但是您也可以自己來實現。通過usersByUsernameQuery這個SQL得到你的(用戶ID,密碼,狀態信息);通過authoritiesByUsernameQuery這個SQL得到你的(用戶ID,授權信息)
<bean id="jdbcDaoImpl" class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
??????? <property name="dataSource" ref="dataSource"/>
??????? <property name="usersByUsernameQuery">
??????????? <value>select loginid,passwd,1 from users where loginid = ?</value>
??????? </property>
??????? <property name="authoritiesByUsernameQuery">
??????????? <value>select u.loginid,p.name from users u,roles r,permissions p,user_role ur,role_permis rp where u.id=ur.user_id and r.id=ur.role_id and p.id=rp.permis_id and
??????????????? r.id=rp.role_id and p.status='1' and u.loginid=?</value>
??????? </property>
</bean>
5) userCache &? resourceCache
緩存用戶和資源相對應的權限信息。每當請求一個受保護資源時,daoAuthenticationProvider就會被調用以獲取用戶授權信息。如果每次都從數據庫獲取的話,那代價很高,對于不常改變的用戶和資源信息來說,最好是把相關授權信息緩存起來。(詳見 2.6.3 資源權限定義擴展 )
userCache提供了兩種實現: NullUserCache和EhCacheBasedUserCache, NullUserCache實際上就是不進行任何緩存,EhCacheBasedUserCache是使用Ehcache來實現緩功能。
??? <bean id="userCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
??????? <property name="cacheManager" ref="cacheManager"/>
??????? <property name="cacheName" value="userCache"/>
??? </bean>
??? <bean id="userCache" class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache" autowire="byName">
??????? <property name="cache" ref="userCacheBackend"/>
??? </bean>
??? <bean id="resourceCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
??????? <property name="cacheManager" ref="cacheManager"/>
??????? <property name="cacheName" value="resourceCache"/>
??? </bean>
??? <bean id="resourceCache" class="org.springside.modules.security.service.acegi.cache.ResourceCache" autowire="byName">
??????? <property name="cache" ref="resourceCacheBackend"/>
??? </bean>
6) basicProcessingFilter
用于處理HTTP頭的認證信息,如從Spring遠程協議(如Hessian和Burlap)或普通的瀏覽器如IE,Navigator的HTTP頭中獲取用戶信息,將他們轉交給通過authenticationManager屬性裝配的認證管理器。如果認證成功,會將一個Authentication對象放到會話中,否則,如果認證失敗,會將控制轉交給認證入口點(通過authenticationEntryPoint屬性裝配)
??? <bean id="basicProcessingFilter" class="org.acegisecurity.ui.basicauth.BasicProcessingFilter">
??????? <property name="authenticationManager" ref="authenticationManager"/>
??????? <property name="authenticationEntryPoint" ref="basicProcessingFilterEntryPoint"/>
??? </bean>
7) basicProcessingFilterEntryPoint
通過向瀏覽器發送一個HTTP401(未授權)消息,提示用戶登錄。
處理基于HTTP的授權過程, 在當驗證過程出現異常后的"去向",通常實現轉向、在response里加入error信息等功能。
<bean id="basicProcessingFilterEntryPoint" class="org.acegisecurity.ui.basicauth.BasicProcessingFilterEntryPoint">
??????? <property name="realmName" value="SpringSide Realm"/>
</bean>
8) authenticationProcessingFilterEntryPoint
當拋出AccessDeniedException時,將用戶重定向到登錄界面。屬性loginFormUrl配置了一個登錄表單的URL,當需要用戶登錄時,authenticationProcessingFilterEntryPoint會將用戶重定向到該URL
<bean id="authenticationProcessingFilterEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
??????? <property name="loginFormUrl">
??????????? <value>/security/login.jsp</value>
??????? </property>
??????? <property name="forceHttps" value="false"/>
</bean>
2.2.3 HTTP安全請求
1) httpSessionContextIntegrationFilter
每次request前 HttpSessionContextIntegrationFilter從Session中獲取Authentication對象,在request完后, 又把Authentication對象保存到Session中供下次request使用,此filter必須其他Acegi filter前使用,使之能跨越多個請求。
<bean id="httpSessionContextIntegrationFilter" class="org.acegisecurity.context.HttpSessionContextIntegrationFilter"></bean>
??? <bean id="httpRequestAccessDecisionManager" class="org.acegisecurity.vote.AffirmativeBased">
??????? <property name="allowIfAllAbstainDecisions" value="false"/>
??????? <property name="decisionVoters">
??????????? <list>
??????????????? <ref bean="roleVoter"/>
??????????? </list>
??????? </property>
</bean>
2) httpRequestAccessDecisionManager
經過投票機制來決定是否可以訪問某一資源(URL或方法)。allowIfAllAbstainDecisions為false時如果有一個或以上的decisionVoters投票通過,則授權通過。可選的決策機制有ConsensusBased和UnanimousBased
??? <bean id="httpRequestAccessDecisionManager" class="org.acegisecurity.vote.AffirmativeBased">
??????? <property name="allowIfAllAbstainDecisions" value="false"/>
??????? <property name="decisionVoters">
??????????? <list>
??????????????? <ref bean="roleVoter"/>
??????????? </list>
??????? </property>
??? </bean>
3) roleVoter
? 必須是以rolePrefix設定的value開頭的權限才能進行投票,如AUTH_ , ROLE_
??? <bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter">
??????? <property name="rolePrefix" value="AUTH_"/>
?? </bean>
4)exceptionTranslationFilter
異常轉換過濾器,主要是處理AccessDeniedException和AuthenticationException,將給每個異常找到合適的"去向"?
?? <bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter">
??????? <property name="authenticationEntryPoint" ref="authenticationProcessingFilterEntryPoint"/>
??? </bean>
5) authenticationProcessingFilter
和servlet spec差不多,處理登陸請求.當身份驗證成功時,AuthenticationProcessingFilter會在會話中放置一個Authentication對象,并且重定向到登錄成功頁面
???????? authenticationFailureUrl定義登陸失敗時轉向的頁面
???????? defaultTargetUrl定義登陸成功時轉向的頁面
???????? filterProcessesUrl定義登陸請求的頁面
???????? rememberMeServices用于在驗證成功后添加cookie信息
??? <bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
??????? <property name="authenticationManager" ref="authenticationManager"/>
??????? <property name="authenticationFailureUrl">
??????????? <value>/security/login.jsp?login_error=1</value>
??????? </property>
??????? <property name="defaultTargetUrl">
??????????? <value>/admin/index.jsp</value>
??????? </property>
??????? <property name="filterProcessesUrl">
??????????? <value>/j_acegi_security_check</value>
??????? </property>
??????? <property name="rememberMeServices" ref="rememberMeServices"/>
??? </bean>
6) filterInvocationInterceptor
在執行轉向url前檢查objectDefinitionSource中設定的用戶權限信息。首先,objectDefinitionSource中定義了訪問URL需要的屬性信息(這里的屬性信息僅僅是標志,告訴accessDecisionManager要用哪些voter來投票)。然后,authenticationManager掉用自己的provider來對用戶的認證信息進行校驗。最后,有投票者根據用戶持有認證和訪問url需要的屬性,調用自己的voter來投票,決定是否允許訪問。
??? <bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
??????? <property name="authenticationManager" ref="authenticationManager"/>
??????? <property name="accessDecisionManager" ref="httpRequestAccessDecisionManager"/>
??????? <property name="objectDefinitionSource" ref="filterDefinitionSource"/>
??? </bean>
7) filterDefinitionSource (詳見 2.6.3 資源權限定義擴展)
自定義DBFilterInvocationDefinitionSource從數據庫和cache中讀取保護資源及其需要的訪問權限信息?
<bean id="filterDefinitionSource" class="org.springside.modules.security.service.acegi.DBFilterInvocationDefinitionSource">
??????? <property name="convertUrlToLowercaseBeforeComparison" value="true"/>
??????? <property name="useAntPath" value="true"/>
??????? <property name="acegiCacheManager" ref="acegiCacheManager"/>
</bean>
2.2.4 方法調用安全控制
(詳見 2.6.3 資源權限定義擴展)
1) methodSecurityInterceptor
在執行方法前進行攔截,檢查用戶權限信息
2) methodDefinitionSource
自定義MethodDefinitionSource從cache中讀取權限
?? <bean id="methodSecurityInterceptor" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
??????? <property name="authenticationManager" ref="authenticationManager"/>
??????? <property name="accessDecisionManager" ref="httpRequestAccessDecisionManager"/>
??????? <property name="objectDefinitionSource" ref="methodDefinitionSource"/>
??? </bean>
??? <bean id="methodDefinitionSource" class="org.springside.modules.security.service.acegi.DBMethodDefinitionSource">
??????? <property name="acegiCacheManager" ref="acegiCacheManager"/>
??? </bean>
2.3 Jcaptcha驗證碼
采用 http://jcaptcha.sourceforge.net?作為通用的驗證碼方案,請參考SpringSide中的例子,或網上的:
http://www.coachthrasher.com/page/blog?entry=jcaptcha_with_appfuse。
差沙在此過程中又發現acegi logout filter的錯誤,進行了修正。
另外它默認提供的圖片比較難認,我們custom了一個美觀一點的版本。
posted @
2007-02-02 20:31 西紅柿(tomato) 閱讀(462) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2007-02-02 20:28 西紅柿(tomato) 閱讀(940) |
評論 (0) |
編輯 收藏
Subscriber:www.1cn.biz
Subscriber Code: jLR8ZC-444-55-4467865481680090
Subscriber:www.1cn.biz
Subscriber Code: jLR8ZC-444-55-4467865481680090
posted @
2006-12-14 15:54 西紅柿(tomato) 閱讀(584) |
評論 (0) |
編輯 收藏
格式化輸出NumberFormat
相關內容:Local,?DataFormat,?MessageFormat,?SimpleDateFormat,?Format
---------------------------------------------------------------
java.text.NumberFormat類有三個方法可以產生下列數據的標準格式化器:
數字
貨幣
百分數
---------------------------------------------------------------
創建格式化器(默認地區Local格式):
NumberFormat.getNumberInstance();
NumberFormat.getCurrencyInstance();
NumberFormat.getPercentInstance();
---------------------------------------------------------------
例題:
double?dbl=10000.0/3;
NumberFormat?formatter=NumberFormat.getNumberInstance();
String?s=formatter.format(x);
System.out.println(s);
---------------------------------------------------------------
設定整數或小數部分所顯示的最少和最多位數,可以使用NumberFormat類
的方法:
setMinimumIntegerDigits(int)
setMinimumFractionDigits(int)
setMaximumIntegerDigits(int)
setMaximumFractionDigits(int)
設定小數部分的最多位很有用處。如果小數部分丟失的第一位數字大于等于5,
那么顯示的最后一位會增1(四舍五入)。如果要顯示尾隨的零,可以把小數部分的最少位等于最多位。
如果不想顯示,可以把小數部分的最少位設定為0或不設定。
指定最多位整數相當危險,顯示值將會被截斷,產生一個錯誤的值。
---------------------------------------------------------------
測試例題:
文件名TestNumberFormat.java
--------------------------------------------------------
import?java.text.NumberFormat;
public?class?TestNumberFormat
{
????public?static?void?main(String[]?args)?{
????????????NumberFormat?nFormat=NumberFormat.getNumberInstance();
????????????nFormat.setMinimumIntegerDigits(3);//設置整數部分至少為3位
????????????nFormat.setMaximumFractionDigits(5);//設置小數點后面尾數為5
????????System.out.println("Format?Out?3.2128345="+nFormat.format(3.2128345));
????????????NumberFormat?cFormat=NumberFormat.getCurrencyInstance();
????????????cFormat.setMaximumFractionDigits(3);
????????System.out.println("Format?Out?321283.47656="+cFormat.format(321283.47656));
????????????NumberFormat?pFormat=NumberFormat.getPercentInstance();
????????????pFormat.setMaximumFractionDigits(4);
????????System.out.println("Format?Out?3.2128345="+pFormat.format(3.2128345));
????????System.out.println("Format?Out?null="+nFormat.format(null));//參數是null,出現異常
????????//Throws??IllegalArgumentException
????}
}
//=================?運行結果如下?=======================
Format?Out?3.2128345=003.21283
Format?Out?321283.47656=¥321,283.477
Format?Out?3.2128345=321.2834%
Exception?in?thread?"main"?java.lang
posted @
2006-12-14 15:50 西紅柿(tomato) 閱讀(15685) |
評論 (1) |
編輯 收藏
Log4j由三個重要的組件構成:日志信息的優先級,日志信息的輸出目的地,日志信息的輸出格式。日志信息的優先級從高到低有ERROR、WARN、INFO、DEBUG,分別用來指定這條日志信息的重要程度;日志信息的輸出目的地指定了日志將打印到控制臺還是文件中;而輸出格式則控制了日志信息的顯示內容。
一、定義配置文件
其實您也可以完全不使用配置文件,而是在代碼中配置Log4j環境。但是,使用配置文件將使您的應用程序更加靈活。Log4j支持兩種配置文件格式,一種是XML格式的文件,一種是Java特性文件(鍵=值)。下面我們介紹使用Java特性文件做為配置文件的方法:
1.配置根Logger,其語法為:
log4j.rootLogger = [ level ] , appenderName, appenderName, …
其中,level 是日志記錄的優先級,分為OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL或者您定義的級別。Log4j建議只使用四個級別,優先級從高到低分別是ERROR、WARN、INFO、DEBUG。通過在這里定義的級別,您可以控制到應用程序中相應級別的日志信息的開關。比如在這里定義了INFO級別,則應用程序中所有DEBUG級別的日志信息將不被打印出來。 appenderName就是指定日志信息輸出到哪個地方。您可以同時指定多個輸出目的地。
2.配置日志信息輸出目的地Appender,其語法為:
log4j.appender.appenderName = fully.qualified.name.of.appender.class
log4j.appender.appenderName.option1 = value1
…
log4j.appender.appenderName.option = valueN
其中,Log4j提供的appender有以下幾種:
org.apache.log4j.ConsoleAppender(控制臺),
org.apache.log4j.FileAppender(文件),
org.apache.log4j.DailyRollingFileAppender(每天產生一個日志文件),
org.apache.log4j.RollingFileAppender(文件大小到達指定尺寸的時候產生一個新的文件),
org.apache.log4j.WriterAppender(將日志信息以流格式發送到任意指定的地方)
3.配置日志信息的格式(布局),其語法為:
log4j.appender.appenderName.layout = fully.qualified.name.of.layout.class
log4j.appender.appenderName.layout.option1 = value1
…
log4j.appender.appenderName.layout.option = valueN
其中,Log4j提供的layout有以下幾種:
org.apache.log4j.HTMLLayout(以HTML表格形式布局),
org.apache.log4j.PatternLayout(可以靈活地指定布局模式),
org.apache.log4j.SimpleLayout(包含日志信息的級別和信息字符串),
org.apache.log4j.TTCCLayout(包含日志產生的時間、線程、類別等等信息)
Log4J采用類似C語言中的printf函數的打印格式格式化日志信息,打印參數如下: %m 輸出代碼中指定的消息
%p 輸出優先級,即DEBUG,INFO,WARN,ERROR,FATAL
%r 輸出自應用啟動到輸出該log信息耗費的毫秒數
%c 輸出所屬的類目,通常就是所在類的全名
%t 輸出產生該日志事件的線程名
%n 輸出一個回車換行符,Windows平臺為“\r\n”,Unix平臺為“\n”
%d 輸出日志時間點的日期或時間,默認格式為ISO8601,也可以在其后指定格式,比如:%d{yyy MMM dd HH:mm:ss,SSS},輸出類似:2002年10月18日 22:10:28,921
%l 輸出日志事件的發生位置,包括類目名、發生的線程,以及在代碼中的行數。舉例:Testlog4.main(TestLog4.java:10)
二、在代碼中使用Log4j
1.得到記錄器
使用Log4j,第一步就是獲取日志記錄器,這個記錄器將負責控制日志信息。其語法為:
public static Logger getLogger( String name)
通過指定的名字獲得記錄器,如果必要的話,則為這個名字創建一個新的記錄器。Name一般取本類的名字,比如:
static Logger logger = Logger.getLogger ( ServerWithLog4j.class.getName () )
2.讀取配置文件
當獲得了日志記錄器之后,第二步將配置Log4j環境,其語法為:
BasicConfigurator.configure (): 自動快速地使用缺省Log4j環境。
PropertyConfigurator.configure ( String configFilename) :讀取使用Java的特性文件編寫的配置文件。
DOMConfigurator.configure ( String filename ) :讀取XML形式的配置文件。
3.插入記錄信息(格式化日志信息)
當上兩個必要步驟執行完畢,您就可以輕松地使用不同優先級別的日志記錄語句插入到您想記錄日志的任何地方,其語法如下:
Logger.debug ( Object message ) ;
Logger.info ( Object message ) ;
Logger.warn ( Object message ) ;
Logger.error ( Object message ) ;
posted @
2006-12-14 15:48 西紅柿(tomato) 閱讀(349) |
評論 (0) |
編輯 收藏
Acegi1.0.3 使用的是Spring1.2.8
本人經過對Acegi1.0.3 的源代碼進行刪選,并引入到Spring2.0.1環境下,做了嚴格的測試。
本demo 就是 在 Spring2.0.1 + Hibernate3.2 環境下,針對視圖層使用 Struts 和 JSF 分別進行了集成,簡單鮮明描述如何使用 Acegi1.0.3 進行基于用戶角色的動態授權安全控制。
本demo既適合于JSF + Spring2.0.1 + Hibernate3.2 項目也適合于Struts + Spring2.0.1 + Hibernate3.2項目.
未列入特別說明沒有授權的企業和個人都可以自由免費下載使用提供寶貴意見.
本人不急功近利,正在做完整的文檔編寫,做最后嚴格的測試,近期在此免費發布,敬請關注.
posted @
2006-12-11 12:21 西紅柿(tomato) 閱讀(1815) |
評論 (34) |
編輯 收藏
摘要: SQL中的單記錄函數
??2
1
.
ASCII
??3
返回與指定的字符對應的十進制數;
??4
SQL
>
?
select
?
ascii
(
'
A
'
)?A,
ascii
(
...
閱讀全文
posted @
2006-12-11 12:07 西紅柿(tomato) 閱讀(391) |
評論 (0) |
編輯 收藏
一:Oracle
select * from (select rownum,name from table where rownum <=endIndex )
where rownum > startIndex
二:DB2
DB2分頁查詢
SELECT * FROM (Select 字段1,字段2,字段3,rownumber() over(ORDER BY 排序用的列名 ASC) AS rn from 表名) AS a1 WHERE a1.rn BETWEEN 10 AND 20
以上表示提取第10到20的紀錄
select * from (select rownumber() over(order by id asc ) as rowid from table where rowid <=endIndex )
where rowid > startIndex
三:MySQL
:select ? * ? from ? table ? limit ? start,pageNum??
posted @
2006-12-11 12:06 西紅柿(tomato) 閱讀(4709) |
評論 (4) |
編輯 收藏
JS檢測郵箱地址正則表達式
|
[ yangliangy 發表于 2006-11-29 14:36:00 ]
|
?var strm = document.myform.CoMail.value?? //提交mail地址的文本框 ?var regm = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;//驗證Mail的正則表達式,^[a-zA-Z0-9_-]:開頭必須為字母,下劃線,數字, ?if (!strm.match(regm) && strm!="") ?? { ???? alert("郵箱地址格式錯誤或含有非法字符!\n請檢查!"); ??document.myform.CoMail.select();?? ??return false; ??? }
|
posted @
2006-12-03 18:11 西紅柿(tomato) 閱讀(10704) |
評論 (7) |
編輯 收藏