日韩亚洲欧洲在线com91tv,亚洲妇女水蜜桃av网网站,午夜亚洲福利在线老司机http://m.tkk7.com/nkjava/category/37729.html置身浩瀚的沙漠,方向最為重要,希望此blog能向大漠駝鈴一樣,給我方向和指引。<br/> Java,Php,Shell,Python,服務(wù)器運(yùn)維,大數(shù)據(jù),SEO, 網(wǎng)站開(kāi)發(fā)、運(yùn)維,云服務(wù)技術(shù)支持,IM服務(wù)供應(yīng)商, FreeSwitch搭建,技術(shù)支持等. 技術(shù)討論QQ群:428622099zh-cnWed, 03 Aug 2016 04:56:17 GMTWed, 03 Aug 2016 04:56:17 GMT60To prevent a memory leak, the JDBC Driver has been forcibly unregistered--有關(guān)Tomcat自動(dòng)宕機(jī)的解決方案http://m.tkk7.com/nkjava/archive/2016/08/03/431436.html草原上的駱駝草原上的駱駝Wed, 03 Aug 2016 02:59:00 GMThttp://m.tkk7.com/nkjava/archive/2016/08/03/431436.htmlhttp://m.tkk7.com/nkjava/comments/431436.htmlhttp://m.tkk7.com/nkjava/archive/2016/08/03/431436.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/431436.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/431436.html 在Stackoverflow上找到比較有用的一篇文章,解決方案如下:
http://stackoverflow.com/questions/3320400/to-prevent-a-memory-leak-the-jdbc-driver-has-been-forcibly-unregistered
有以下幾個(gè)解決途徑:
  1. Ignore those warnings. Tomcat is doing its job right. The actual bug is in someone else's code (the JDBC driver in question), not in yours. Be happy that Tomcat did its job properly and wait until the JDBC driver vendor get it fixed so that you can upgrade the driver. On the other hand, you aren't supposed to drop a JDBC driver in webapp's /WEB-INF/lib, but only in server's /lib. If you still keep it in webapp's /WEB-INF/lib, then you should manually register and deregister it using a ServletContextListener.
    忽略警告。把WEB-INF/lib下的mysql驅(qū)動(dòng)文件拷貝到Tomcat/lib下。如果仍然要放在WEB-INF/lib下,需要使用監(jiān)聽(tīng)器手動(dòng)的注冊(cè)和注銷(xiāo)。
    下面的文章介紹如何寫(xiě)監(jiān)聽(tīng)器,http://javabeat.net/servletcontextlistener-example/, 當(dāng)然如果是Servlet3.0, 使用注解方式設(shè)置監(jiān)聽(tīng)也是可以的。
    下面的代碼是如何注銷(xiāo)。

    Step 1: Register a Listener
    web.xml
    <listener>
        
    <listener-class>com.mysite.MySpecialListener</listener-class>
    </listener>
    Step 
    2: Implement the Listener

    com.mysite.MySpecialListener.java

    public class MySpecialListener extends ApplicationContextListener {

        @Override
        
    public void contextInitialized(ServletContextEvent sce) {
            
    // On Application Startup, please…

            
    // Usually I'll make a singleton in here, set up my pool, etc.
        }

        @Override
        
    public void contextDestroyed(ServletContextEvent sce) {
          
    // This manually deregisters JDBC driver, which prevents Tomcat 7 from complaining about memory leaks wrto this class
            Enumeration<Driver> drivers = DriverManager.getDrivers();
            while (drivers.hasMoreElements()) {
                Driver driver = drivers.nextElement();
                try {
                    DriverManager.deregisterDriver(driver);
                    LOG.log(Level.INFO, String.format("deregistering jdbc driver: %s", driver));
                } catch (SQLException e) {
                    LOG.log(Level.SEVERE, String.format("Error deregistering driver %s", driver), e);
                }

            }
        }

    }
  2. Downgrade to Tomcat 6.0.23 or older so that you will not be bothered with those warnings. But it will silently keep leaking memory. Not sure if that's good to know after all. Those kind of memory leaks are one of the major causes behind OutOfMemoryError issues during Tomcat hotdeployments.
    把Tomcat降級(jí)到低版本(6.0.23以下),雖然不會(huì)報(bào)錯(cuò),但是還是存在內(nèi)存益出的問(wèn)題,這并不是一個(gè)好的解決方案。

  3. Move the JDBC driver to Tomcat's /lib folder and have a connection pooled datasource to manage the driver. Note that Tomcat's builtin DBCP does not deregister drivers properly on close. See also bug DBCP-322 which is closed as WONTFIX. You would rather like to replace DBCP by another connection pool which is doing its job better then DBCP. For exampleHikariCPBoneCP, or perhaps Tomcat JDBC Pool.
    把驅(qū)動(dòng)文件移到Tomcat/lib文件夾下,不用使用DBCP,使用以下的連接池庫(kù),HikariCP, BoneCP,或者Tomcat JDBC Pool.

  4. MAVEN項(xiàng)目

    If you are getting this message from a Maven built war change the scope of the JDBC driver to provided, and put a copy of it in the lib directory. Like this:<dependency>,
    對(duì)于MAVEN項(xiàng)目,由于Tomcat中存在mysql驅(qū)動(dòng)文件(1中介紹),這樣在部署時(shí)就不會(huì)把mysql帶到打包文件里,注意是<scope>provided</scope>。

      <groupId>mysql</groupId>
      
    <artifactId>mysql-connector-java</artifactId>
      
    <version>5.1.18</version>
      
    <!-- put a copy in /usr/share/tomcat7/lib -->
      
    <scope>provided</scope>
    </dependency>
好了,如果您遇到同樣的問(wèn)題,可以和我溝通,聯(lián)系方式見(jiàn)頭部。

草原上的駱駝 2016-08-03 10:59 發(fā)表評(píng)論
]]>
MAVEN命令不斷完善中。。。http://m.tkk7.com/nkjava/archive/2016/02/15/429325.html草原上的駱駝草原上的駱駝Mon, 15 Feb 2016 09:13:00 GMThttp://m.tkk7.com/nkjava/archive/2016/02/15/429325.htmlhttp://m.tkk7.com/nkjava/comments/429325.htmlhttp://m.tkk7.com/nkjava/archive/2016/02/15/429325.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/429325.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/429325.html
http://www.mvnrepository.com  #中央倉(cāng)庫(kù)

mvn eclipse:eclipse  #生成eclipse配置文件
mvn clean package #打包項(xiàng)目
mvn clean install #安裝成本地庫(kù)
mvn clean install -DoutputDirectory=lib -Dsilent=true -Pmodules
mvn clean install -Pmodules #安裝指定的模塊到本地倉(cāng)庫(kù)
mvn jetty:run #運(yùn)行jetty
mvn tomcat7:run #運(yùn)行tomcat




mvn compile #編譯
mvn test #運(yùn)行測(cè)試




下載源碼和文檔
mvn -DdownloadJavadocs=true eclipse:eclipse
mvn -DdownloadSources=true eclipse:eclipse
mvn archetype:generate -DgroupId=cn.ourwill.maven -DartifactId=hello-world -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false   #mvn 創(chuàng)建項(xiàng)目

mvn install -Dmaven.test.skip=true#不執(zhí)行測(cè)試




環(huán)境分離
<profiles>
        <profile>
            <id>mine</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <filters>
                    <filter>src/main/filters/filter-mine.properties</filter>
                </filters>
            </build>
        </profile>
        <profile>
            <id>test</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <filters>
                    <filter>src/main/filters/filter-test.properties</filter>
                </filters>
            </build>
        </profile>
        <profile>
            <id>release</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <filters>
                    <filter>src/main/filters/filter-release.properties</filter>
                </filters>
            </build>
        </profile>
    </profiles>

mvn install -Denvironment.type=prod  #使用不同的環(huán)境,生產(chǎn)環(huán)境,開(kāi)發(fā)環(huán)境,測(cè)試環(huán)境  

mvn install:install-file -Dfile=Sample.jar -DgroupId=uniquesample -DartifactId=sample_jar -Dversion=2.1.3b2 -Dpackaging=jar -DgeneratePom=true  #安裝到本地

mvn dependency:tree #依賴(lài)樹(shù)
mvn dependencies: copy-dependency #復(fù)制依賴(lài)的jar包



生成java-doc
mvn javadoc:javadoc
mvn javadoc:jar
mvn javadoc:aggregate
mvn javadoc:aggregate-jar
mvn javadoc:test-javadoc
mvn javadoc:test-jar
mvn javadoc:test-aggregate
mvn javadoc:test-aggregate-jar



生成jar
mvn jar:jar
mvn jar:test-jar



說(shuō)明文檔
1. mvn help:describe -Dplugin=eclipse -Dfull > eclipse-help.txt
2. mvn help:describe -Dplugin=help -Dfull > help-help.txt
3. mvn help:describe -Dplugin=dependency -Dfull > dependency-help.txt
4. mvn help:describe -Dcmd=compiler:compile –Ddetail
5. mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin

GRADLE命令

