波多野结衣av在线播放,成人网中文字幕,成年网站在线视频网站http://www.aygfsteel.com/nkjava/category/37729.html置身浩瀚的沙漠,方向最為重要,希望此blog能向大漠駝鈴一樣,給我方向和指引。<br/> Java,Php,Shell,Python,服務器運維,大數據,SEO, 網站開發、運維,云服務技術支持,IM服務供應商, FreeSwitch搭建,技術支持等. 技術討論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--有關Tomcat自動宕機的解決方案http://www.aygfsteel.com/nkjava/archive/2016/08/03/431436.html草原上的駱駝草原上的駱駝Wed, 03 Aug 2016 02:59:00 GMThttp://www.aygfsteel.com/nkjava/archive/2016/08/03/431436.htmlhttp://www.aygfsteel.com/nkjava/comments/431436.htmlhttp://www.aygfsteel.com/nkjava/archive/2016/08/03/431436.html#Feedback0http://www.aygfsteel.com/nkjava/comments/commentRss/431436.htmlhttp://www.aygfsteel.com/nkjava/services/trackbacks/431436.html 在Stackoverflow上找到比較有用的一篇文章,解決方案如下:
http://stackoverflow.com/questions/3320400/to-prevent-a-memory-leak-the-jdbc-driver-has-been-forcibly-unregistered
有以下幾個解決途徑:
  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驅動文件拷貝到Tomcat/lib下。如果仍然要放在WEB-INF/lib下,需要使用監聽器手動的注冊和注銷。
    下面的文章介紹如何寫監聽器,http://javabeat.net/servletcontextlistener-example/, 當然如果是Servlet3.0, 使用注解方式設置監聽也是可以的。
    下面的代碼是如何注銷。

    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降級到低版本(6.0.23以下),雖然不會報錯,但是還是存在內存益出的問題,這并不是一個好的解決方案。

  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.
    把驅動文件移到Tomcat/lib文件夾下,不用使用DBCP,使用以下的連接池庫,HikariCP, BoneCP,或者Tomcat JDBC Pool.

  4. MAVEN項目

    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>,
    對于MAVEN項目,由于Tomcat中存在mysql驅動文件(1中介紹),這樣在部署時就不會把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>
好了,如果您遇到同樣的問題,可以和我溝通,聯系方式見頭部。

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

mvn eclipse:eclipse  #生成eclipse配置文件
mvn clean package #打包項目
mvn clean install #安裝成本地庫
mvn clean install -DoutputDirectory=lib -Dsilent=true -Pmodules
mvn clean install -Pmodules #安裝指定的模塊到本地倉庫
mvn jetty:run #運行jetty
mvn tomcat7:run #運行tomcat




mvn compile #編譯
mvn test #運行測試




下載源碼和文檔
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 創建項目

mvn install -Dmaven.test.skip=true#不執行測試




環境分離
<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  #使用不同的環境,生產環境,開發環境,測試環境  

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

mvn dependency:tree #依賴樹
mvn dependencies: copy-dependency #復制依賴的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



說明文檔
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 發表評論
]]>
Row was updated or deleted by another transactionhttp://www.aygfsteel.com/nkjava/archive/2010/08/11/328555.html草原上的駱駝草原上的駱駝Wed, 11 Aug 2010 08:48:00 GMThttp://www.aygfsteel.com/nkjava/archive/2010/08/11/328555.htmlhttp://www.aygfsteel.com/nkjava/comments/328555.htmlhttp://www.aygfsteel.com/nkjava/archive/2010/08/11/328555.html#Feedback1http://www.aygfsteel.com/nkjava/comments/commentRss/328555.htmlhttp://www.aygfsteel.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", 在對一條數據進行插入時手動設置了version的值, 沒有問題。
但是在對條數據進行更新操作時卻報錯了:org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect):
需要在更新的的頁面傳遞version字段同時設計隱藏,<s:hidden name="info.version"></s:hidden>
這樣就解決了問題。

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

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

      返回所有User對象

二、find(String queryString , Object value);

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

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

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

三、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"});

      返回用戶名為test并且密碼為123的所有User對象

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

