DreamTiger的夢幻樂園

          隨便寫寫,自得其樂,生活就是這樣

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            29 Posts :: 0 Stories :: 13 Comments :: 0 Trackbacks

          #

          今天遇到一個問題就是,如何設置<html:select>多選情況下的默認值,網上有些人說下面是可行的:
          <html:form action="/projectUpdate.do" focus="experimenters">
                <html:select property="experimenters" size="10" multiple="true" value="experimenters">
                  <html:optionsCollection name="msms_experimenterlist" value="email" label="email"/>
                </html:select>
          ....
          </html:form>
          這里,experimenters是projectForm的屬性,類型為String[]
          msms_experimenterlist是保存在request中的一個set<UserInfo>,email是UserInfo的屬性,類型為String。

          顯示以及傳遞到/projectUpdate.do對應的Action都正常,但是如果給projectForm的experimenters設置了初始值,在真實顯示的時候,多選框中并沒有設置這些初始值,很是麻煩。

          雖然最后通過jsp的方法解決,總是不爽阿:
                <html:select property="experimenters" size="10" multiple="true" value="experimenters">
                 <%ProjectForm projForm = (ProjectForm) request.getAttribute("projectForm");
                   HashSet<String> oldExperimenters = new HashSet<String>(Arrays.asList(projForm.getExperimenters()));
                   List userList = (List)request.getAttribute("msms_experimenterlist");
                   for(int i = 0;i < userList.size();i++){
                     UserInfo user = (UserInfo) userList.get(i);
                     if (oldExperimenters.contains(user.getEmail())){
                       out.print("<option value=\"" + user.getEmail() + "\" selected>" + user.getEmail());
                     }
                     else{
                       out.print("<option value=\"" + user.getEmail() + "\">" + user.getEmail());
                     }
                   }
                  %>
                </html:select>


          posted @ 2005-12-23 23:04 夢幻樂園 閱讀(1414) | 評論 (1)編輯 收藏

          http://www-900.ibm.com/cn/support/faqhtmlfaq/1311001000049.htm

          環境
           產品:AIX
           版本:V4
          問題
           如何用tar備份鏈接文件
          解答

           用tar備份鏈接文件時,缺省時只備份鏈接,用-h選項可以將鏈接所指的文件一同備份進去.


          posted @ 2005-12-15 16:50 夢幻樂園 閱讀(1044) | 評論 (0)編輯 收藏

          由于通過tomcat的manager無法完全清除msms目錄,導致重新deploy會無效,于是想出了怪招:

              <target name="deploy-local" description="Install application in Local Tomcat">
                  <echo message="deploying to local ..." />
                  <exec executable="cmd" os="Windows 2000" vmlauncher="false">
                      <arg line="/c start ${tomcat.dir}/bin/shutdown.bat" />
                  </exec>
                  <delete dir="${tomcat.webapps}/${context-path}" />
                  <copy todir="${tomcat.webapps}" overwrite="true">
                      <fileset dir="${dist}">
                          <include name="${context-path}.war" />
                      </fileset>
                  </copy>
                  <exec executable="${tomcat.dir}/bin/startup.bat" os="Windows 2000" spawn="true" vmlauncher="false">
                      <arg line="/c start ${tomcat.dir}/bin/startup.bat" />
                  </exec>
              </target>

          首先通過調用shutdown.bat,而且不設置spawn="true",這樣就會有一個cmd窗口在那里留著,可以看著tomcat停掉了,然后關 閉這個cmd窗口,ant才會繼續向下執行刪除和拷貝,然后自動啟動tomcat。雖然看上去比較怪,好歹還算管用,哈哈。
          posted @ 2005-12-14 21:26 夢幻樂園 閱讀(518) | 評論 (0)編輯 收藏

          下載了Hibernate3.1編譯,無論通過build.bat還是ant jar都會出錯。前者會說找不到javac,我暈倒。后者說antlr/Tool找不到。

          后來在hibernate網站上(http://www.hibernate.org/6.html)看到:

          Fixing Ant classpath/plugin issues

          You may need to add junit.jar to your $ANT_HOME/lib directory if it is not there already, or alternatively remove the $ANT_HOME/lib/ant-junit.jar file. For Hibernate3, repeat the steps above, but also copy lib/antlr.jar or remove the $ANT_HOME/lib/ant-antlr.jar file.

          These steps are necessary because Ant ships with plugin stub libraries in its classpath, so Ant plugins for JUnit or Antlr can't be used without copying or removing files. If you don't have Ant installed on your machine or don't want to mess with the default Ant installation then, on Windows, just run build.bat to use the bundled Ant libraries.

          雖然他說可以用build.bat來進行,但我也不知道他為什么會找不到javac,反正我把antlr.jar拷到ant的lib下面,就OK了。



          posted @ 2005-12-14 21:22 夢幻樂園 閱讀(326) | 評論 (0)編輯 收藏

          昨天的錯誤至今無法修正,即使重裝了Tomcat也不行。

          不過,deploy到兩臺linux服務器上倒都成功了。
              <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask">
                  <classpath>
                      <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
                  </classpath>
              </taskdef>

              <taskdef name="list" classname="org.apache.catalina.ant.ListTask">
                  <classpath>
                      <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
                  </classpath>
              </taskdef>

              <target name="deploy-web" description="Install application in Local Tomcat">
                  <echo message="deploying to web ..." />
                  <deploy url="http://172.16.1.20:8080/manager" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" war="file:${dist}/${context-path}.war" update="true" />
              </target>

              <target name="list-web">
                  <echo message="list web tomcat ..." />
                  <list url="http://172.16.1.20:8080/manager" username="${tomcat.manager.username}" password="${tomcat.manager.password}" />
              </target>


          這里跟昨天的代碼有一點不一樣:
          1、localWar改成了war。
          原來更新遠程服務器的時候,總是顯示更新成功,但是到webapps目錄下總是沒有相應的war文件,通過調用
          ant list-web
          發現,有一個context-path是dist/msms,而且是stop狀態。哦,原來localWar的意思不是指開發的機器的local path,而是指把這個war被寫到服務器的什么地方。改成war就正常了。

          2、不需要判斷是否已經deploy進而調用undeploy了,直接通過update="true"更新就可以了。
          posted @ 2005-12-09 11:06 夢幻樂園 閱讀(890) | 評論 (0)編輯 收藏

          今天研究對象是Ant,用于對msms系統進行Tomcat的自動部署。

          遇到一個怪問題,百思不得其解:
          通過ant depoly可以把msms.war部署到tomcat上。當然,要求這時候webapps下面沒有msms目錄。
          看tomcat的紀錄,加載msms.war正常,網頁也可以打開。

          通過ant undeploy,可以把msms卸載。Tomcat顯示:
          Undeploying context [/msms]
          正常卸載了。問題是,去看webapps目錄下面,居然有一個msms目錄的殘骸,里面保留的目錄是
          WEB-INF\lib
          有以下幾個文件殘留著:
          commons-digester.jar
          commons-validator.jar
          struts.jar

          這時候msms目錄也無法手工刪除,必須停掉tomcat后才能刪除。

          我裝的tomcat是5.5。不知道是否還有人遇到過這種情況,我反正是暈了。

          build.properties文件如下:
          tomcat.dir=C:/ApacheGroup/Tomcat5.5
          tomcat.webapps=C:/ApacheGroup/Tomcat5.5/webapps
          tomcat.manager.url=http://localhost:8080/manager
          tomcat.manager.username=admin
          tomcat.manager.password=xxxxxxxx

          build.xml文件如下:
          <?xml version="1.0"?>
          <project name="msms" default="compile" basedir=".">
              <!-- Ant Tomcat Task Definition -->
              <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask">
                  <classpath>
                      <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
                  </classpath>
              </taskdef>

              <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask">
                  <classpath>
                      <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
                  </classpath>
              </taskdef>

              <taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
                  <classpath>
                      <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
                  </classpath>
              </taskdef>

              <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
                  <classpath>
                      <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
                  </classpath>
              </taskdef>

              <taskdef name="list" classname="org.apache.catalina.ant.ListTask">
                  <classpath>
                      <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
                  </classpath>
              </taskdef>

              <taskdef name="start" classname="org.apache.catalina.ant.StartTask">
                  <classpath>
                      <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
                  </classpath>
              </taskdef>

              <taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
                  <classpath>
                      <path location="${tomcat.dir}/server/lib/catalina-ant.jar" />
                  </classpath>
              </taskdef>

              <property name="build" value="build" />
              <property name="dist" value="dist" />
              <property name="src" value="src/java" />
              <property name="test" value="src/test" />
              <property name="war-config" value="src/config" />
              <property name="report" value="report" />
              <property name="lib" value="lib" />
              <property name="web" value="web" />
              <property name="meta" value="meta" />
              <property name="context-path" value="${ant.project.name}" />
              <property file="build.properties" />

              <path id="build.classpath">
                  <fileset file="${lib}/*.jar" />
                  <fileset dir="${tomcat.dir}/common/lib">
                      <include name="*.jar" />
                  </fileset>
                  <fileset dir="${tomcat.dir}/common/endorsed">
                      <include name="*.jar" />
                  </fileset>
                  <pathelement path="${build}" />
              </path>

              <!-- Hibernate Tool Task Definition -->
              <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="build.classpath" />
             
              <target name="clean">
                  <echo message="Cleaning up the build and dist directories" />
                  <delete dir="${build}" />
                  <mkdir dir="${build}" />
                  <delete dir="${dist}" />
                  <mkdir dir="${dist}" />
              </target>

              <target name="copy-resources">
                  <copy todir="${build}">
                      <fileset dir="${src}">
                          <exclude name="**/*.java" />
                          <exclude name="**/*.hbm.xml" />
                      </fileset>
                  </copy>
              </target>

              <target name="compile" depends="copy-resources">
                  <javac destdir="${build}" srcdir="${src}:${test}">
                      <classpath refid="build.classpath" />
                  </javac>
              </target>

              <target name="initdb" depends="compile">
                  <hibernatetool destdir="${build}">
                      <classpath>
                          <path location="${build}" />
                      </classpath>
                      <annotationconfiguration configurationfile="src/java/hibernate.cfg.xml" />

                      <hbm2ddl create="true" />
                  </hibernatetool>
              </target>

              <target name="run" depends="compile">
                  <java fork="true" classname="cn.ac.rcpa.msms.tools.ProjectManager" classpathref="build.classpath">
                      <classpath path="${build}" />
                      <arg value="${action}" />
                      <arg value="${project}" />
                      <arg value="${description}" />
                  </java>
              </target>

              <target name="test" depends="compile" description="run junit test">
                  <delete dir="${report}" />
                  <mkdir dir="${report}" />
                  <junit dir="." fork="true" printsummary="on" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
                      <classpath refid="build.classpath" />
                      <formatter type="brief" />
                      <batchtest todir="${report}">
                          <fileset dir="${build}">
                              <include name="**/*Test.*" />
                              <include name="**/Test*.*" />
                          </fileset>
                      </batchtest>
                  </junit>
                  <fail if="tests.failed">
                ***********************************************************
                **** One or more tests failed! Check the output ... ****
                ***********************************************************
              </fail>
              </target>

              <target name="create-war" depends="clean, compile" description="build release war">
                  <echo message="creation the WAR file...${context-path}.war" />
                  <war destfile="${dist}/${context-path}.war" webxml="${meta}/web.xml">
                      <classes dir="${build}">
                          <exclude name="**/*Test.*" />
                          <exclude name="**/Test*.*" />
                          <exclude name="hibernate.cfg.xml" />
                      </classes>
                      <lib dir="${lib}" />
                      <fileset dir="${web}" />
                      <zipfileset dir="${war-config}" prefix="WEB-INF/classes" />
                  </war>
                  <!--        <scp file="${dist}/${context-path}.war" todir="root:${password}@172.16.1.20:/usr/local/tomcat/webapps" trust="true" /> -->
              </target>

              <target name="deploy" description="Install application in Tomcat">
                  <deploy url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" localWar="file:${dist}/${context-path}.war" />
              </target>

              <target name="undeploy" description="Remove application in Tomcat" if="already.deployed">
                  <undeploy url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" />
              </target>

              <target name="reload" description="Reload application in Tomcat">
                  <reload url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" />
              </target>

              <target name="start" description="Start Tomcat application">
                  <start url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" />
              </target>

              <target name="stop" description="Stop Tomcat application">
                  <stop url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${context-path}" />
              </target>

              <target name="list" description="List Tomcat applications">
                  <list url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" />
              </target>

              <target name="deploy-application" description="Compile the web application...">
                  <echo message="Undeploying the application only if it's deployed..." />
                  <available file="${tomcat.webapps}/${context-path}.war" property="already.deployed" />
                  <antcall target="undeploy" />
                  <antcall target="create-war" />
                  <antcall target="deploy" />
              </target>
          </project>


          posted @ 2005-12-08 18:13 夢幻樂園 閱讀(1422) | 評論 (3)編輯 收藏

          http://www.jroller.com/page/kbaum/20040708#orm_lazy_initialization_with_dao
          posted @ 2005-12-07 09:52 夢幻樂園 閱讀(251) | 評論 (0)編輯 收藏

          用hibernate一段時間,期間寫過hbm.xml,也通過XDoclet產生過Java,
          最后采用的是annotation方式。保留一份包含了hbm.xml方式和XDoclet
          方式的hibernate.cfg.xml文件,以備查詢。

          <?xml version="1.0"?>
          <project name="RcpaMSMSDisplay" default="compile" basedir=".">

              <property name="src.dir" value="${basedir}/src" />
              <property name="test.dir" value="${basedir}/test" />
              <property name="classes.dir" value="${basedir}/WEB-INF/classes" />
              <property name="report.dir" value="${basedir}/report" />
              <property name="tomcat.dir" value="C:/ApacheGroup/Tomcat5.5" />
              <property name="lib.dir" value="${basedir}/WEB-INF/lib" />

              <path id="build.classpath">
                  <fileset file="${lib.dir}/*.jar" />
                  <fileset file="${tomcat.dir}/common/lib/*-api.jar" />
                  <pathelement path="${classes.dir}" />
              </path>

              <target name="clean">
                  <delete dir="${classes.dir}" />
                  <mkdir dir="${classes.dir}" />
              </target>

              <target name="compile" depends="copy-resources">
                  <javac destdir="${classes.dir}" srcdir="${src.dir}:${test.dir}">
                      <classpath refid="build.classpath" />
                  </javac>
              </target>

              <target name="copy-resources">
                  <copy todir="${classes.dir}">
                      <fileset dir="${src.dir}">
                          <exclude name="**/*.java" />
                          <exclude name="**/*.hbm.xml" />
                      </fileset>
                  </copy>
              </target>

              <target name="copy-hbm-xml">
                  <copy todir="${classes.dir}">
                      <fileset dir="${src.dir}">
                          <include name="**/*.hbm.xml" />
                      </fileset>
                  </copy>
              </target>

              <target name="generate" description="Generates Hibernate class descriptor files." depends="compile">
                  <!-- Define the hibernatedoclet task -->
                  <taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask">
                      <classpath>
                          <fileset dir="${lib.dir}/xdoclet">
                              <include name="*.jar" />
                          </fileset>
                      </classpath>
                  </taskdef>

                  <!-- Execute the hibernatedoclet task -->
                  <hibernatedoclet destdir="${src.dir}" excludedtags="@version,@author,@todo" verbose="false">
                      <fileset dir="${src.dir}">
                          <include name="**/*.java" />
                      </fileset>
                      <hibernate version="3.0" />
                  </hibernatedoclet>
              </target>

              <target name="initdb" depends="compile">
                  <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="build.classpath" />

                  <hibernatetool destdir="${classes.dir}">
                      <classpath>
                          <path location="${classes.dir}" />
                      </classpath>
                      <annotationconfiguration configurationfile="src/hibernate.cfg.xml" />

                      <hbm2ddl create="true" />
                  </hibernatetool>
              </target>

              <target name="run" depends="compile">
                  <java fork="true" classname="cn.ac.rcpa.msms.tools.ProjectManager" classpathref="build.classpath">
                      <classpath path="${classes.dir}" />
                      <arg value="${action}" />
                      <arg value="${project}" />
                      <arg value="${description}" />
                  </java>
              </target>
              
              <target name="test" depends="compile" description="run junit test">
                  <delete dir="${report.dir}" />
                  <mkdir dir="${report.dir}" />
                  <junit dir="." fork="true" printsummary="on" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
                      <classpath refid="build.classpath" />
                      <formatter type="brief" />
                      <batchtest todir="${report.dir}">
                          <fileset dir="${classes.dir}">
                              <include name="**/*Test.*" />
                              <include name="**/Test*.*" />
                          </fileset>
                      </batchtest>
                  </junit>
                  <fail if="tests.failed">
                ***********************************************************
                **** One or more tests failed! Check the output ... ****
                ***********************************************************
              </fail>
              </target>
              
          </project>

          posted @ 2005-12-06 16:25 夢幻樂園 閱讀(778) | 評論 (0)編輯 收藏

          1、HelloApp
          書上是:
          BeanFactory factory = new XmlBeanFactory(new FileInputStream("hello.xml"));
          應該是:
          BeanFactory factory = new XmlBeanFactory(new FileSystemResource("hello.xml"));

          2、KnightApp
          在實現了XML中Minstrel的interceptor后,
          需要把
          KnightOfTheRoundTable knight = (KnightOfTheRoundTable) factory.getBean("knight");
          改成:
          Knight knight = (Knight) factory.getBean("knight");
          否則會報:
          Exception in thread "main" java.lang.ClassCastException: $Proxy0
          posted @ 2005-12-05 12:49 夢幻樂園 閱讀(423) | 評論 (0)編輯 收藏

          由于數據庫connection在較長時間沒有訪問下會自動斷開連接,導致瀏覽出錯,增加proxool作為數據庫pool。它有自動連接功能。
          1、從http://proxool.sourceforge.net/下載proxool,釋放proxool.jar到WEB-INF/lib

          2、在hibernate.cfg.xml中增加:
          <property name="hibernate.proxool.pool_alias">dbpool</property>
          <property name="hibernate.proxool.xml">proxool.xml</property>
          <property name="connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>

          3、在與hibernate.cfg.xml同級目錄(src根目錄下)增加proxool.xml文件:
          <?xml version="1.0" encoding="utf-8"?>
          <!-- the proxool configuration can be embedded within your own application's.
              Anything outside the "proxool" tag is ignored. -->
          <something-else-entirely>
              <proxool>
                  <alias>dbpool</alias>
                  <!--proxool只能管理由自己產生的連接-->
                  <driver-url>
                      jdbc:mysql://localhost:3306/msms
                  </driver-url>
                  <driver-class>com.mysql.jdbc.Driver</driver-class>
                  <driver-properties>
                      <property name="user" value="sqh" />
                      <property name="password" value="sqh" />
                  </driver-properties>
                  <!-- proxool自動偵察各個連接狀態的時間間隔(毫秒),偵察到空閑的連接就馬上回收,超時的銷毀-->
                  <house-keeping-sleep-time>90000</house-keeping-sleep-time>
                  <!-- 最少保持的空閑連接數-->
                  <prototype-count>5</prototype-count>
                  <!-- 允許最大連接數,超過了這個連接,再有請求時,就排在隊列中等候,最大的等待請求數由maximum-new-connections決定-->
                  <maximum-connection-count>100</maximum-connection-count>
                  <!-- 最小連接數-->
                  <minimum-connection-count>10</minimum-connection-count>
              </proxool>
          </something-else-entirely>

          4、重起tomcat
          posted @ 2005-12-05 12:46 夢幻樂園 閱讀(1416) | 評論 (0)編輯 收藏

          僅列出標題
          共3頁: 上一頁 1 2 3 下一頁 
          主站蜘蛛池模板: 万安县| 呈贡县| 江华| 芦溪县| 翼城县| 屏南县| 岳池县| 乐清市| 旺苍县| 绥中县| 普兰县| 安吉县| 岑巩县| 拉萨市| 佛坪县| 广汉市| 和静县| 乳源| 靖远县| 山东| 河津市| 乡宁县| 石泉县| 和政县| 沅江市| 准格尔旗| 新野县| 望都县| 察哈| 内江市| 滁州市| 志丹县| 乐清市| 旺苍县| 涞源县| 罗源县| 新蔡县| 成都市| 丽江市| 孟连| 芦溪县|