練功房推薦書單

  • Google!Android 3手機應用程式設計入門(第四版)
  • 賈伯斯傳(軟皮精裝版)
  • 猛虎出閘制霸版:最新OCP Java SE 6 Programmer專業認證(附原始程式碼及範例檔)
  • SCWCD 5 猛虎出閘:Java Web 應用程式專業認證
Messages posted by: andowson
Forum Index » Profile for andowson » Messages posted by andowson
Message
Java Polis'07 Slide: Wicket in Action
這篇概念說明的還滿清楚的,可以先有一個overview

Wicket in Action
有三篇電子書及範例程式碼,值得下載研讀

Enjoying Web Development with Wicket
前三章免費閱讀,並有範例程式碼,值得下載研讀

http://ptrthomas.files.wordpress.com/2008/05/peter_thomas_migrating_to_apache_wicket.pdf
JTrac 的作者 Peter Thomas 對整個Webapp Architecture 的說明提供一個不錯的參考架構
最近想改用符合 MVC 的 Web Framework 來開發網頁應用程式,經過一番尋找後,發現前端用Wicket是個不錯的選擇,可以將HTML和Java完全分開,只要後端再整合Spring,然後透過Spring再去整合Hibernate,就可以存取資料庫。如此一來就變成了Wicket+Spring+Hibernate的架構,只是這樣子一來要學的東西一下子變多了,在看完了Wicket的Hello World範例後,心中的想法是趕快弄個Wicket+Spring+Hibernate三合一的範例來跑跑看,如果不是很複雜,才能繼續花時間下去。