草原上的駱駝 2016-02-15 17:13 發(fā)表評(píng)論
]]>
Row was updated or deleted by another transactionhttp://m.tkk7.com/nkjava/archive/2010/08/11/328555.html草原上的駱駝草原上的駱駝Wed, 11 Aug 2010 08:48:00 GMThttp://m.tkk7.com/nkjava/archive/2010/08/11/328555.htmlhttp://m.tkk7.com/nkjava/comments/328555.htmlhttp://m.tkk7.com/nkjava/archive/2010/08/11/328555.html#Feedback1http://m.tkk7.com/nkjava/comments/commentRss/328555.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/328555.html javax.persistence.OptimisticLockException
    at org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:627)
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:588)
    at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:244)
    at org.jboss.jpa.tx.TransactionScopedEntityManager.merge(TransactionScopedEntityManager.java:193)
    at hanvon.ebook.persistence.general.JPAPrimaryKeyObjectDAO.update(JPAPrimaryKeyObjectDAO.java:91)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
    at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
    at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
    at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
    at sun.reflect.GeneratedMethodAccessor967.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
    at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_24570304.invoke(InvocationContextInterceptor_z_fillMethod_24570304.java)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
    at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_24570304.invoke(InvocationContextInterceptor_z_setup_24570304.java)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
    at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:176)
    at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:216)
    at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
    at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
    at $Proxy784.update(Unknown Source)
    at hanvon.ebook.business.info.impl.InfoManagerBean.updateInfoNoQuestion(InfoManagerBean.java:101)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
    at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
    at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
    at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
    at sun.reflect.GeneratedMethodAccessor967.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
    at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_24570304.invoke(InvocationContextInterceptor_z_fillMethod_24570304.java)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
    at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_24570304.invoke(InvocationContextInterceptor_z_setup_24570304.java)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
    at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:421)
    at org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:85)
    at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
    at $Proxy1309.invoke(Unknown Source)
    at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
    at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
    at $Proxy1246.updateInfoNoQuestion(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.remoting.rmi.RmiClientInterceptorUtils.invokeRemoteMethod(RmiClientInterceptorUtils.java:110)
    at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.doInvoke(SimpleRemoteSlsbInvokerInterceptor.java:99)
    at org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.invokeInContext(AbstractRemoteSlsbInvokerInterceptor.java:141)
    at org.springframework.ejb.access.AbstractSlsbInvokerInterceptor.invoke(AbstractSlsbInvokerInterceptor.java:189)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy1247.updateInfoNoQuestion(Unknown Source)
    at hanvon.ebook.web.info.service.InfoService.updateInfoNoQuestion(InfoService.java:77)
    at hanvon.ebook.web.info.action.InfoAction.addOrEditInfo(InfoAction.java:356)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
    at hanvon.ebook.web.interceptor.PermissionInterceptor.intercept(PermissionInterceptor.java:34)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at hanvon.ebook.web.interceptor.EbookLogonInterceptor.intercept(EbookLogonInterceptor.java:32)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:306)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [hanvon.ebook.persistence.po.Info#123]
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:313)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:167)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:81)
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:704)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:688)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:692)
    at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:235)
    ... 197 more


EJB+hibernate, table has "version", 在對(duì)一條數(shù)據(jù)進(jìn)行插入時(shí)手動(dòng)設(shè)置了version的值, 沒(méi)有問(wèn)題。
但是在對(duì)條數(shù)據(jù)進(jìn)行更新操作時(shí)卻報(bào)錯(cuò)了:org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect):
需要在更新的的頁(yè)面?zhèn)鬟fversion字段同時(shí)設(shè)計(jì)隱藏,<s:hidden name="info.version"></s:hidden>
這樣就解決了問(wèn)題。

草原上的駱駝 2010-08-11 16:48 發(fā)表評(píng)論
]]>
Spring中常用的hql查詢(xún)方法(getHibernateTemplate())http://m.tkk7.com/nkjava/archive/2010/07/22/326836.html草原上的駱駝草原上的駱駝Thu, 22 Jul 2010 06:15:00 GMThttp://m.tkk7.com/nkjava/archive/2010/07/22/326836.htmlhttp://m.tkk7.com/nkjava/comments/326836.htmlhttp://m.tkk7.com/nkjava/archive/2010/07/22/326836.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/326836.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/326836.html一、find(String queryString);

      示例:this.getHibernateTemplate().find("from bean.User");

      返回所有User對(duì)象

二、find(String queryString , Object value);

      示例:this.getHibernateTemplate().find("from bean.User u where u.name=?", "test");

      或模糊查詢(xún):this.getHibernateTemplate().find("from bean.User u where u.name like ?", "%test%");

      返回name屬性值為test的對(duì)象(模糊查詢(xún),返回name屬性值包含test的對(duì)象)

三、find(String queryString, Object[] values);

      示例:String hql= "from bean.User u where u.name=? and u.password=?"

                this.getHibernateTemplate().find(hql, new String[]{"test", "123"});

      返回用戶(hù)名為test并且密碼為123的所有User對(duì)象

---------------------------------

四、findByExample(Object exampleEntity)

      示例:

             User u=new User();    

             u.setPassword("123");//必須 符合的條件但是這兩個(gè)條件時(shí)并列的(象當(dāng)于sql中的and)    

   u.setName("bb");    

       list=this.getHibernateTemplate().findByExample(u,start,max);  

      返回:用戶(hù)名為bb密碼為123的對(duì)象

五、findByExample(Object exampleEntity, int firstResult, int maxResults)

      示例:

    User u=new User();    

            u.setPassword("123");//必須 符合的條件但是這兩個(gè)條件時(shí)并列的(象當(dāng)于sql中的and)    

            u.setName("bb");    

            list=this.getHibernateTemplate().findByExample(u,start,max);    

      返回:滿(mǎn)足用戶(hù)名為bb密碼為123,自start起共max個(gè)User對(duì)象。(對(duì)象從0開(kāi)始計(jì)數(shù))

---------------------------------------------------

六、findByNamedParam(String queryString , String paramName , Object value)

    使用以下語(yǔ)句查詢(xún):

       String queryString = "select count(*) from bean.User u where u.name=:myName";

         String paramName= "myName";

         String value= "xiyue";

         this.getHibernateTemplate().findByNamedParam(queryString, paramName, value);

         System.out.println(list.get(0));

     返回name為xiyue的User對(duì)象的條數(shù)

七、findByNamedParam(String queryString , String[] paramName , Object[] value)

      示例:

         String queryString = "select count(*) from bean.User u where u.name=:myName and u.password=:myPassword";

         String[] paramName= new String[]{"myName", "myPassword"};

         String[] value= new String[]{"xiyue", "123"};

         this.getHibernateTemplate().findByNamedParam(queryString, paramName, value);

         返回用戶(hù)名為xiyue密碼為123的User對(duì)象

八、findByNamedQuery(String queryName)

      示例:

        1、首先需要在User.hbm.xml中定義命名查詢(xún)

             <hibernate-mapping>

                  <class>......</class>

                  <query name="queryAllUser"><!--此查詢(xún)被調(diào)用的名字-->

                       <![CDATA[

                            from bean.User

                        ]]>

                  </query>

             </hibernate-mapping>

         2、如下使用查詢(xún):

             this.getHibernateTemplate().findByNamedQuery("queryAllUser");

九、findByNamedQuery(String queryName, Object value)

      示例:

        1、首先需要在User.hbm.xml中定義命名查詢(xún)

             <hibernate-mapping>

                  <class>......</class>

                  <query name="queryByName"><!--此查詢(xún)被調(diào)用的名字-->

                       <![CDATA[

                            from bean.User u where u.name = ?

                        ]]>

                  </query>

             </hibernate-mapping>

         2、如下使用查詢(xún):

             this.getHibernateTemplate().findByNamedQuery("queryByName", "test");

十、findByNamedQuery(String queryName, Object[] value)

      示例:

        1、首先需要在User.hbm.xml中定義命名查詢(xún)

             <hibernate-mapping>

                  <class>......</class>

                  <query name="queryByNameAndPassword"><!--此查詢(xún)被調(diào)用的名字-->

                       <![CDATA[

                            from bean.User u where u.name =? and u.password =?

                        ]]>

                  </query>

             </hibernate-mapping>

         2、如下使用查詢(xún):

             String[] values= new String[]{"test", "123"};

             this.getHibernateTemplate().findByNamedQuery("queryByNameAndPassword" , values);

十一、findByNamedQueryAndNamedParam(String queryName, String paramName, Object value)

示例:

        1、首先需要在User.hbm.xml中定義命名查詢(xún)

             <hibernate-mapping>

                  <class>......</class>

                  <query name="queryByName"><!--此查詢(xún)被調(diào)用的名字-->

                       <![CDATA[

                            from bean.User u where u.name =:myName

                        ]]>

                  </query>

             </hibernate-mapping>

         2、如下使用查詢(xún):

             this.getHibernateTemplate().findByNamedQuery("queryByName" , "myName", "test");

十二、findByNamedQueryAndNamedParam(String queryName, String[] paramName, Object[] value)

             this.getHibernateTemplate().findByNamedQuery("queryByNameAndPassword" , names, values);

十三、findByValueBean(String queryString , Object value);

示例:

      1、定義一個(gè)ValueBean,屬性名必須和HSQL語(yǔ)句中的:后面的變量名同名,此處必須至少有兩個(gè)屬性,分別為myName和 myPassword,使用setter方法設(shè)置屬性值后

          ValueBean valueBean= new ValueBean();

          valueBean.setMyName("test");

          valueBean.setMyPasswrod("123");

      2、

          String queryString= "from bean.User u where u.name=:myName and u.password=:myPassword";

          this.getHibernateTemplate().findByValueBean(queryString , valueBean);

        

十四、findByNamedQueryAndValueBean(String queryName , Object value);

示例:

        1、首先需要在User.hbm.xml中定義命名查詢(xún)

             <hibernate-mapping>

                  <class>......</class>

                  <query name="queryByNameAndPassword"><!--此查詢(xún)被調(diào)用的名字-->

                       <![CDATA[

                            from bean.User u where u.name =:myName and u.password=:myPassword

                        ]]>

                  </query>

             </hibernate-mapping>

      2、定義一個(gè)ValueBean,屬性名必須和User.hbm.xml命名查詢(xún)語(yǔ)句中的:后面的變量名同名,此處必須至少有兩個(gè)屬性,分別為 myName和myPassword,使用setter方法設(shè)置屬性值后

          ValueBean valueBean= new ValueBean();

          valueBean.setMyName("test");

          valueBean.setMyPasswrod("123");

      3、

          String queryString= "from bean.User u where u.name=:myName and u.password=:myPassword";

          this.getHibernateTemplate().findByNamedQueryAndValueBean("queryByNameAndPassword", valueBean);



草原上的駱駝 2010-07-22 14:15 發(fā)表評(píng)論
]]>
struts2.1.6中的datatimepicker 設(shè)置http://m.tkk7.com/nkjava/archive/2009/05/28/278313.html草原上的駱駝草原上的駱駝Thu, 28 May 2009 03:30:00 GMThttp://m.tkk7.com/nkjava/archive/2009/05/28/278313.htmlhttp://m.tkk7.com/nkjava/comments/278313.htmlhttp://m.tkk7.com/nkjava/archive/2009/05/28/278313.html#Feedback2http://m.tkk7.com/nkjava/comments/commentRss/278313.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/278313.html <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-dojo-plugin</artifactId>
        <version>2.1.6</version>
        <type>jar</type>
            <scope>compile</scope>
</dependency>&nbsp;
=================
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<s:head theme="xhtml"/>
<sx:head parseContent="true"/>
<sx:datetimepicker name="dd" label="Order Date"/>

草原上的駱駝 2009-05-28 11:30 發(fā)表評(píng)論
]]>
JSF學(xué)習(xí)筆記開(kāi)始http://m.tkk7.com/nkjava/archive/2009/05/15/270935.html草原上的駱駝草原上的駱駝Fri, 15 May 2009 13:49:00 GMThttp://m.tkk7.com/nkjava/archive/2009/05/15/270935.htmlhttp://m.tkk7.com/nkjava/comments/270935.htmlhttp://m.tkk7.com/nkjava/archive/2009/05/15/270935.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/270935.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/270935.html

草原上的駱駝 2009-05-15 21:49 發(fā)表評(píng)論
]]>
struts2中如何獲取Session,HttpServletRequest,HttpServletResponsehttp://m.tkk7.com/nkjava/archive/2009/03/29/262733.html草原上的駱駝草原上的駱駝Sun, 29 Mar 2009 08:40:00 GMThttp://m.tkk7.com/nkjava/archive/2009/03/29/262733.htmlhttp://m.tkk7.com/nkjava/comments/262733.htmlhttp://m.tkk7.com/nkjava/archive/2009/03/29/262733.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/262733.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/262733.html
You can obtain the session attributes by asking the ActionContext or implementing SessionAware. Implementing SessionAware is preferred.

Ask the ActionContext

 

Map attibutes = ActionContext.getContext().getSession();

 

Implement SessionAware

The session attributes are available on the ActionContext instance, which is made available via ThreadLocal. _Preferred_

  • Ensure that servlet-config Interceptor is included in the Action's stack.
    • The default stack already includes servlet-config.
  • Edit the Action so that it implements the SessionAware interface.
    • The SessionAware interface expects a setSession method. You may wish to include a companion getSession method.
  • At runtime, call getSession to obtain a Map representing the session attributes.
  • Any changes made to the session Map are reflected in the actual HttpSessionRequest. You may insert and remove session attributes as needed.
  • Map parameters = this.getSession();
To unit test a SessionAware Action, create your own Map with the pertinent session attributes and call setSession as part of the test's setUp method.


2,How can we access the HttpServletRequest

You can obtain the request by asking the ActionContext or implementing ServletRequestAware. Implementing ServletRequestAware is preferred.

Ask the ActionContext

The request is available on the ActionContext instance, which is made available via ThreadLocal.
HttpServletRequest request = ServletActionContext.getRequest();

Implement ServletRequestAware

Preferred

  • Ensure that servlet-config Interceptor is included in the Action's stack.
    • The default stack already includes servlet-config.
  • Edit the Action so that it implements the ServletRequestAware interface.
    • The ServletRequestAware interface expects a setServletRequest method. You may wish to include a companion getServletRequest method.
  • At runtime, call getServletRequest to obtain a reference to the request object.
It is more difficult to test Actions with runtime dependencies on HttpServletRequest. Only implement ServletRequestAware as a last resort. If the use case cannot be solved by one of the other servet-config interfaces (ApplicationAware, SessionAware, ParameterAware), consider whether an custom Interceptor could be used instead of Action code. (Review how servlet-config works for examples of what can be done.)


3,How can we access the HttpServletResponse

You can obtain the request by asking the ActionContext or implementing ServletResponseAware. Implementing ServletResponseAware is preferred.

Ask the ActionContext


The response is available on the ActionContext instance, which is made available via ThreadLocal.
HttpServletResponse response = ServletActionContext.getResponse();

Implement ServletResponseAware


Preferred

  • Ensure that servlet-config Interceptor is included in the Action's stack.
    • The default stack already includes servlet-config.
  • Edit the Action so that it implements the ServletResponseAware interface.
    • The ServletResponseAware interface expects a setServletResponse method. You may wish to include a companion getServletResponse method.
  • At runtime, call getServletResponse to obtain a reference to the response object.
t is more difficult to test Actions with runtime dependencies on HttpServletReponse. Only implement ServletResponseAware as a last resort. A better approach to solving a use case involving the response may be with a custom Result Type.

草原上的駱駝 2009-03-29 16:40 發(fā)表評(píng)論
]]>
No mapping found for dependency [type=java.lang.String, name='actionPackages'] http://m.tkk7.com/nkjava/archive/2009/03/29/262705.html草原上的駱駝草原上的駱駝Sun, 29 Mar 2009 03:33:00 GMThttp://m.tkk7.com/nkjava/archive/2009/03/29/262705.htmlhttp://m.tkk7.com/nkjava/comments/262705.htmlhttp://m.tkk7.com/nkjava/archive/2009/03/29/262705.html#Feedback5http://m.tkk7.com/nkjava/comments/commentRss/262705.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/262705.html     at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:132)
    at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
    at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:507)
    at com.opensymphony.xwork2.inject.ContainerImpl$8.call(ContainerImpl.java:540)
    at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574)
    at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:538)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:198)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
    at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
    at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:620)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1233)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)
    at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:124)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo.restartWebApp(AbstractJettyRunMojo.java:441)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo$1.filesChanged(AbstractJettyRunMojo.java:402)
    at org.mortbay.util.Scanner.reportBulkChanges(Scanner.java:486)
    at org.mortbay.util.Scanner.reportDifferences(Scanner.java:352)
    at org.mortbay.util.Scanner.scan(Scanner.java:280)
    at org.mortbay.util.Scanner$1.run(Scanner.java:232)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
Caused by: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:495)
    at com.opensymphony.xwork2.inject.ContainerImpl$7.call(ContainerImpl.java:532)
    at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:581)
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:530)
    at com.opensymphony.xwork2.config.impl.LocatableFactory.create(LocatableFactory.java:32)
    at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:130)
    ... 27 more
Caused by: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:144)
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMethods(ContainerImpl.java:113)
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:90)
    at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:71)
    at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:69)
    at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
    at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
    at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.<init>(ContainerImpl.java:348)
    at com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:305)
    at com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:304)
    at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
    at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
    at com.opensymphony.xwork2.inject.ContainerImpl.getConstructor(ContainerImpl.java:594)
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:491)
    ... 32 more
Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
    at com.opensymphony.xwork2.inject.ContainerImpl.createParameterInjector(ContainerImpl.java:235)
    at com.opensymphony.xwork2.inject.ContainerImpl.getParametersInjectors(ContainerImpl.java:225)
    at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.<init>(ContainerImpl.java:287)
    at com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:117)
    at com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:115)
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:141)
    ... 51 more
2009-03-29 11:23:51.305::WARN:  Failed startup of context org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@8932e8{/ssh,D:"workplace"ssh"src"main"webapp}
java.lang.RuntimeException: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
    at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:132)
    at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
    at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:507)
    at com.opensymphony.xwork2.inject.ContainerImpl$8.call(ContainerImpl.java:540)
    at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574)
    at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:538)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:198)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
    at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
    at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:620)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1233)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)
    at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:124)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo.restartWebApp(AbstractJettyRunMojo.java:441)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo$1.filesChanged(AbstractJettyRunMojo.java:402)
    at org.mortbay.util.Scanner.reportBulkChanges(Scanner.java:486)
    at org.mortbay.util.Scanner.reportDifferences(Scanner.java:352)
    at org.mortbay.util.Scanner.scan(Scanner.java:280)
    at org.mortbay.util.Scanner$1.run(Scanner.java:232)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
Caused by: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:495)
    at com.opensymphony.xwork2.inject.ContainerImpl$7.call(ContainerImpl.java:532)
    at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:581)
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:530)
    at com.opensymphony.xwork2.config.impl.LocatableFactory.create(LocatableFactory.java:32)
    at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:130)
    ... 27 more
Caused by: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:144)
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMethods(ContainerImpl.java:113)
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:90)
    at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:71)
    at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:69)
    at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
    at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
    at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.<init>(ContainerImpl.java:348)
    at com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:305)
    at com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:304)
    at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
    at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
    at com.opensymphony.xwork2.inject.ContainerImpl.getConstructor(ContainerImpl.java:594)
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:491)
    ... 32 more
Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String).
    at com.opensymphony.xwork2.inject.ContainerImpl.createParameterInjector(ContainerImpl.java:235)
[INFO] Restart completed at Sun Mar 29 11:23:51 CST 2009
    at com.opensymphony.xwork2.inject.ContainerImpl.getParametersInjectors(ContainerImpl.java:225)
    at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.<init>(ContainerImpl.java:287)
    at com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:117)
    at com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:115)
    at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:141)
    ... 51 more

出現(xiàn)這個(gè)問(wèn)題,可能是添加了struts2-codebehind包,去除這個(gè)包就可以了

草原上的駱駝 2009-03-29 11:33 發(fā)表評(píng)論
]]>
Eclipse+Maven+jetty+Struts2+Hibernate3開(kāi)發(fā)注冊(cè)登陸模塊http://m.tkk7.com/nkjava/archive/2009/03/26/262198.html草原上的駱駝草原上的駱駝Thu, 26 Mar 2009 10:59:00 GMThttp://m.tkk7.com/nkjava/archive/2009/03/26/262198.htmlhttp://m.tkk7.com/nkjava/comments/262198.htmlhttp://m.tkk7.com/nkjava/archive/2009/03/26/262198.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/262198.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/262198.html今天在blog上看到 http://m.tkk7.com/rongxh7/archive/2008/11/29/243456.html 這個(gè)帖子,其中開(kāi)發(fā)工具是Myeclipse,  這段時(shí)間很少寫(xiě)代碼, 閑來(lái)無(wú)事就把他的代碼整合一下,放在我用的平臺(tái)上,很順利,希望能給大家有所幫助。

開(kāi)發(fā)平臺(tái):Eclipse3.4+maven2.0
我安裝Eclipse了maven插件,也可以不安裝, 用maven生成了maven-archetype-webapp項(xiàng)目,首先先手動(dòng)的把所有的目錄補(bǔ)充好,下圖為我的程序目錄。


其中pom.xml如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation
="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  
<modelVersion>4.0.0</modelVersion>
  
<groupId>cn.edu.nku</groupId>
  
<artifactId>blog</artifactId>
  
<packaging>war</packaging>
  
<version>0.0.1-SNAPSHOT</version>
  
<name>blog Maven Webapp</name>
  
<url>http://maven.apache.org</url>
  
<dependencies>
    
<dependency>
      
<groupId>junit</groupId>
      
<artifactId>junit</artifactId>
      
<version>3.8.1</version>
      
<scope>test</scope>
    
</dependency>
    
<dependency>
        
<groupId>org.apache.struts</groupId>
        
<artifactId>struts2-core</artifactId>
        
<version>2.1.6</version>
        
<scope>compile</scope>
    
</dependency>
    
<dependency>
        
<groupId>org.hibernate</groupId>
        
<artifactId>hibernate</artifactId>
        
<version>3.2.6.ga</version>
        
<scope>compile</scope>
    
</dependency>
    
<dependency>
        
<groupId>mysql</groupId>
        
<artifactId>mysql-connector-java</artifactId>
        
<version>5.1.6</version>
        
<type>jar</type>
        
<scope>compile</scope>
    
</dependency>
  
</dependencies>
  
<build>
    
<finalName>blog</finalName>
    
<plugins>
        
<plugin>
            
<groupId>org.mortbay.jetty</groupId>
            
<artifactId>maven-jetty-plugin</artifactId>
            
<version>6.1.15.pre0</version>
        
</plugin>
        
<plugin>
            
<groupId>org.apache.maven.plugins</groupId>
            
<artifactId>maven-compiler-plugin</artifactId>
            
<version>2.0.2</version>
            
<configuration>
                    
<source>1.5</source>
                    
<target>1.5</target>
                    
<encoding>UTF-8</encoding>
                
</configuration>
            
        
</plugin>
    
</plugins>
  
</build>
</project>


在windows操作系統(tǒng)下(當(dāng)然linux也可以,linux是在終端下)cd到項(xiàng)目的目錄,mvn jetty:run, 即可看到系統(tǒng)。
源碼付在下面,請(qǐng)大家參考。
用eclipse導(dǎo)入后,修改hibernate.cfg.xml里面的mysql的配置,首先要先建立相應(yīng)的數(shù)據(jù)庫(kù),然后運(yùn)行cn.edu.nku.common.ExportDB.java生成數(shù)據(jù)庫(kù)里的表,。


有一點(diǎn)還希望大家能給出指點(diǎn),用maven+jetty部署項(xiàng)目, 每次都要關(guān)閉jetty,然后再運(yùn)行mvn jetty:run,才能重新部署,不知道有沒(méi)有好的辦法,進(jìn)行熱部署。希望高人能指點(diǎn)迷津。


源碼下載



草原上的駱駝 2009-03-26 18:59 發(fā)表評(píng)論
]]>
記事貼2:Struts的Validator并不好用!轉(zhuǎn)載http://m.tkk7.com/nkjava/archive/2009/03/19/260848.html草原上的駱駝草原上的駱駝Thu, 19 Mar 2009 09:45:00 GMThttp://m.tkk7.com/nkjava/archive/2009/03/19/260848.htmlhttp://m.tkk7.com/nkjava/comments/260848.htmlhttp://m.tkk7.com/nkjava/archive/2009/03/19/260848.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/260848.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/260848.html 記事貼2:Struts的Validator并不好用! 2005年 02月01日 使用正則表達(dá)式,使email字段中不能輸入漢字。最近用AppFuse開(kāi)發(fā)一個(gè)BS的系統(tǒng), 用的是Struts的MVC部分,使用Validator進(jìn)行驗(yàn)證,結(jié)果發(fā)現(xiàn)Validator的驗(yàn)證EMail并不好,EMail中可以輸入漢字,然后 到服務(wù)器端驗(yàn)證,我配置了客戶(hù)端驗(yàn)證,也可以驗(yàn)證Email的格式,但如果輸入的是正確的格式,但是包含漢字它卻驗(yàn)證不出來(lái),但到了后臺(tái)又管用了,不知道 為什么,時(shí)間緊,我也沒(méi)時(shí)間去研究它,找到一個(gè)方法可以解決這個(gè)問(wèn)題,雖不完美,卻也湊合:

使用正則表達(dá)式,將原代碼
            <html:text property="email" styleId="email" size="50"/>
注釋?zhuān)瑩Q成

            <input type="text" name="email" value='<c:out value="${userForm.email}"/>' onkeyup="value=value.replace(/["u4E00-"u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/["u4E00-"u9FA5]/g,''))"
 />
就解決了問(wèn)題,用戶(hù)如果輸入漢字,則自動(dòng)刪除漢字,而且如果使用向左的箭頭向前移動(dòng)使光標(biāo)前移,則根本移動(dòng)不了,光標(biāo)始終在行尾,只能刪除后面的字符,再重新寫(xiě),其實(shí)最好是在EMail的自動(dòng)生成的腳本中提示,目前先這樣實(shí)現(xiàn)吧,將來(lái)再說(shuō)!

草原上的駱駝 2009-03-19 17:45 發(fā)表評(píng)論
]]>
hibernate的 fetch lazy inverse cascadehttp://m.tkk7.com/nkjava/archive/2009/03/09/258655.html草原上的駱駝草原上的駱駝Mon, 09 Mar 2009 11:41:00 GMThttp://m.tkk7.com/nkjava/archive/2009/03/09/258655.htmlhttp://m.tkk7.com/nkjava/comments/258655.htmlhttp://m.tkk7.com/nkjava/archive/2009/03/09/258655.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/258655.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/258655.html1.fetch 和 lazy 主要用于級(jí)聯(lián)查詢(xún)(select) 而 inverse和cascade主要用于級(jí)聯(lián)增、加刪、除修改(sava-update,delete)
2.想要?jiǎng)h除父表中的記錄,但希望子表中記錄的外鍵引用值設(shè)為null的情況:
   父表的映射文件應(yīng)該如下配置:
        <set name="emps" inverse="false" cascade="all">
            <key>
                <column name="DEPTNO" precision="2" scale="0" />
            </key>
            <one-to-many class="com.sino.hibernate.Emp" />
        </set>
    inverse="false"是必須的,cascade可有可無(wú),并且子表的映射文件中inverse沒(méi)必要設(shè)置,cascade也可以不設(shè)置,如果設(shè)置就設(shè)置成為cascade="none"或者cascade="sava-update"
<many-to-one name="dept" class="com.sino.hibernate.Dept" fetch="select" cascade="save-update">
            <column name="DEPTNO" precision="2" scale="0" />
        </many-to-one>

3.關(guān)于級(jí)聯(lián)查找
  對(duì)子表的持久化類(lèi)進(jìn)行查找的時(shí)候,會(huì)一起把子表持久化類(lèi)中的父表持久化類(lèi)的對(duì)象一起查詢(xún)出來(lái),在頁(yè)面中可以直接取值的情況:
    要把父表的映射文件中設(shè)置 lazy 屬性如下:
<class name="com.sino.hibernate.Emp" table="EMP" schema="SCOTT" lazy="false">
這樣就可以直接在頁(yè)面中取值 (類(lèi)似于這樣的取值 client.cmanager.id)
如果沒(méi)有設(shè)置 lazy="false" 則會(huì)拋出異常
javax.servlet.ServletException: Exception thrown by getter for property cmanager.realName of bean cl
在Action中取值的話(huà)就會(huì)拋出
could not initialize proxy - the owning Session was closed的異常

草原上的駱駝 2009-03-09 19:41 發(fā)表評(píng)論
]]>
JPA annotation 筆記http://m.tkk7.com/nkjava/archive/2009/02/22/256123.html草原上的駱駝草原上的駱駝Sun, 22 Feb 2009 14:08:00 GMThttp://m.tkk7.com/nkjava/archive/2009/02/22/256123.htmlhttp://m.tkk7.com/nkjava/comments/256123.htmlhttp://m.tkk7.com/nkjava/archive/2009/02/22/256123.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/256123.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/256123.html
@GeneratedValue:主鍵的產(chǎn)生策略,通過(guò)strategy屬性指定。
默認(rèn)情況下,JPA自動(dòng)選擇一個(gè)最適合底層數(shù)據(jù)庫(kù)的主鍵生成策略,如SqlServer對(duì)應(yīng)identity,MySql對(duì)應(yīng)auto increment。
在javax.persistence.GenerationType中定義了以下幾種可供選擇的策略:
1) IDENTITY:表自增鍵字段,Oracle不支持這種方式;
2) AUTO: JPA自動(dòng)選擇合適的策略,是默認(rèn)選項(xiàng);
3) SEQUENCE:通過(guò)序列產(chǎn)生主鍵,通過(guò)@SequenceGenerator注解指定序列名,MySql不支持這種方式;
4) TABLE:通過(guò)表產(chǎn)生主鍵,框架借由表模擬序列產(chǎn)生主鍵,使用該策略可以使應(yīng)用更易于數(shù)據(jù)庫(kù)移植。

這里我重點(diǎn)來(lái)說(shuō)下GenerationType.TABLE的情況。
把庫(kù)表的主鍵auto_increment去掉
CREATE TABLE `t_creditcard` (   
  `id` int(11) NOT NULL,   
  `cardName` varchar(20) NOT NULL,   
  PRIMARY KEY  (`id`)   
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `id_gen` (
  `gen_name` varchar(80) NOT NULL default '',
  `gen_val` int(11) default NULL,
  PRIMARY KEY  (`gen_name`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;

@Entity
@Table(name="t_creditcard")
public class CreditCard{
    @TableGenerator(name = "CardPkGen",
              table = "ID_GEN",
              pkColumnName = "GEN_NAME",
              pkColumnValue = "Card_Gen",
              valueColumnName = "GEN_VAL",
              allocationSize = 1
    )
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE,generator="CardPkGen")
    private Long id;


@GeneratedValue:定義主鍵生成策略,這里因?yàn)槭褂玫氖荰ableGenerator,所以,主鍵的生成策略為GenerationType.TABLE,生成主鍵策略的名稱(chēng)則為前面定義的"CardPkGen”。
@TableGenerator各屬性含義如下:
name:表示該表主鍵生成策略的名稱(chēng),這個(gè)名字可以自定義,它被引用在@GeneratedValue中設(shè)置的"generator"值中
table:表示表生成策略所持久化的表名,說(shuō)簡(jiǎn)單點(diǎn)就是一個(gè)管理其它表主鍵的表,本例中,這個(gè)表名為ID_GEN
pkColumnName:表生成器中的列名,用來(lái)存放其它表的主鍵鍵名,一般來(lái)說(shuō)一個(gè)主鍵鍵名對(duì)應(yīng)一張其他表要獲取主鍵值對(duì)應(yīng)的key。這個(gè)值要與數(shù)據(jù)庫(kù)的列對(duì)應(yīng),比如GEN_NAME對(duì)應(yīng)id_gen中的主鍵名稱(chēng)
pkColumnValue:該實(shí)體所要訪(fǎng)問(wèn)對(duì)應(yīng)主鍵生成表的主鍵的key值
valueColumnName:表生成器所要對(duì)應(yīng)pkColumnName主鍵的下一個(gè)值,這個(gè)值也要和表生成器中的列名對(duì)應(yīng)
allocationSize:表示每次主鍵值增加的大小,例如設(shè)置成1,則表示每次創(chuàng)建新記錄后自動(dòng)加1,默認(rèn)為50

按照以上結(jié)構(gòu),如果我們執(zhí)行:
CreditCard cc = new CreditCard();
cc.setCardName("測(cè)試卡");
cc = ccDao.persist(cc);



表id_gen內(nèi)的數(shù)據(jù)為

GEN_NAME GEN_VALUE
Card_Gen  2

表t_creditcard內(nèi)的數(shù)據(jù)為

ID CARDNAME
1   測(cè)試卡

再執(zhí)行一次程序
表id_gen內(nèi)的數(shù)據(jù)為

GEN_NAME GEN_VALUE
Card_Gen  3

表t_creditcard內(nèi)的數(shù)據(jù)為

ID CARDNAME
1   測(cè)試卡
2   測(cè)試卡

把實(shí)體類(lèi)的annation改寫(xiě)為:
@Entity
@Table(name="t_creditcard")
public class CreditCard{
    @TableGenerator(name = "CardPkGen",
              table = "ID_GEN",
              pkColumnName = "GEN_NAME",
              pkColumnValue = "Card_Gen2",
              valueColumnName = "GEN_VAL",
              allocationSize = 1
    )
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE,generator="CardPkGen")
    private Long id;


注意看,pkColumnValue已經(jīng)被改為Card_Gen2。

執(zhí)行程序,插入數(shù)據(jù)失敗,拋出t_creditcard表主鍵重復(fù)的異常,因?yàn)檫@次去名為Card_Gen2的這個(gè)主鍵生成器去拿來(lái)的id為1,t_creditcard表之前已經(jīng)插入過(guò)一條主鍵為1的數(shù)據(jù)了。

表id_gen內(nèi)的數(shù)據(jù)為

GEN_NAME GEN_VALUE
Card_Gen  3
Card_Gen2  2

表t_creditcard內(nèi)的數(shù)據(jù)還是為

ID CARDNAME
1   測(cè)試卡
2   測(cè)試卡

結(jié)論:在有些應(yīng)用中,我們可以適用@TableGenerator來(lái)統(tǒng)一管理我們數(shù)據(jù)庫(kù)中的各個(gè)表的主鍵生成,如果我們的應(yīng)用中有10個(gè)實(shí)體需要使用自動(dòng)生成的主鍵,只需在每個(gè)實(shí)體中使用@TableGenerator并給出不同的pkColumnValue值就可以了。

@Id還有一些另類(lèi)的用法:

1.使用系統(tǒng)毫秒數(shù)作為主鍵
@Id
private Long id = System.currentTimeMillis();
CreditCard cc = new CreditCard();
cc.setCardName("測(cè)試卡");
cc = ccDao.persist(cc);


2.使用UUID作為主鍵
@Id
private String id;;

CreditCard cc = new CreditCard();
cc.setId(UUID.randomUUID().toString());
cc.setCardName("測(cè)試卡");
cc = ccDao.persist(cc);



別忘了修改庫(kù)表中主鍵字段的大小和對(duì)應(yīng)的類(lèi)型.

草原上的駱駝 2009-02-22 22:08 發(fā)表評(píng)論
]]>
A Blog Application with Warp (continued)(2)http://m.tkk7.com/nkjava/archive/2009/02/17/255131.html草原上的駱駝草原上的駱駝Tue, 17 Feb 2009 08:30:00 GMThttp://m.tkk7.com/nkjava/archive/2009/02/17/255131.htmlhttp://m.tkk7.com/nkjava/comments/255131.htmlhttp://m.tkk7.com/nkjava/archive/2009/02/17/255131.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/255131.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/255131.html

A Blog Application with Warp (continued)

First check out the previous tutorial on creating a Blog application to get yourself going. In this article, I'll show you how to add forms and a bit of interactivity. You will learn the following Warp concepts:

  • Event Handling and Navigation
  • Events and the Button component
  • The TextField and TextArea components
  • Page scopes

Continuing from the previous tutorial, let's now make a "compose new entry" page. This will be very similar to the other pages with some different components:

<html>

<head w:component="meta">
<title>Warp :: Compose New Blog Entry</title>
</head>

  <body w:component="frame">

<input w:component="textfield" w:bind="newBlog.subject" />
<input w:component="textarea" w:bind="newBlog.text" />

<input w:component="button" w:label="post blog" />
</body>

</html> 

The first important part to notice is that the <head> tag is decorated with a Meta component. This is very important indeed--along with the Frame component on <body>, Meta forms the foundation for Warp page behavior.

The other things to notice are the input components. TextField is a simple text box, we use the attribute w:bind to tell Warp where to bind the user input to. In this case I am giving it a path to a property of newBlog, which is a variable in my page object. OK, let's create ourselves this property:

@URIMapping("/blogs/compose")
public class ComposeBlog {
private Blog newBlog = new Blog("", ""); //an empty blog

@OnEvent
public void save() {
System.out.println(newBlog.getSubject() + " - "

+ newBlog.getText());
}
public Blog getNewBlog() {
return newBlog;
}
}

Here I have provided an event handler method named save(). By tagging it with the @OnEvent annotation, I have told Warp to invoke this method whenever the page triggers an event (in our case, the clicking of the button). First, the data is synchronized between the input components (TextField and TextArea) and the bound properties, then the event handler is fired which prints out their content.

Let's add some more functionality, where our list of blogs (from the previous tutorial) actually gets updated. For this we first need to add a method in ListBlogs that stores a new blog entry into the map. That part is easy enough:

@URIMapping("/home")
public class ListBlogs {
private Map<String, Blog> blogs = new HashMap<String, Blog>();

public ListBlogs() { .. }

public void addNewBlog(Blog blog) {
blogs.put(blog.getSubject(), blog);
}

//...

 Ok now let us invoke the store method from our compose page's event handler (remember Page-injection from the previous tutorial):

@URIMapping("/blogs/compose")
public class ComposeBlog {
private Blog newBlog = new Blog("", ""); //an empty blog

@Inject @Page ListBlogs listBlogs;

@OnEvent
public void save() {
listBlogs.addNewBlog(newBlog);
}

public Blog getNewBlog() {
return newBlog;
}
}

We're almost there, now when I save the entry, I want it to come back to the blog list. This follows the post-and-redirect design pattern common in web development. Warp supports this in an intuitive, type-safe manner. After saving the blog in my event handler, I simply return the page object that I want shown:

    @OnEvent
public ListBlogs save() {
listBlogs.addNewBlog(newBlog);

return listBlogs;

}

Neat! Now when you click the "post blog" button, it runs the save() method and redirects you to back to the blog list. You can return any type of object from an event handler so long as it is a page object (or a subclass of one). You can also redirect to an arbitrary URL or use JSP-style forwarding instead of post-and-redirect. Check out the Event Handling guide on the wiki for details.

One last step concerning Page scoping. Typically, Warp obtains an instance of a page object from the Guice injector on every request. This effectively means that any page object that is not bound (see Guice user guide for information on scopes) with a given scope is instantiated once per request. Since our HashMap is a property of the ListBlogs page, this means that when we redirect (in a new request), the Map gets blown away and we lose our new entry.

To fix this, we can scope the ListBlogs page object as a singleton. This means that ListBlogs is only created once for the lifetime of the webapp, and the Map of entries is retained.

@URIMapping("/home")
@Singleton
public class ListBlogs { .. }

You should be careful about relying on page objects to maintain state and do a lot of thinking before declaring a scope on a page.

The singleton scope is an easy fix for our example but in the real world you will want to store the blogs in a more permanent storage medium (such as a database or persistent store). In my next tutorial, we'll see how to do just that using JPA and Hibernate.

 


草原上的駱駝 2009-02-17 16:30 發(fā)表評(píng)論
]]>
A Blog Application with Wideplay's Warp Framework(1)http://m.tkk7.com/nkjava/archive/2009/02/17/255130.html草原上的駱駝草原上的駱駝Tue, 17 Feb 2009 08:29:00 GMThttp://m.tkk7.com/nkjava/archive/2009/02/17/255130.htmlhttp://m.tkk7.com/nkjava/comments/255130.htmlhttp://m.tkk7.com/nkjava/archive/2009/02/17/255130.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/255130.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/255130.htmlA Blog Application with Wideplay's Warp Framework

First check out the Hello World example to get yourself going. In this article, I'll show you how to knock together a simple Blog application where you can browse and read blog entries. You will learn the following Warp concepts:

  • Page Injection
  • RESTful behavior and the HyperLink component
  • The Table and Column components
  • Simple Internationalization (i18n)

First let's create ourselves a data model object representing a blog. This will be a simple POJO with 2 fields: subject and text.

public class Blog {

private String subject;

private String text;

//don't forget your getters/setters here...

}


OK, now we make a list page where you can see a list of all the blogs currently in the system. For simplicity, we will store blogs in a HashMap. The Page object class for this list should look something like this:

@URIMapping("/blogs")

public class ListBlogs {

private final Map<String, Blog> blogs = new HashMap<String, Blog>();



public ListBlogs() {

//setup a blog as dummy data

blog = new Blog("MyBlog", "Warp is so great...");

blogs.put(blog.getSubject(), blog);

}



public Collection<Blog> getBlogList() {

return blogs.values();

}

}



Note the @URIMapping annotation which tells warp to map this page object to the URI "/blogs". The getter for property blogList, simply returns a list of all the values contained in our HashMap of blogs. For the interesting part, let's make a template to layout our blogs:



<?xml version="1.0" encoding="UTF-8"?>

<html>



<head>

<title>Warp :: Blogs</title>

</head>



<body w:component="frame">

<h1>A list of blog entries</h1>



<table w:component="table" w:items="${blogList}"/>



</body>

</html>





This is a very simple template. Inside our body we have only one real component (Table) and we pass it our list of blogs in the w:items property that we declared above. Go ahead and run the app now and point your browser to: http://localhost:8080/blogs, you should see a table with 2 columns (subject and text) corresponding to the Blog data model object we declared above. Table is smart enough to inspect the items given it and construct an appropriate set of display columns. The rows of the table reflect the data in each instance of the Blog object in our HashMap. Nice!

OK, having the property names as the title of each column is not ideal--let's customize this. Customizing is as simple as adding a properties file in the same package as our Blog class, with the same name:

Blog.properties:

subject=Subject of Blog

text=Content



Now, run the app again and you should see the column names changed. In this way, you can also achieve internationalization (i18n). If you want to hide a property (i.e. not render a column for it), specify an empty key (so to hide subject, you would have just "subject=").

OK, let's create a view blog page now. This page will display one blog entry. Let's start with the view portion (called ViewBlog.html):

<?xml version="1.0" encoding="UTF-8"?>

<html>



<head w:component="meta">

<title>Reading :: ${blog.subject}</title>

</head>



<body w:component="frame">

<h1>Read...</h1>

<h3>${blog.subject}</h3>



${blog.text}



<a href="../home">back to list</a>

</body>

And its Page object:

@URIMapping("/blog")

public class ViewBlog {

private Blog blog;



//getters/setters...

}



Ok, this is fairly simple, but how does it know what blog to display? Let us use a RESTful idiom to achieve this. First, change your ViewBlog page object so that it takes a parameter indicating what blog to show:

@URIMapping("/blog/{subject}")

public class ViewBlog {

private Blog blog;



@OnEvent @PreRender

public void init(String subject) { .. }

}



Ok, this tells warp that when the URL http://localhost:8080/blog/myblog is requested, to inject anything matching the {subject} portion of the @URIMapping (in this case "myblog") to the @PreRender event handler method. Hold on, we're not done yet--we still need to obtain the appropriate blog from our HashMap which is stored in the ListBlogs page. This is done via page-injection:

@URIMapping("/blog/{subject}")

public class ViewBlog {

private Blog blog;



@Inject @Page private ListBlogs listBlogs;



@OnEvent @PreRender

public void init(String subject) {

this.blog = listBlogs.getBlog(subject);

}

}

Finally, we need to modify ListBlogs and give it a getBlog() method to fetch a Blog by subject:

@URIMapping("/blogs")

public class ListBlogs {

private Map<String, Blog> blogs = new HashMap<String, Blog>();



public ListBlogs() { .. }



public Collection<Blog> getBlogList() {

return blogs.values();

}



public Blog getBlog(String subject) {

return blogs.get(subject);

}


}


Ok, now let's wire the pages together so clicking on a blog in the list will take us to the view page for that blog. I want to make the subject of the blog clickable, so let's use the Column component to override the default behavior of table (which just prints out the subject as text):

<?xml version="1.0" encoding="UTF-8"?>

<html>



<head w:component="meta">

<title>Warp :: Blogs</title>

</head>



<body w:component="frame">

<h1>A list of blog entries</h1>



<table w:component="table" w:items="${blogList}" class="mytableCss">

<td w:component="column" w:property="subject">

<a w:component="hyperlink" w:target="/blog"


w:topic="${subject}">${subject}</a>

</td>


</table>



</body>

</html>





Notice that we nest the hyperlink component inside the column override. This tells the Table component not to draw the column, instead to use our overridden layout instead. The attribute w:target simply tells the hyperlink the URI that we're linking (in this case /blog, which is the ViewBlog's mapping) and w:topic tells hyperlink to append the subject of the blog to the URI. So for a blog entitled "MyBlog," Warp will generate a URI as follows: /blog/MyBlog. And "MyBlog" gets stripped out and injected into the ViewBlog page's @PreRender handler so it can set it up.

Also notice the addition of a non-Warp attribute class to the <table> tag, which refers to the CSS class I want to style my table with. This is a useful tool for both for previewability as well as the end result HTML--generally whatever HTML attributes you write on a component will be passed through the final rendered page.

Done!

草原上的駱駝 2009-02-17 16:29 發(fā)表評(píng)論
]]>
A Hello World Application in Warphttp://m.tkk7.com/nkjava/archive/2009/02/17/255127.html草原上的駱駝草原上的駱駝Tue, 17 Feb 2009 08:28:00 GMThttp://m.tkk7.com/nkjava/archive/2009/02/17/255127.htmlhttp://m.tkk7.com/nkjava/comments/255127.htmlhttp://m.tkk7.com/nkjava/archive/2009/02/17/255127.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/255127.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/255127.htmlGetting started with Wideplay's Warp Framework

First download warp and its dependencies from the link provided above. For convenience, dependencies are packaged along with the warp core library in a zip file named warp-with-deps.zip. Unzip and place the provided jars into your application's WEB-INF/lib folder. Create a web.xml file in WEB-INF, and add the following filter mapping to it:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4"

xmlns="http://java.sun.com/xml/ns/j2ee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >

	<context-param>

<param-name>warp.module</param-name>

<param-value>my.example.MyModule</param-value>
	</context-param>



<filter>

<filter-name>warp</filter-name>

<filter-class>com.wideplay.warp.WarpFilter</filter-class>

</filter>



<filter-mapping>

<filter-name>warp</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

</web-app>


Note that the parameter warp.module must specify the class name of your Warp Module class. This is typically a class that looks like so:

package my.example; 
public class MyModule implements WarpModule {
 	public void configure(Warp warp) {
		//nothing required yet

 	}

 

Now, this tells Warp to look in package my.example for page classes (and resources) to register to the runtime. Every class in the WarpModule's package and its sub-packages are considered candidates for page object registration (but only those that have corresponding templates are typically registered). You can also perform a lot of setup work in the WarpModule as we will see later on. 

In Warp, a page is represented by a page object, and any manipulation of that page or its state is driven from the page object. OK, let's create a simple page to say hello to the world:

package my.example;
public class Start {

private String message = "hello warp!";
 	//getter... 

public String getMessage() { return message; }   

 

In Warp, page objects are always be accompanied by a template (in this case a standard HTML template) to tell Warp how to decorate and layout the content in the page. As a convention, templates are named the same as page classes (in our case, Start.html in the / directory):

<?xml version="1.0" encoding="UTF-8"?>

<html xmlns:w="http://www.wideplay.com/warp/schema/warp_core.xsd"

xmlns="http://www.w3.org/1999/xhtml"

xml:lang="en" lang="en">



<head>

<title>Warp :: Hello World</title>

</head>



<body w:component="frame">

<p>
			${message}

</p>

</body>

</html>


Note that the only unusual part about this template is the attribute on body named w:component which tells Warp to decorate the <body> tag with a Frame component. The Frame component is used on nearly every page and is a kind of "wrapper" for the page (and should always be present on the <body> tag) which creates some necessary conditions for the rendering of the page by the Warp framework.

The other noteworthy part of the template is the ${message} expression, which is a property expression telling Warp to look into the corresponding page object for a property named message. If you look above, we've declared message as a String in our Start page class. 

You should now have a web application with roughly the following structure:

	/
	 - Start.html 
	 - WEB-INF/
		- web.xml
		+ lib/
		+ classes/

Running the web aplication and pointing your browser at http://localhost:8080/Start now will produce the following page output:



Contribute to the Warp Framework

Get involved! Email me on the Warp mailing list if you want to help or have a problem to report. Problems with Guice should be reported on the Guice user mailing list.

草原上的駱駝 2009-02-17 16:28 發(fā)表評(píng)論
]]>
Struts2.0的Struts.properties(轉(zhuǎn))http://m.tkk7.com/nkjava/archive/2009/02/14/254700.html草原上的駱駝草原上的駱駝Sat, 14 Feb 2009 13:09:00 GMThttp://m.tkk7.com/nkjava/archive/2009/02/14/254700.htmlhttp://m.tkk7.com/nkjava/comments/254700.htmlhttp://m.tkk7.com/nkjava/archive/2009/02/14/254700.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/254700.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/254700.htmlstruts.action.extension
          The URL extension to use to determine if the request is meant for a Struts action
           用URL擴(kuò)展名來(lái)確定是否這個(gè)請(qǐng)求是被用作Struts action,其實(shí)也就是設(shè)置 action的后綴,例如login.do的"'do"'字。

struts.configuration
          The org.apache.struts2.config.Configuration implementation class
            org.apache.struts2.config.Configuration接口名

struts.configuration.files
          A list of configuration files automatically loaded by Struts
           struts自動(dòng)加載的一個(gè)配置文件列表

struts.configuration.xml.reload
          Whether to reload the XML configuration or not
           是否加載xml配置(true,false)

struts.continuations.package
           The package containing actions that use Rife continuations
           含有actions的完整連續(xù)的package名稱(chēng)

struts.custom.i18n.resources
          Location of additional localization properties files to load
           加載附加的國(guó)際化屬性文件(不包含.properties后綴)

struts.custom.properties
          Location of additional configuration properties files to load
           加載附加的配置文件的位置


struts.devMode
          Whether Struts is in development mode or not
           是否為struts開(kāi)發(fā)模式

struts.dispatcher.parametersWorkaround
          Whether to use a Servlet request parameter workaround necessary for some versions of WebLogic
            (某些版本的weblogic專(zhuān)用)是否使用一個(gè)servlet請(qǐng)求參數(shù)工作區(qū)(PARAMETERSWORKAROUND)

struts.enable.DynamicMethodInvocation
          Allows one to disable dynamic method invocation from the URL
            允許動(dòng)態(tài)方法調(diào)用

struts.freemarker.manager.classname
          The org.apache.struts2.views.freemarker.FreemarkerManager implementation class
           org.apache.struts2.views.freemarker.FreemarkerManager接口名

struts.i18n.encoding
          The encoding to use for localization messages
           國(guó)際化信息內(nèi)碼

struts.i18n.reload
          Whether the localization messages should automatically be reloaded
           是否國(guó)際化信息自動(dòng)加載

struts.locale
          The default locale for the Struts application
           默認(rèn)的國(guó)際化地區(qū)信息

struts.mapper.class
          The org.apache.struts2.dispatcher.mapper.ActionMapper implementation class
            org.apache.struts2.dispatcher.mapper.ActionMapper接口

struts.multipart.maxSize
          The maximize size of a multipart request (file upload)
           multipart請(qǐng)求信息的最大尺寸(文件上傳用)

struts.multipart.parser
          The org.apache.struts2.dispatcher.multipart.
          MultiPartRequest parser implementation for a multipart request (file upload)
          專(zhuān)為multipart請(qǐng)求信息使用的org.apache.struts2.dispatcher.multipart.MultiPartRequest解析器接口(文件上傳用)


struts.multipart.saveDir
          The directory to use for storing uploaded files
           設(shè)置存儲(chǔ)上傳文件的目錄夾

struts.objectFactory
          The com.opensymphony.xwork2.ObjectFactory implementation class
           com.opensymphony.xwork2.ObjectFactory接口(spring)

struts.objectFactory.spring.autoWire
          Whether Spring should autoWire or not
           是否自動(dòng)綁定Spring

struts.objectFactory.spring.useClassCache
          Whether Spring should use its class cache or not
           是否spring應(yīng)該使用自身的cache

struts.objectTypeDeterminer
          The com.opensymphony.xwork2.util.ObjectTypeDeterminer implementation class
            com.opensymphony.xwork2.util.ObjectTypeDeterminer接口

struts.serve.static.browserCache
  If static content served by the Struts filter should set browser caching header properties or not
           是否struts過(guò)濾器中提供的靜態(tài)內(nèi)容應(yīng)該被瀏覽器緩存在頭部屬性中

struts.serve.static
          Whether the Struts filter should serve static content or not
           是否struts過(guò)濾器應(yīng)該提供靜態(tài)內(nèi)容

struts.tag.altSyntax
          Whether to use the alterative syntax for the tags or not
           是否可以用替代的語(yǔ)法替代tags

struts.ui.templateDir
          The directory containing UI templates
           UI templates的目錄夾

struts.ui.theme
          The default UI template theme
           默認(rèn)的UI template主題

struts.url.http.port
          The HTTP port used by Struts URLs
           設(shè)置http端口

struts.url.https.port
          The HTTPS port used by Struts URLs
           設(shè)置https端口

struts.url.includeParams
          The default includeParams method to generate Struts URLs
          在url中產(chǎn)生 默認(rèn)的includeParams

struts.velocity.configfile
          The Velocity configuration file path
           velocity配置文件路徑

struts.velocity.contexts
          List of Velocity context names
           velocity的context列表

struts.velocity.manager.classname
          org.apache.struts2.views.velocity.VelocityManager implementation class
           org.apache.struts2.views.velocity.VelocityManager接口名

struts.velocity.toolboxlocation
          The location of the Velocity toolbox
           velocity工具盒的位置

struts.xslt.nocache
          Whether or not XSLT templates should not be cached
           是否XSLT模版應(yīng)該被緩存



草原上的駱駝 2009-02-14 21:09 發(fā)表評(píng)論
]]>
Struts2.0標(biāo)簽庫(kù)(三)表單標(biāo)簽http://m.tkk7.com/nkjava/archive/2009/02/14/254699.html草原上的駱駝草原上的駱駝Sat, 14 Feb 2009 13:07:00 GMThttp://m.tkk7.com/nkjava/archive/2009/02/14/254699.htmlhttp://m.tkk7.com/nkjava/comments/254699.htmlhttp://m.tkk7.com/nkjava/archive/2009/02/14/254699.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/254699.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/254699.html閱讀全文

草原上的駱駝 2009-02-14 21:07 發(fā)表評(píng)論
]]>
Struts2.0標(biāo)簽庫(kù)(二)數(shù)據(jù)標(biāo)簽[轉(zhuǎn)]http://m.tkk7.com/nkjava/archive/2009/02/14/254698.html草原上的駱駝草原上的駱駝Sat, 14 Feb 2009 13:07:00 GMThttp://m.tkk7.com/nkjava/archive/2009/02/14/254698.htmlhttp://m.tkk7.com/nkjava/comments/254698.htmlhttp://m.tkk7.com/nkjava/archive/2009/02/14/254698.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/254698.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/254698.html閱讀全文

草原上的駱駝 2009-02-14 21:07 發(fā)表評(píng)論
]]>
struts2 標(biāo)簽學(xué)習(xí)http://m.tkk7.com/nkjava/archive/2009/02/14/254697.html草原上的駱駝草原上的駱駝Sat, 14 Feb 2009 13:05:00 GMThttp://m.tkk7.com/nkjava/archive/2009/02/14/254697.htmlhttp://m.tkk7.com/nkjava/comments/254697.htmlhttp://m.tkk7.com/nkjava/archive/2009/02/14/254697.html#Feedback3http://m.tkk7.com/nkjava/comments/commentRss/254697.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/254697.html閱讀全文

草原上的駱駝 2009-02-14 21:05 發(fā)表評(píng)論
]]>
SiteMesh學(xué)習(xí)筆記1(一個(gè)優(yōu)于Apache Tiles的Web頁(yè)面布局、裝飾框架)http://m.tkk7.com/nkjava/archive/2008/12/10/245559.html草原上的駱駝草原上的駱駝Wed, 10 Dec 2008 12:14:00 GMThttp://m.tkk7.com/nkjava/archive/2008/12/10/245559.htmlhttp://m.tkk7.com/nkjava/comments/245559.htmlhttp://m.tkk7.com/nkjava/archive/2008/12/10/245559.html#Feedback0http://m.tkk7.com/nkjava/comments/commentRss/245559.htmlhttp://m.tkk7.com/nkjava/services/trackbacks/245559.html OS(OpenSymphony)的SiteMesh是一個(gè)用來(lái)在JSP中實(shí)現(xiàn)頁(yè)面布局和裝飾(layout and decoration)
的框架組件,能夠幫助網(wǎng)站開(kāi)發(fā)人員較容易實(shí)現(xiàn)頁(yè)面中動(dòng)態(tài)內(nèi)容和靜態(tài)裝飾外觀(guān)的分離。

       Sitemesh是由一個(gè)基于Web頁(yè)面布局、裝飾以及與現(xiàn)存Web應(yīng)用整合的框架。它能幫助我們?cè)谟纱?br /> 量頁(yè)面構(gòu)成的項(xiàng)目中創(chuàng)建一致的頁(yè)面布局和外觀(guān),如一致的導(dǎo)航條,一致的banner,一致的版權(quán),等等。
它不僅僅能處理動(dòng)態(tài)的內(nèi)容,如jsp,php,asp等產(chǎn)生的內(nèi)容,它也能處理靜態(tài)的內(nèi)容,如htm的內(nèi)容,
使得它的內(nèi)容也符合你的頁(yè)面結(jié)構(gòu)的要求。甚至于它能將HTML文件象include那樣將該文件作為一個(gè)面板
的形式嵌入到別的文件中去。所有的這些,都是GOF的Decorator模式的最生動(dòng)的實(shí)現(xiàn)。盡管它是由java語(yǔ)言來(lái)實(shí)現(xiàn)的,但它能與其他Web應(yīng)用很好地集成。

  官方:http://www.opensymphony.com/sitemesh/

  下載地址:http://www.opensymphony.com/sitemesh/download.action 目前的最新版本是Version 2.3

本文介紹sitemesh的簡(jiǎn)單應(yīng)用:

首先下載 sitemesh.jar, 拷貝到你的WEB-INF/lib文件夾下,然后將一下代碼添加到你的web.xml下
<!-- sitemesh配置 -->
    
<filter>
        
<filter-name>sitemesh</filter-name>
        
<filter-class>             com.opensymphony.module.sitemesh.filter.PageFilter
        
</filter-class>
    
</filter>
    
<filter-mapping>
        
<filter-name>sitemesh</filter-name>
        
<url-pattern>/*</url-pattern>
    </filter-mapping>
(注意過(guò)濾器的位置:應(yīng)該在struts2的org.apache.struts2.dispatcher.FilterDispatcher過(guò)濾器之前 org.apache.struts2.dispatcher.ActionContextCleanUp過(guò)濾器之后,否則會(huì)有問(wèn)題;)
在WEB-INF下建立
decorators.xml文件,添加如下代碼:
<?xml version="1.0" encoding="utf-8"?>  
  
<decorators defaultdir="/WEB-INF/decorators">  
        
<!-- 此處用來(lái)定義不需要過(guò)濾的頁(yè)面 -->  
        
<excludes> 
<pattern>/login/*</pattern>
        </excludes>        
     
<!-- 用來(lái)定義裝飾器要過(guò)濾的頁(yè)面 -->  
    
<decorator name="main" page="main.jsp">  
        
<pattern>/*</pattern>  
   
</decorator>  
</decorators> 
decorators.xml有兩個(gè)主要的結(jié)點(diǎn):
       decorator結(jié)點(diǎn)指定了模板的位置和文件名,通過(guò)pattern來(lái)指定哪些路徑引用哪個(gè)模板
       excludes結(jié)點(diǎn)則指定了哪些路徑的請(qǐng)求不使用任何模板
上面代碼,凡是以/login/開(kāi)頭的請(qǐng)求路徑一律不使用模板;
decorators結(jié)點(diǎn)的defaultdir屬性指定了模板文件存放的目錄;



在WEB-INF下建立decorators文件夾,在下面建立main.jsp,代碼如下:
    <%@ page language="java" contentType="text/html; charset=utf-8"  
        pageEncoding
="utf-8"%>  
    
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>  
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 01 Transitional//EN" "http://www.worg/TR/html4/loose.dtd">  
    
<html>  
     
<!-- 第一個(gè)裝飾頁(yè)面 -->  
        
<head>  
     
<!-- 從被裝飾頁(yè)面獲取title標(biāo)簽內(nèi)容,并設(shè)置默認(rèn)值-->  
     
<title><decorator:title default="默認(rèn)title"/></title>  
<!-- 從被裝飾頁(yè)面獲取head標(biāo)簽內(nèi)容 -->  
 
<decorator:head/>  
</head>  

<body>  
   
<h2>SiteMesh裝飾header</h2>  
  
<hr />  
<!-- 從被裝飾頁(yè)面獲取body標(biāo)簽內(nèi)容 -->  
 
<decorator:body />  
 
<hr />  
 
<h2>SiteMesh裝飾footer</h2>  
 
</body>  
</html> 
這就是個(gè)簡(jiǎn)單的模板,頁(yè)面的頭和腳都由模板里的靜態(tài)HTML決定了,主頁(yè)面區(qū)域用的是<decorator:body />標(biāo)簽;
也就是說(shuō)凡是能進(jìn)入過(guò)濾器的請(qǐng)求生成的頁(yè)面都會(huì)默認(rèn)加上模板上的頭和腳,然后頁(yè)面自身的內(nèi)容將自動(dòng)放到<decorator:body />標(biāo)簽所在位置;

<decorator:title default="
默認(rèn)title" />:讀取被裝飾頁(yè)面的標(biāo)題,并給出了默認(rèn)標(biāo)題。
<decorator:head />:讀取被裝飾頁(yè)面的<head>中的內(nèi)容;
<decorator:body />:讀取被裝飾頁(yè)面的<body>中的內(nèi)容;



好了,下載可以建立頁(yè)面了,看看你的頁(yè)面是不是被sitemesh改變了呢?(建立index.jsp)瀏覽
    <%@ page language="java" contentType="text/html; charset=utf-8"  
        pageEncoding
="utf-8"%>  
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 01 Transitional//EN" "http://wwwworg/TR/html4/loosedtd">  
    
<html>  
     
<!-- 第一個(gè)被裝飾(目標(biāo))頁(yè)面  -->  
     
<head>  
     
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
     
<title>被裝飾(目標(biāo))頁(yè)面title</title>  
     
</head>  
      
    
<body>  
    
<h4>被裝飾(目標(biāo))頁(yè)面body標(biāo)簽內(nèi)內(nèi)容。</h4>  
    
<h3>使用SiteMesh的好處?</h3>  
    
<ul>  
        
<li>  
         
<li>很多很多</li>  
        
</ul>  
    
</body>  
   
</html> 



草原上的駱駝 2008-12-10 20:14 發(fā)表評(píng)論
]]>
主站蜘蛛池模板: 成人免费视频网站www| 久久久久久毛片免费播放| 亚洲尹人九九大色香蕉网站| 成人a毛片视频免费看| 亚洲精品动漫人成3d在线| 免费无毒a网站在线观看| 亚洲成av人片天堂网老年人| 青娱乐在线免费观看视频| 亚洲精品美女久久久久99小说| 污视频网站免费观看| 亚洲黄黄黄网站在线观看| 久久久久久久国产免费看| 成人亚洲性情网站WWW在线观看| 一级毛片视频免费| 久久精品国产69国产精品亚洲| 国产精品免费看久久久| 亚洲欧洲在线播放| 在线精品免费视频| a毛片成人免费全部播放| 久久久亚洲精品无码| 国产精品爱啪在线线免费观看| 亚洲日韩中文字幕无码一区| 免费jlzzjlzz在线播放视频| 精品人妻系列无码人妻免费视频| 亚洲成人在线网站| 成人毛片免费播放| 一个人看的www视频免费在线观看| 精品亚洲永久免费精品| 在线看片韩国免费人成视频| 亚洲精品无码永久在线观看男男| 免费国产高清视频| 男人的天堂网免费网站| 日本亚洲免费无线码 | 在线日韩日本国产亚洲| 日本免费电影一区二区| 国产成人亚洲精品| 亚洲午夜精品第一区二区8050| 久久国产乱子伦免费精品| 亚洲精品GV天堂无码男同| 青青草原亚洲视频| 一个人免费观看视频www|