四、findByExample(Object exampleEntity)

      示例:

             User u=new User();    

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

   u.setName("bb");    

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

      返回:用戶名為bb密碼為123的對象

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

      示例:

    User u=new User();    

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

            u.setName("bb");    

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

      返回:滿足用戶名為bb密碼為123,自start起共max個User對象。(對象從0開始計數)

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

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

    使用以下語句查詢:

       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對象的條數

七、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);

         返回用戶名為xiyue密碼為123的User對象

八、findByNamedQuery(String queryName)

      示例:

        1、首先需要在User.hbm.xml中定義命名查詢

             <hibernate-mapping>

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

                  <query name="queryAllUser"><!--此查詢被調用的名字-->

                       <![CDATA[

                            from bean.User

                        ]]>

                  </query>

             </hibernate-mapping>

         2、如下使用查詢:

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

九、findByNamedQuery(String queryName, Object value)

      示例:

        1、首先需要在User.hbm.xml中定義命名查詢

             <hibernate-mapping>

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

                  <query name="queryByName"><!--此查詢被調用的名字-->

                       <![CDATA[

                            from bean.User u where u.name = ?

                        ]]>

                  </query>

             </hibernate-mapping>

         2、如下使用查詢:

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

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

      示例:

        1、首先需要在User.hbm.xml中定義命名查詢

             <hibernate-mapping>

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

                  <query name="queryByNameAndPassword"><!--此查詢被調用的名字-->

                       <![CDATA[

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

                        ]]>

                  </query>

             </hibernate-mapping>

         2、如下使用查詢:

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

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

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

示例:

        1、首先需要在User.hbm.xml中定義命名查詢

             <hibernate-mapping>

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

                  <query name="queryByName"><!--此查詢被調用的名字-->

                       <![CDATA[

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

                        ]]>

                  </query>

             </hibernate-mapping>

         2、如下使用查詢:

             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、定義一個ValueBean,屬性名必須和HSQL語句中的:后面的變量名同名,此處必須至少有兩個屬性,分別為myName和 myPassword,使用setter方法設置屬性值后

          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中定義命名查詢

             <hibernate-mapping>

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

                  <query name="queryByNameAndPassword"><!--此查詢被調用的名字-->

                       <![CDATA[

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

                        ]]>

                  </query>

             </hibernate-mapping>

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

          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 發表評論
]]>
struts2.1.6中的datatimepicker 設置http://www.aygfsteel.com/nkjava/archive/2009/05/28/278313.html草原上的駱駝草原上的駱駝Thu, 28 May 2009 03:30:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/05/28/278313.htmlhttp://www.aygfsteel.com/nkjava/comments/278313.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/05/28/278313.html#Feedback2http://www.aygfsteel.com/nkjava/comments/commentRss/278313.htmlhttp://www.aygfsteel.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 發表評論
]]>
JSF學習筆記開始http://www.aygfsteel.com/nkjava/archive/2009/05/15/270935.html草原上的駱駝草原上的駱駝Fri, 15 May 2009 13:49:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/05/15/270935.htmlhttp://www.aygfsteel.com/nkjava/comments/270935.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/05/15/270935.html#Feedback0http://www.aygfsteel.com/nkjava/comments/commentRss/270935.htmlhttp://www.aygfsteel.com/nkjava/services/trackbacks/270935.html

草原上的駱駝 2009-05-15 21:49 發表評論
]]>
struts2中如何獲取Session,HttpServletRequest,HttpServletResponsehttp://www.aygfsteel.com/nkjava/archive/2009/03/29/262733.html草原上的駱駝草原上的駱駝Sun, 29 Mar 2009 08:40:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/03/29/262733.htmlhttp://www.aygfsteel.com/nkjava/comments/262733.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/03/29/262733.html#Feedback0http://www.aygfsteel.com/nkjava/comments/commentRss/262733.htmlhttp://www.aygfsteel.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 發表評論
]]>
No mapping found for dependency [type=java.lang.String, name='actionPackages'] http://www.aygfsteel.com/nkjava/archive/2009/03/29/262705.html草原上的駱駝草原上的駱駝Sun, 29 Mar 2009 03:33:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/03/29/262705.htmlhttp://www.aygfsteel.com/nkjava/comments/262705.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/03/29/262705.html#Feedback5http://www.aygfsteel.com/nkjava/comments/commentRss/262705.htmlhttp://www.aygfsteel.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

出現這個問題,可能是添加了struts2-codebehind包,去除這個包就可以了

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

開發平臺:Eclipse3.4+maven2.0
我安裝Eclipse了maven插件,也可以不安裝, 用maven生成了maven-archetype-webapp項目,首先先手動的把所有的目錄補充好,下圖為我的程序目錄。


其中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操作系統下(當然linux也可以,linux是在終端下)cd到項目的目錄,mvn jetty:run, 即可看到系統。
源碼付在下面,請大家參考。
用eclipse導入后,修改hibernate.cfg.xml里面的mysql的配置,首先要先建立相應的數據庫,然后運行cn.edu.nku.common.ExportDB.java生成數據庫里的表,。


有一點還希望大家能給出指點,用maven+jetty部署項目, 每次都要關閉jetty,然后再運行mvn jetty:run,才能重新部署,不知道有沒有好的辦法,進行熱部署。希望高人能指點迷津。


源碼下載



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

使用正則表達式,將原代碼
            <html:text property="email" styleId="email" size="50"/>
注釋,換成

            <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,''))"
 />
就解決了問題,用戶如果輸入漢字,則自動刪除漢字,而且如果使用向左的箭頭向前移動使光標前移,則根本移動不了,光標始終在行尾,只能刪除后面的字符,再重新寫,其實最好是在EMail的自動生成的腳本中提示,目前先這樣實現吧,將來再說!

草原上的駱駝 2009-03-19 17:45 發表評論
]]>
hibernate的 fetch lazy inverse cascadehttp://www.aygfsteel.com/nkjava/archive/2009/03/09/258655.html草原上的駱駝草原上的駱駝Mon, 09 Mar 2009 11:41:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/03/09/258655.htmlhttp://www.aygfsteel.com/nkjava/comments/258655.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/03/09/258655.html#Feedback0http://www.aygfsteel.com/nkjava/comments/commentRss/258655.htmlhttp://www.aygfsteel.com/nkjava/services/trackbacks/258655.html1.fetch 和 lazy 主要用于級聯查詢(select) 而 inverse和cascade主要用于級聯增、加刪、除修改(sava-update,delete)
2.想要刪除父表中的記錄,但希望子表中記錄的外鍵引用值設為null的情況:
   父表的映射文件應該如下配置:
        <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可有可無,并且子表的映射文件中inverse沒必要設置,cascade也可以不設置,如果設置就設置成為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.關于級聯查找
  對子表的持久化類進行查找的時候,會一起把子表持久化類中的父表持久化類的對象一起查詢出來,在頁面中可以直接取值的情況:
    要把父表的映射文件中設置 lazy 屬性如下:
<class name="com.sino.hibernate.Emp" table="EMP" schema="SCOTT" lazy="false">
這樣就可以直接在頁面中取值 (類似于這樣的取值 client.cmanager.id)
如果沒有設置 lazy="false" 則會拋出異常
javax.servlet.ServletException: Exception thrown by getter for property cmanager.realName of bean cl
在Action中取值的話就會拋出
could not initialize proxy - the owning Session was closed的異常

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

這里我重點來說下GenerationType.TABLE的情況。
把庫表的主鍵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:定義主鍵生成策略,這里因為使用的是TableGenerator,所以,主鍵的生成策略為GenerationType.TABLE,生成主鍵策略的名稱則為前面定義的"CardPkGen”。
@TableGenerator各屬性含義如下:
name:表示該表主鍵生成策略的名稱,這個名字可以自定義,它被引用在@GeneratedValue中設置的"generator"值中
table:表示表生成策略所持久化的表名,說簡單點就是一個管理其它表主鍵的表,本例中,這個表名為ID_GEN
pkColumnName:表生成器中的列名,用來存放其它表的主鍵鍵名,一般來說一個主鍵鍵名對應一張其他表要獲取主鍵值對應的key。這個值要與數據庫的列對應,比如GEN_NAME對應id_gen中的主鍵名稱
pkColumnValue:該實體所要訪問對應主鍵生成表的主鍵的key值
valueColumnName:表生成器所要對應pkColumnName主鍵的下一個值,這個值也要和表生成器中的列名對應
allocationSize:表示每次主鍵值增加的大小,例如設置成1,則表示每次創建新記錄后自動加1,默認為50

按照以上結構,如果我們執行:
CreditCard cc = new CreditCard();
cc.setCardName("測試卡");
cc = ccDao.persist(cc);



表id_gen內的數據為

GEN_NAME GEN_VALUE
Card_Gen  2

表t_creditcard內的數據為

ID CARDNAME
1   測試卡

再執行一次程序
表id_gen內的數據為

GEN_NAME GEN_VALUE
Card_Gen  3

表t_creditcard內的數據為

ID CARDNAME
1   測試卡
2   測試卡

把實體類的annation改寫為:
@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已經被改為Card_Gen2。

執行程序,插入數據失敗,拋出t_creditcard表主鍵重復的異常,因為這次去名為Card_Gen2的這個主鍵生成器去拿來的id為1,t_creditcard表之前已經插入過一條主鍵為1的數據了。

表id_gen內的數據為

GEN_NAME GEN_VALUE
Card_Gen  3
Card_Gen2  2

表t_creditcard內的數據還是為

ID CARDNAME
1   測試卡
2   測試卡

結論:在有些應用中,我們可以適用@TableGenerator來統一管理我們數據庫中的各個表的主鍵生成,如果我們的應用中有10個實體需要使用自動生成的主鍵,只需在每個實體中使用@TableGenerator并給出不同的pkColumnValue值就可以了。

@Id還有一些另類的用法:

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


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

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



別忘了修改庫表中主鍵字段的大小和對應的類型.

草原上的駱駝 2009-02-22 22:08 發表評論
]]>
A Blog Application with Warp (continued)(2)http://www.aygfsteel.com/nkjava/archive/2009/02/17/255131.html草原上的駱駝草原上的駱駝Tue, 17 Feb 2009 08:30:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/02/17/255131.htmlhttp://www.aygfsteel.com/nkjava/comments/255131.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/02/17/255131.html#Feedback0http://www.aygfsteel.com/nkjava/comments/commentRss/255131.htmlhttp://www.aygfsteel.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 發表評論
]]>
A Blog Application with Wideplay's Warp Framework(1)http://www.aygfsteel.com/nkjava/archive/2009/02/17/255130.html草原上的駱駝草原上的駱駝Tue, 17 Feb 2009 08:29:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/02/17/255130.htmlhttp://www.aygfsteel.com/nkjava/comments/255130.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/02/17/255130.html#Feedback0http://www.aygfsteel.com/nkjava/comments/commentRss/255130.htmlhttp://www.aygfsteel.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 發表評論
]]>
A Hello World Application in Warphttp://www.aygfsteel.com/nkjava/archive/2009/02/17/255127.html草原上的駱駝草原上的駱駝Tue, 17 Feb 2009 08:28:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/02/17/255127.htmlhttp://www.aygfsteel.com/nkjava/comments/255127.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/02/17/255127.html#Feedback0http://www.aygfsteel.com/nkjava/comments/commentRss/255127.htmlhttp://www.aygfsteel.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 發表評論
]]>
Struts2.0的Struts.properties(轉)http://www.aygfsteel.com/nkjava/archive/2009/02/14/254700.html草原上的駱駝草原上的駱駝Sat, 14 Feb 2009 13:09:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/02/14/254700.htmlhttp://www.aygfsteel.com/nkjava/comments/254700.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/02/14/254700.html#Feedback0http://www.aygfsteel.com/nkjava/comments/commentRss/254700.htmlhttp://www.aygfsteel.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擴展名來確定是否這個請求是被用作Struts action,其實也就是設置 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自動加載的一個配置文件列表

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的完整連續的package名稱

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

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


struts.devMode
          Whether Struts is in development mode or not
           是否為struts開發模式

struts.dispatcher.parametersWorkaround
          Whether to use a Servlet request parameter workaround necessary for some versions of WebLogic
            (某些版本的weblogic專用)是否使用一個servlet請求參數工作區(PARAMETERSWORKAROUND)

struts.enable.DynamicMethodInvocation
          Allows one to disable dynamic method invocation from the URL
            允許動態方法調用

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
           國際化信息內碼

struts.i18n.reload
          Whether the localization messages should automatically be reloaded
           是否國際化信息自動加載

struts.locale
          The default locale for the Struts application
           默認的國際化地區信息

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請求信息的最大尺寸(文件上傳用)

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


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

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

struts.objectFactory.spring.autoWire
          Whether Spring should autoWire or not
           是否自動綁定Spring

struts.objectFactory.spring.useClassCache
          Whether Spring should use its class cache or not
           是否spring應該使用自身的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過濾器中提供的靜態內容應該被瀏覽器緩存在頭部屬性中

struts.serve.static
          Whether the Struts filter should serve static content or not
           是否struts過濾器應該提供靜態內容

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

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

struts.ui.theme
          The default UI template theme
           默認的UI template主題

struts.url.http.port
          The HTTP port used by Struts URLs
           設置http端口

struts.url.https.port
          The HTTPS port used by Struts URLs
           設置https端口

struts.url.includeParams
          The default includeParams method to generate Struts URLs
          在url中產生 默認的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模版應該被緩存



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

草原上的駱駝 2009-02-14 21:07 發表評論
]]>
Struts2.0標簽庫(二)數據標簽[轉]http://www.aygfsteel.com/nkjava/archive/2009/02/14/254698.html草原上的駱駝草原上的駱駝Sat, 14 Feb 2009 13:07:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/02/14/254698.htmlhttp://www.aygfsteel.com/nkjava/comments/254698.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/02/14/254698.html#Feedback0http://www.aygfsteel.com/nkjava/comments/commentRss/254698.htmlhttp://www.aygfsteel.com/nkjava/services/trackbacks/254698.html閱讀全文

草原上的駱駝 2009-02-14 21:07 發表評論
]]>
struts2 標簽學習http://www.aygfsteel.com/nkjava/archive/2009/02/14/254697.html草原上的駱駝草原上的駱駝Sat, 14 Feb 2009 13:05:00 GMThttp://www.aygfsteel.com/nkjava/archive/2009/02/14/254697.htmlhttp://www.aygfsteel.com/nkjava/comments/254697.htmlhttp://www.aygfsteel.com/nkjava/archive/2009/02/14/254697.html#Feedback3http://www.aygfsteel.com/nkjava/comments/commentRss/254697.htmlhttp://www.aygfsteel.com/nkjava/services/trackbacks/254697.html閱讀全文

草原上的駱駝 2009-02-14 21:05 發表評論
]]>
SiteMesh學習筆記1(一個優于Apache Tiles的Web頁面布局、裝飾框架)http://www.aygfsteel.com/nkjava/archive/2008/12/10/245559.html草原上的駱駝草原上的駱駝Wed, 10 Dec 2008 12:14:00 GMThttp://www.aygfsteel.com/nkjava/archive/2008/12/10/245559.htmlhttp://www.aygfsteel.com/nkjava/comments/245559.htmlhttp://www.aygfsteel.com/nkjava/archive/2008/12/10/245559.html#Feedback0http://www.aygfsteel.com/nkjava/comments/commentRss/245559.htmlhttp://www.aygfsteel.com/nkjava/services/trackbacks/245559.html OS(OpenSymphony)的SiteMesh是一個用來在JSP中實現頁面布局和裝飾(layout and decoration)
的框架組件,能夠幫助網站開發人員較容易實現頁面中動態內容和靜態裝飾外觀的分離。

       Sitemesh是由一個基于Web頁面布局、裝飾以及與現存Web應用整合的框架。它能幫助我們在由大
量頁面構成的項目中創建一致的頁面布局和外觀,如一致的導航條,一致的banner,一致的版權,等等。
它不僅僅能處理動態的內容,如jsp,php,asp等產生的內容,它也能處理靜態的內容,如htm的內容,
使得它的內容也符合你的頁面結構的要求。甚至于它能將HTML文件象include那樣將該文件作為一個面板
的形式嵌入到別的文件中去。所有的這些,都是GOF的Decorator模式的最生動的實現。盡管它是由java語言來實現的,但它能與其他Web應用很好地集成。

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

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

本文介紹sitemesh的簡單應用:

首先下載 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>
(注意過濾器的位置:應該在struts2的org.apache.struts2.dispatcher.FilterDispatcher過濾器之前 org.apache.struts2.dispatcher.ActionContextCleanUp過濾器之后,否則會有問題;)
在WEB-INF下建立
decorators.xml文件,添加如下代碼:
<?xml version="1.0" encoding="utf-8"?>  
  
<decorators defaultdir="/WEB-INF/decorators">  
        
<!-- 此處用來定義不需要過濾的頁面 -->  
        
<excludes> 
<pattern>/login/*</pattern>
        </excludes>        
     
<!-- 用來定義裝飾器要過濾的頁面 -->  
    
<decorator name="main" page="main.jsp">  
        
<pattern>/*</pattern>  
   
</decorator>  
</decorators> 
decorators.xml有兩個主要的結點:
       decorator結點指定了模板的位置和文件名,通過pattern來指定哪些路徑引用哪個模板
       excludes結點則指定了哪些路徑的請求不使用任何模板
上面代碼,凡是以/login/開頭的請求路徑一律不使用模板;
decorators結點的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>  
     
<!-- 第一個裝飾頁面 -->  
        
<head>  
     
<!-- 從被裝飾頁面獲取title標簽內容,并設置默認值-->  
     
<title><decorator:title default="默認title"/></title>  
<!-- 從被裝飾頁面獲取head標簽內容 -->  
 
<decorator:head/>  
</head>  

<body>  
   
<h2>SiteMesh裝飾header</h2>  
  
<hr />  
<!-- 從被裝飾頁面獲取body標簽內容 -->  
 
<decorator:body />  
 
<hr />  
 
<h2>SiteMesh裝飾footer</h2>  
 
</body>  
</html> 
這就是個簡單的模板,頁面的頭和腳都由模板里的靜態HTML決定了,主頁面區域用的是<decorator:body />標簽;
也就是說凡是能進入過濾器的請求生成的頁面都會默認加上模板上的頭和腳,然后頁面自身的內容將自動放到<decorator:body />標簽所在位置;

<decorator:title default="
默認title" />:讀取被裝飾頁面的標題,并給出了默認標題。
<decorator:head />:讀取被裝飾頁面的<head>中的內容;
<decorator:body />:讀取被裝飾頁面的<body>中的內容;



好了,下載可以建立頁面了,看看你的頁面是不是被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>  
     
<!-- 第一個被裝飾(目標)頁面  -->  
     
<head>  
     
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
     
<title>被裝飾(目標)頁面title</title>  
     
</head>  
      
    
<body>  
    
<h4>被裝飾(目標)頁面body標簽內內容。</h4>  
    
<h3>使用SiteMesh的好處?</h3>  
    
<ul>  
        
<li>  
         
<li>很多很多</li>  
        
</ul>  
    
</body>  
   
</html> 



草原上的駱駝 2008-12-10 20:14 發表評論
]]>
主站蜘蛛池模板: 长宁县| 攀枝花市| 通道| 高唐县| 平昌县| 韶关市| 三台县| 丘北县| 广安市| 侯马市| 炎陵县| 朔州市| 宝兴县| 张掖市| 海盐县| 德格县| 和硕县| 砀山县| 汝州市| 盐边县| 宽甸| 江华| 边坝县| 同德县| 个旧市| 沅江市| 兰溪市| 和林格尔县| 福建省| 莒南县| 凤城市| 湘西| 大足县| 慈利县| 饶河县| 保亭| 武平县| 邯郸县| 罗山县| 合阳县| 婺源县|