經過一番搜尋後,找到了一個Qwicket的範例,下載並解壓縮後直接用ant去編譯跟執行,卻發現不太會動,原來是build.xml裡面的maven-ant-task的版本比較舊,要更新到2.0.9才行。經過一番修正後,把一些版本都更新到最新版,再去執行,發現也不太work,原來跟maven repository上面的目錄名稱有點關係,例如hibernate的目錄名稱到了3.3.1.GA之後要改成大寫的GA,而有些軟體雖然在自己的網站上已經推出了較新的版本,但在maven repository上則沒有收錄到,就得先到maven repository上面去查一下,再回來修改。
修改完成的build.xml內容大致如下:
<project name="Qwicket" default="war" xmlns:artifact="urn:maven-artifact-ant">

    <property name="version" value="1.0"/>
    <property name="dist.file" value="Qwicket-${version}"/>

    <property file="build.properties"/>
    <property file="build.default.properties"/>

    <property name="maven.version" value="2.0.9"/>
    <property name="maven.ant.file" location="${user.home}/.m2/maven-ant-tasks-${maven.version}.jar"/>
    <available file="${maven.ant.file}" property="maven.ant.available"/>
    <property name="jetty.version" value="6.1.14"/>
    <property name="wicket.version" value="1.3.5"/>
    <property name="build.dir" value="build"/>
    <property name="src.conf.dir" value="src/conf"/>
    <property name="src.java.dir" value="src/java"/>
    <property name="src.test.dir" value="src/test"/>
    <property name="src.web.dir" value="src/web"/>
    <property name="logging.directory" value="/tmp"/>
    <property name="report.build.dir" value="${build.dir}/reports"/>
    <property name="war.build.dir" value="${build.dir}/war"/>
    <property name="javadoc.dir" value="javadoc"/>

    <target name="init" depends="deps">
        <path id="project.class.path">
            <pathelement location="${war.build.dir}/WEB-INF/classes"/>
            <pathelement location="${build.dir}/test"/>
            <path refid="base.class.path"/>
            <path refid="build.class.path"/>
        </path>
    </target>

    <target name="build" depends="init" description="Compiles the source files.">
        <mkdir dir="${war.build.dir}/WEB-INF/classes"/>
        <mkdir dir="${build.dir}/test"/>
        <javac srcdir="${src.java.dir}" classpathref="project.class.path" destdir="${war.build.dir}/WEB-INF/classes" debug="true"/>
    </target>

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

    <target name="build-war-structure" depends="build">
        <filter filtersfile="build.default.properties"/>
        <filter filtersfile="build.properties"/>
        <copy todir="${war.build.dir}">
            <fileset dir="src/web"/>
        </copy>
        <copy todir="${war.build.dir}/WEB-INF/classes" filtering="true" overwrite="true">
            <fileset dir="src/web/WEB-INF/classes"/>
        </copy>
        <copy todir="${war.build.dir}/WEB-INF/classes">
            <fileset dir="src/java">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy todir="${war.build.dir}/WEB-INF/lib" flatten="true">
            <fileset refid="runtime.fileset"/>
        </copy>
        <delete dir="${war.build.dir}/WEB-INF/lib">
            <include name="servlet*"/>
        </delete>
        <copy todir="${war.build.dir}">
            <fileset dir="src/web" includes="**/**"/>
        </copy>
    </target>

    <target name="war" depends="build-war-structure">
        <jar destfile="${build.dir}/${dist.file}.war" basedir="${war.build.dir}"/>
    </target>

    <target name="report-init">
        <mkdir dir="${report.build.dir}"/>
        <mkdir dir="${report.build.dir}/pmd"/>
    </target>

    <target name="pmd" depends="report-init">
        <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="project.class.path"/>
        <pmd rulesetfiles="imports,unusedcode,optimizations,basic,design,strictexception,strings,codesize,braces">
            <formatter type="html" toFile="${report.build.dir}/pmd/pmd.html"/>
            <fileset dir="${src.java.dir}">
                <include name="**/*.java"/>
            </fileset>
        </pmd>
    </target>

    <target name="javadoc" depends="init" description="Creates Javadoc.">
        <delete dir="${javadoc.dir}"/>
        <mkdir dir="${javadoc.dir}"/>
        <javadoc sourcepath="${src.java.dir}" destdir="${javadoc.dir}"
                 noqualifier="all" author="true" private="true" version="true"
                 classpathref="project.class.path">
            <packageset dir="${src.java.dir}">
                <include name="**/**"/>
            </packageset>
        </javadoc>
    </target>

    <target name="reports" depends="build, report-init, pmd, javadoc"/>

    <target name="jetty" depends="build-war-structure">
        <java classname="qwicket.myapp.util.Start" classpathref="project.class.path" fork="yes" failonerror="yes"/>
    </target>

    <target name="maven-ant" unless="maven.ant.available">
        <get src="http://apache.ntu.edu.tw/maven/binaries/maven-ant-tasks-${maven.version}.jar"
            dest="${maven.ant.file}"/>
    </target>

    <target name="deps" depends="maven-ant">
        <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant">
            <classpath>
                <pathelement location="${maven.ant.file}"/>
            </classpath>
        </typedef>

        <artifact:remoteRepository id="main" url="http://repo1.maven.org/maven2/"/>
        <artifact:remoteRepository id="java.net.repository"
                                   url="https://maven-repository.dev.java.net/nonav/repository/" layout="legacy"/>
        <artifact:remoteRepository id="jboss.repository" url="http://repository.jboss.com/maven2/"/>

        <artifact:dependencies pathId="build.class.path" filesetId="build.fileset">
            <remoteRepository refid="jboss.repository"/>
            <remoteRepository refid="java.net.repository"/>
            <remoteRepository refid="main"/>

            <dependency groupId="org.mortbay.jetty" artifactId="jetty" version="${jetty.version}"/>
            <dependency groupId="org.mortbay.jetty" artifactId="jetty-util" version="${jetty.version}"/>
            <dependency groupId="dom4j" artifactId="dom4j" version="1.6.1"/>
            <dependency groupId="org.apache.ant" artifactId="ant" version="1.7.1"/>
            <dependency groupId="pmd" artifactId="pmd" version="4.2.4"/>
        </artifact:dependencies>

        <artifact:dependencies pathId="base.class.path" filesetId="runtime.fileset">
            <remoteRepository refid="jboss.repository"/>
            <remoteRepository refid="java.net.repository"/>
            <remoteRepository refid="main"/>

            <dependency groupId="oswego-concurrent" artifactId="concurrent" version="1.3.4"/>
            <dependency groupId="c3p0" artifactId="c3p0" version="0.9.1.2"/>
            <dependency groupId="javax.mail" artifactId="mail" version="1.4.1"/>
            <dependency groupId="org.springframework" artifactId="spring" version="2.5.6"/>
            <dependency groupId="org.hibernate" artifactId="hibernate-annotations" version="3.4.0.GA"/>
            <dependency groupId="org.hibernate" artifactId="hibernate-entitymanager" version="3.4.0.GA"/>
            <dependency groupId="org.hibernate" artifactId="hibernate-core" version="3.3.1.GA"/>
            <dependency groupId="org.apache.wicket" artifactId="wicket" version="${wicket.version}"/>
            <dependency groupId="org.apache.wicket" artifactId="wicket-extensions" version="${wicket.version}"/>
            <dependency groupId="org.apache.wicket" artifactId="wicket-spring-annot" version="${wicket.version}"/>
            <dependency groupId="org.slf4j" artifactId="slf4j-api" version="1.5.6"/>
            <dependency groupId="org.slf4j" artifactId="slf4j-log4j12" version="1.5.6"/>

            <dependency groupId="org.apache.commons" artifactId="commons-email" version="1.1"/>
            <dependency groupId="hsqldb" artifactId="hsqldb" version="1.8.0.7"/>
            <dependency groupId="postgresql" artifactId="postgresql" version="8.3-603.jdbc3"/>
        </artifact:dependencies>
    </target>

    <target name="update-project" depends="init">
        <taskdef name="mvnProject" classname="qwicket.myapp.util.ProjectConfigTask" classpathref="project.class.path"/>

        <mvnProject idea="../../test-project-files/java.iml">
            <path refid="project.class.path"/>
        </mvnProject>
    </target>
</project>

如果執行完ant沒問題後,可以直接執行ant jetty來執行,然後開啟一個瀏覽器連到http://localhost:8080/來檢查看看能否加入一個會員。
另外,要注意的一點是,如果要連到PostgreSQL等其他資料庫要先開好帳號跟密碼及資料庫,例如都叫做qwicket。這部分可以修改web/WEB-INF/classes目錄下的application.properties或application-override.properties檔案。
另外,也可以執行ant reports來用PMD檢查看看原來的程式有沒有地方可以改善的。
附上我修改過的版本,如果您懶得自己慢慢修改,可以直接使用這個版本來改。
參考資料
http://www.antwerkz.com/qwicket/app/home
http://www.mindrot.org/projects/jBCrypt/
http://wicket.apache.org/examplemarkupinheritance.html
看起來可以用Greybox來作,可以參考這篇文章看看
http://www.andowson.com/posts/list/224.page
這些我在網路上找到由JGS goodsolutions GmbH對OLAT的Framework所做的說明,如果萬一原來的連結無法下載時可以下載本站的附檔。

http://www.jugs.ch/html/events/slides/051208_olat.ppt
http://www.goodsolutions.ch/shared/resources/framework.pdf

這個週末花了兩天終於把現有的OLAT由6.0.4升級至6.0.6, 步驟如下:
cd ~/download
mv olat3 olat-6.0.4
wget http://www.olat.org/downloads/stable/OLAT-6.0.6.zip
unzip OLAT-6.0.6.zip
mv OLAT-6.0.6-PUBLIC-* olat3
cd olat3
sed -e "s/\/usr\/local\/opt\/olat\/olat3/\/home\/andowson\/download\/olat3/g" \
-e "s/\/usr\/local\/opt\/olat\/olatdata/\/home\/andowson\/www\/data\/olatdata/g" \
-e "1,$$s/myolat/andowson/g" \
-e "s/smtp.host=smtp.andowson.com/smtp.host=mail.andowson.com/" \
-e "s/\/usr\/local\/opt\/tomcat/\/var\/tomcat5/g" \
-e "1,$$s/net.sf.hibernate/org.hibernate/g" \
-e "48c\server.modjk.enabled=true" \
-e "57c\defaultcharset=UTF-8" \
-e "95,117d" \
-e "1,$$s/#db/db/g" \
-e "s/instantMessaging.enable=false/instantMessaging.enable=true/" \
-e "s/instantMessaging.server.name=jabber.andowson.com/instantMessaging.server.name=www.andowson.com/" \
-e "s/instantMessaging.generateTestUsers=false/instantMessaging.generateTestUsers=true/" \
-e "s/instantMessaging.db.name=wildfire/instantMessaging.db.name=openfire/" \
-e "s/instantMessaging.db.user=wildfire/instantMessaging.db.user=olat/" \
-e "s/instantMessaging.db.pass=wildfire/instantMessaging.db.pass=olat/" \
-e "s/cluster.catalinaport=8005/cluster.catalinaport=8105/" \
-e "s/cluster.ajpport = 8009/cluster.ajpport = 8109/" build.properties.default > build.properties
ant install
ant jsmath
sudo /etc/init.d/tomcat stop
mv ~/www/olat /tmp/olat-6.0.4
cp -rf ~/download/olat3/webapp ~/www/olat
cp -rf ~/download/olat3/htdocs/* ~/www/olat
sed -i -e "13c\        <\!-- default session timeout -->" ~/www/olat/WEB-INF/web.xml
rm -rf ~/www/olat/WEB-INF/src
rm -rf ~/www/olat/WEB-INF/patchesSrc
rm -rf ~/www/olat/WEB-INF/test
cp /tmp/olat-6.0.4/WEB-INF/classes/hibernate.properties ~/www/olat/WEB-INF/classes/.
chgrp -R tomcat ~/www/olat
chgrp -R tomcat ~/www/data/olatdata
chmod 775 ~/www/olat/static
chmod 775 ~/www/olat/WEB-INF
sudo -u postgres pg_dump olat > /tmp/olat.bak
sudo /etc/init.d/tomcat start
cd ~/download
mv olat3 olat-6.0.0
wget http://www.olat.org/downloads/stable/OLAT-6.0.4.zip
unzip OLAT-6.0.4.zip
mv OLAT-6.0.4-FINAL-* olat3
cd olat3
sed -e "s/\/usr\/local\/opt\/olat\/olat3/\/home\/andowson\/download\/olat3/g" \
-e "s/\/usr\/local\/opt\/olat\/olatdata/\/home\/andowson\/www\/data\/olatdata/g" \
-e "1,$$s/myolat/andowson/g" \
-e "s/smtp.host=smtp.andowson.com/smtp.host=mail.andowson.com/" \
-e "s/\/usr\/local\/opt\/tomcat/\/var\/tomcat5/g" \
-e "1,$$s/net.sf.hibernate/org.hibernate/g" \
-e "48c\server.modjk.enabled=true" \
-e "95,117d" \
-e "1,$$s/#db/db/g" \
-e "s/instantMessaging.enable=false/instantMessaging.enable=true/" \
-e "s/instantMessaging.server.name=jabber.andowson.com/instantMessaging.server.name=www.andowson.com/" \
-e "s/instantMessaging.generateTestUsers=false/instantMessaging.generateTestUsers=true/" \
-e "s/instantMessaging.db.name=wildfire/instantMessaging.db.name=openfire/" \
-e "s/instantMessaging.db.user=wildfire/instantMessaging.db.user=olat/" \
-e "s/instantMessaging.db.pass=wildfire/instantMessaging.db.pass=olat/" build.properties.default > build.properties
ant install
ant jsmath
sudo /etc/init.d/tomcat stop
mv ~/www/olat /tmp/olat-6.0.0
cp -rf ~/download/olat3/webapp ~/www/olat
cp -rf ~/download/olat3/htdocs/* ~/www/olat
sed -i -e "13c\        <\!-- default session timeout -->" ~/www/olat/WEB-INF/web.xml
rm -rf ~/www/olat/WEB-INF/src
rm -rf ~/www/olat/WEB-INF/patchesSrc
rm -rf ~/www/olat/WEB-INF/test
cp /tmp/olat-6.0.0/WEB-INF/classes/hibernate.properties ~/www/olat/WEB-INF/classes/.
chgrp -R tomcat ~/www/olat
chgrp -R tomcat ~/www/data/olatdata
chmod 775 ~/www/olat/static
chmod 775 ~/www/olat/WEB-INF
sudo -u postgres pg_dump olat > /tmp/olat.bak
sudo psql -U olat olat -f  /home/andowson/download/olat3/database/postgresql/alter_6_0_0_to_6_0_3.sql
sudo psql -U olat olat -f  ~/download/olat3/database/postgresql/alter_6_0_0_to_6_0_3.sql
sudo /etc/init.d/tomcat start
要加上密碼也是可以的,只要將原本的zip.exe換一個可以加密碼的壓縮軟體執行檔即可,例如7-Zip這個免費又可以加上密碼的壓縮軟體的7z.exe。
1.到http://www.7-zip.org/下載安裝用的exe檔
2.執行下載的exe檔安裝
3.安裝完成後,將C:\Program Files\7-Zip下的7z.exe複製到C:\Windows\System32目錄下。

相關的參數可以在命令列下執行7z獲得:
7-Zip 4.57  Copyright (c) 1999-2007 Igor Pavlov  2007-12-06

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
       [<@listfiles...>]

<Commands>
  a: Add files to archive
  b: Benchmark
  d: Delete files from archive
  e: Extract files from archive (without using directory names)
  l: List contents of archive
  t: Test integrity of archive
  u: Update files to archive
  x: eXtract files with full paths
<Switches>
  -ai[r[-|0]]{@listfile|!wildcard}: Include archives
  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
  -bd: Disable percentage indicator
  -i[r[-|0]]{@listfile|!wildcard}: Include filenames
  -m{Parameters}: set compression Method
  -o{Directory}: set Output directory
  -p{Password}: set Password
  -r[-|0]: Recurse subdirectories
  -scs{UTF-8 | WIN | DOS}: set charset for list files
  -sfx[{name}]: Create SFX archive
  -si[{name}]: read data from stdin
  -slt: show technical information for l (List) command
  -so: write data to stdout
  -ssc[-]: set sensitive case mode
  -ssw: compress shared files
  -t{Type}: Set type of archive
  -v{Size}[b|k|m|g]: Create volumes
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
  -w[{path}]: assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
  -y: assume Yes on all queries


以下是一個執行命令的範例,會將目前整個目錄壓縮起來存到c:\backup.zip檔案,並加上密碼secret。
7z a -psecret c:\backup.zip *


所以原來程式簡易的修改方式如下:
將第29行的程式碼取代為:
set ZIPPASSWORD=secret
7z a -p%ZIPPASSWORD% %BACKUPFILE% %TARGET%\*  
1.安裝:
smilie 安裝容易,可手動或透過網頁介面安裝
smilie 支援多種Servlet Container或應用伺服器,如Tomcat、Resin、JBoss等
smilie 支援多種資料庫,包含MySQL、PostgreSQL、Oracle和HSQLDB
smilie 可輕易由phpBB移轉

2.一般:
smilie 可列出主題、作者、篇數、人氣度、發表時間
smilie 支援無限數量的分類、版面和文章主題
smilie 可對文章及使用者進行評分
smilie 可收藏主題到個人書籤且可設定是否公開
smilie 支援友善的網址
smilie 可列出線上使用者名單及線上人數
smilie 可顯示整個討論區的最新主題(依最後發表時間)
smilie 可顯示整個討論區的熱門主題(依點閱次數)
smilie 支援全文檢索,可對文章內容進行關鍵字搜尋
smilie 速度快且易於擴充,最適合忙碌的站台,暫存經常存取的資料到快取區,以避免大量的資料庫查詢動作

3.發表文章:
smilie 可附加檔案到文章,並可設定附加檔案的類型及每篇文章最多幾個附加檔案
smilie 支援HTML語法和表情符號(BBCode)
smilie 自動解析文章中的超連結
smilie 提供整合的私人訊息系統
smilie 電子郵件通知有新的私人訊息及設定文章回覆時通知
smilie 支援無限數量的表情符號,可輕易的由管理介面設定
smilie 支援RSS 聯播(syndication)
smilie 可設定文章主題為公告或置頂
smilie 張貼文章前提供預覧功能
smilie 可設定投票主題及選項

4.版面管理:
smilie 文章審核機制,管理者可設定只有通過版主審核過的文章才能顯示
smilie 可鎖定/解除鎖定文章主題且可在版面間搬移

5.權限及安全性:
smilie 可設定唯讀的版面,只能閱讀,不能新增文章
smilie 可設定僅能回覆的版面,只能回覆給已經存在的文章
smilie 可設定版面管理員群組,並可設定該群組可審核的版面
smilie 可過濾HTML語法,增進安全性
smilie 可設定某個使用者群組可以瀏覽的分區及版面
smilie 可設定匿名訪客僅能閱讀文章,需加入會員並登入後才能發表文章及下載附件
smilie 可設定是否開放會員註冊

資料來源:
http://www.jforum.net/features.jsp
有種方法,不知道管不管用,做張網頁截圖,例如
image
可以利用下列網址產生
http://ppt.cc/yo2/index.php
然後你再將該截圖抓回來放到你的網站上去
再把img src的來源指到你的網站上
不知道您的需求是不是如下:
網站A,動態產生廣告圖片網頁test1.jsp,內容為文字HTML標籤
網站B,只能放HTML的靜態網頁空間,想要將網站A的test1.jsp的結果顯示在一個網頁,例如showTest1.html上
可行的作法是在網站B上使用<frame>或<iframe>或者<javascript>的src屬性去設定來源URL為網站A的test1.jsp
現在您是指,如果不使用上面這幾個標籤時,可以改用img的src屬性來達成嗎?
請先確認test3.jsp一次要顯示幾張圖?這些圖放在哪邊?然後跟test1.jsp有什麼關係?
也許你需要的只是在test3.jsp中使用<jsp:include page="test1.jsp" />
test2.jsp內的第五行
File f = new File("C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\ROOT\\test1.jsp");

要改成
File f = new File("C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\ROOT\\images\\xxx.gif");


test3.jsp的第四行應修正為:
<td><img src="http://localhost:8080/test2.jsp"></td>
可以參考這一篇
A simple way to display database blob stored image in a jsp
要注意的重點就是,
1.JSP頁面內不能有文字輸出,要全部用<% ... %>包圍起來,不能有HTML的標籤被輸出。
2.ContentType要設定為image/gif, image/jpeg, ...。
3.重新由response取得OutputStream,因原本的out物件是屬於文字輸出型的。
       // get the image from any source
       byte[] imgData = getYourImage();  
       // display the image
       response.setContentType("image/gif");
       OutputStream o = response.getOutputStream();
       o.write(imgData);
       o.flush();
       o.close();
檢查日誌檔內有關Queue Manager的警告訊息,指令如下:
egrep 'qmgr.*(panic|fatal|error|warning):' /var/log/maillog

參考資料:
http://www.postfix.org/QSHAPE_README.html

將所有信件刪除,指令如下:
postsuper -d ALL

參考資料:
http://actychen.blogspot.com/2008/03/postfix-mail-queue.html
lpi是一個net.jforum.entities.LastPostInfo類別的物件,包含底下幾個符合JavaBean定義的屬性(properties):
postTimeMillis
topicId
postId
userId
topicReplies
username
postDate
hasInfo

JForum使用FreeMarker作為template engine,所以,我們可以透過lpi.userId來呼叫LastPostInfo的getUserId()來取得某個版面最後發表的文章資訊。

您可以參考此篇JForum Eclipse WTP開發環境設定來建立您的JForum開發環境,對於原始碼的追蹤就會變得很容易。

參考資料:
http://freemarker.org/docs/pgui_quickstart_createdatamodel.html
 
Forum Index » Profile for andowson » Messages posted by andowson
Go to: