??xml version="1.0" encoding="utf-8" standalone="yes"?>日韩精品视频在线,欧美亚洲系列,国产在线播放精品http://www.aygfsteel.com/pepsixp/I am strong, I am in Suzhou.zh-cnWed, 18 Jun 2025 04:23:39 GMTWed, 18 Jun 2025 04:23:39 GMT60搬家?/title><link>http://www.aygfsteel.com/pepsixp/archive/2007/07/06/128463.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Thu, 05 Jul 2007 16:10:00 GMT</pubDate><guid>http://www.aygfsteel.com/pepsixp/archive/2007/07/06/128463.html</guid><description><![CDATA[CQ新的坑Q?a >http://amsz.yo2.cn/</a>  <img src ="http://www.aygfsteel.com/pepsixp/aggbug/128463.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pepsixp/" target="_blank">阿姆斯壮</a> 2007-07-06 00:10 <a href="http://www.aygfsteel.com/pepsixp/archive/2007/07/06/128463.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>安装 DokuWikihttp://www.aygfsteel.com/pepsixp/archive/2007/06/14/DokuWiki.html阿姆斯壮阿姆斯壮Thu, 14 Jun 2007 14:13:00 GMThttp://www.aygfsteel.com/pepsixp/archive/2007/06/14/DokuWiki.htmlhttp://www.aygfsteel.com/pepsixp/comments/124370.htmlhttp://www.aygfsteel.com/pepsixp/archive/2007/06/14/DokuWiki.html#Feedback0http://www.aygfsteel.com/pepsixp/comments/commentRss/124370.htmlhttp://www.aygfsteel.com/pepsixp/services/trackbacks/124370.html环境QLinux AS4、Apache2.2、PHP 4.4.7、DokuWiki-2007-05-24

Apache的安装见前文

PHP

  1. 下蝲php-4.4.7.tar.gzQ解?
  2. ./configure --with-apxs2=$APACHE_HOME/bin/apxs
  3. make & make install
  4. cp php.ini-dist &PHP_HOME/etc/php.ini

DokuWiki

  1. 下蝲dokuwiki-2006-11-06.tgzQ解?
  2. 为apachedrewrite模块Q?br>cd $APACHE_HOME/modules/mappers
    $APACHE_HOME/bin/apxs -i -a -c mod_rewrite.c
  3. 查httpd.conf中是否已l加入:LoadModule rewrite_module libexec/mod_rewrite.so
  4. 配置apache的httpd.conf
    Alias /wiki "/local/xsun/servers/dokuwiki"
    <Directory "$DokuWiki_HOME">
    Allow from all 

    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps
    RewriteEngine on

    RewriteBase /wiki

    RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L]
    RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L]
    RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1
    &id=$2  [QSA,L]
    RewriteRule ^$                        doku.php  [L]
    RewriteCond %{REQUEST_FILENAME}       !-f
    RewriteCond %{REQUEST_FILENAME}       !-d
    RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
    RewriteRule ^index.php$               doku.php
    php_value auto_prepend_file "$DokuWiki_HOME/prepend.php"
    </Directory>
  5. $APACHE_HOME/bin/apachectl start

DokuWiki 安全配置

?DokuWiki_HOME目录下创建prepend.phpQ和apache的配|文件对应,在执行会预先加蝲
<?php
define('DOKU_CONF','$DokuWiki_HOME/conf/');
define('DOKU_INC','$DokuWiki_HOME');
?>

然后?DokuWiki_HOME目录下的文g多wUdQ例?Wiki_HOME
ln -s $DokuWiki_HOME/lib $Wiki_HOME/lib
?DokuWiki_HOME/conf/local.php文g中添加:$conf['savedir'] = '$Wiki_HOME/data';
在浏览器中打开install.phpQ配|完后将q个文g删除

下面是我配置q的文gQ?br>local.php:
$conf['title'] = 'My Wiki';
$conf['useacl'] = 1;
$conf['superuser'] = '@admin';
$conf['userewrite'] = '1';
$conf['useslash'] = 1;
$conf['sepchar'] = '-';
$conf['openregister'] = '0';

 $conf['savedir'] = '/local/xsun/wiki/data';
@include(DOKU_CONF.'local.protected.php');

users.auth.php:
test:61e7250f72098cf2602541ffbaf66e59:LALALA:pepsixp@gmail.com:admin,user

acl.auth.php:
*               @ALL          1
*               @user         8



阿姆斯壮 2007-06-14 22:13 发表评论
]]>
PEPSIXPhttp://www.aygfsteel.com/pepsixp/archive/2007/06/13/123739.html阿姆斯壮阿姆斯壮Tue, 12 Jun 2007 16:08:00 GMThttp://www.aygfsteel.com/pepsixp/archive/2007/06/13/123739.htmlhttp://www.aygfsteel.com/pepsixp/comments/123739.htmlhttp://www.aygfsteel.com/pepsixp/archive/2007/06/13/123739.html#Feedback0http://www.aygfsteel.com/pepsixp/comments/commentRss/123739.htmlhttp://www.aygfsteel.com/pepsixp/services/trackbacks/123739.htmlPEPSIXP = PEPSI + XP = 百事可乐 + 极限~程 = 一个爱喝百事可乐,向往加入敏捷团队的程序员
C?a target=_blank>敏捷团队看得我心直痒痒,貌似看到了一个程序员的天堂。有的团队成天忙忙碌,q度~慢Bug大堆q浪费了自己大好的年华;有的团队d哈哈Q却有着极高的工作效率,q就是环境带来的差异?br>
x嫁错郎Q男怕入错行Q老话没错的!写在公司又一同志职当天晚上?/p>

阿姆斯壮 2007-06-13 00:08 发表评论
]]>
IDEA 6与Junit 4 版本不兼?/title><link>http://www.aygfsteel.com/pepsixp/archive/2007/04/04/108428.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Wed, 04 Apr 2007 06:43:00 GMT</pubDate><guid>http://www.aygfsteel.com/pepsixp/archive/2007/04/04/108428.html</guid><wfw:comment>http://www.aygfsteel.com/pepsixp/comments/108428.html</wfw:comment><comments>http://www.aygfsteel.com/pepsixp/archive/2007/04/04/108428.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pepsixp/comments/commentRss/108428.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pepsixp/services/trackbacks/108428.html</trackback:ping><description><![CDATA[IDEA 6.0.4 不能跑Junit4.2 - <a target=_blank>ISSUES<br></a>IDEA 6.0.5 不能跑Junit4.3 - <a target=_blank>ISSUES</a><br><br>Intellij IDEAL慢一拍,所以最高版本的配置是QIDEA 6.0.5 + Junit4.2 <img src ="http://www.aygfsteel.com/pepsixp/aggbug/108428.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pepsixp/" target="_blank">阿姆斯壮</a> 2007-04-04 14:43 <a href="http://www.aygfsteel.com/pepsixp/archive/2007/04/04/108428.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate OneToOne 复合主键http://www.aygfsteel.com/pepsixp/archive/2007/02/01/97387.html阿姆斯壮阿姆斯壮Thu, 01 Feb 2007 15:55:00 GMThttp://www.aygfsteel.com/pepsixp/archive/2007/02/01/97387.htmlhttp://www.aygfsteel.com/pepsixp/comments/97387.htmlhttp://www.aygfsteel.com/pepsixp/archive/2007/02/01/97387.html#Feedback0http://www.aygfsteel.com/pepsixp/comments/commentRss/97387.htmlhttp://www.aygfsteel.com/pepsixp/services/trackbacks/97387.html主表有两个字D|到副表Q可以取得唯一记录Q但q条记录不定存在Q这两个字段需要做条gqoQ就q个状况?/p>

Hibernate Annotation 配置的注意点Q?/p>

HQL
select  s from ScopeProjection s  left   join fetch s.overridewhere s.hubsite=ands.companyabbr=?

CODE
@Entity
@SequenceGenerator(name
= " SEQ_GEN " , sequenceName = " SCOPEPROJECTIONSEQ " )
public   class  ScopeProjection  implements  Serializable {
    
private  Integer id;
    
private  String hubsite;
    
private  String companyabbr;
    
private  ScopeProjectionOverride override;

    @Id
    @Column(name 
=   " PROJECTIONID " )
    @GeneratedValue(strategy 
=  GenerationType.AUTO, generator  =   " SEQ_GEN " )
    
public  Integer getId() {
        
return  id;
    }

    
public   void  setId(Integer id) {
        
this .id  =  id;
    }

    @Column(name 
=   " HUBSITENAME " , nullable  =   false , insertable  =   false , updatable  =   false )
    
public  String getHubsite() {
        
return  hubsite;
    }

    
public   void  setHubsite(String hubsite) {
        
this .hubsite  =  hubsite;
    }

    @Column(name 
=   " COMPANYABBREVIATION " , nullable  =   false , insertable  =   false , updatable  =   false )
    
public  String getCompanyabbr() {
        
return  companyabbr;
    }

    
public   void  setCompanyabbr(String companyabbr) {
        
this .companyabbr  =  companyabbr;
    }
    
    @OneToOne(cascade 
=  CascadeType.PERSIST)
    @JoinColumns ({
        @JoinColumn(name 
=   " COMPANYABBREVIATION " , referencedColumnName  =   " COMPANYABBREVIATION " ),
        @JoinColumn(name 
=   " HUBSITENAME " , referencedColumnName  =   " HUBSITENAME " )
    })
    
public  ScopeProjectionOverride getOverride() {
        
return  override;
    }

    
public   void  setOverride(ScopeProjectionOverride override) {
        
this .override  =  override;
    }
}

@Entity
@SequenceGenerator(name
= " SEQ_GEN " , sequenceName = " SCOPEOVERRIDESEQ " )
public   class  ScopeProjectionOverride  implements  Serializable {
    
private  Integer id;
    
private  String companyabbr;
    
private  String hubsitename;

    @Id
    @Column(name 
=   " OVERRIDEID " )
    @GeneratedValue(strategy 
=  GenerationType.AUTO, generator  =   " SEQ_GEN " )
    
public  Integer getId() {
        
return  id;
    }

    
public   void  setId(Integer id) {
        
this .id  =  id;
    }

    @Column(name 
=   " COMPANYABBREVIATION " )
    
public  String getCompanyabbr() {
        
return  companyabbr;
    }

    
public   void  setCompanyabbr(String companyabbr) {
        
this .companyabbr  =  companyabbr;
    }

    
public  String getHubsitename() {
        
return  hubsitename;
    }

    
public   void  setHubsitename(String hubsitename) {
        
this .hubsitename  =  hubsitename;
    }
}


阿姆斯壮 2007-02-01 23:55 发表评论
]]>
SVN 配置http://www.aygfsteel.com/pepsixp/archive/2006/12/21/89268.html阿姆斯壮阿姆斯壮Thu, 21 Dec 2006 05:38:00 GMThttp://www.aygfsteel.com/pepsixp/archive/2006/12/21/89268.htmlhttp://www.aygfsteel.com/pepsixp/comments/89268.htmlhttp://www.aygfsteel.com/pepsixp/archive/2006/12/21/89268.html#Feedback0http://www.aygfsteel.com/pepsixp/comments/commentRss/89268.htmlhttp://www.aygfsteel.com/pepsixp/services/trackbacks/89268.html创徏
  1. mkdir /etc/svn/repos1
  2. svnadmin create /etc/svn/repos1
  3. svn import file:///etc/svn/repos1  --message "init" // 导入当前目录下所以文?br />svn import /local/mydir/ file:///etc/svn/repos1  --message "init" // 导入指定目录下所以文?

查看

  • svn list --verbose file:///etc/svn/repos1/
  • svnlook info /etc/svn/repos1/
  • svnlook tree /etc/svn/repos1/ --show-ids

Apache权限控制

${apache}/conf/httpd.conf 的配|:
LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules
/mod_authz_svn.so
<Location /svn/>
DAV svn
SVNParentPath 
/etc/svn/repos1
SVNListParentPath on

AuthType Basic
AuthName 
"MY SVN Repository"
AuthUserFile 
/etc/svn/repos1/passwd.conf
AuthzSVNAccessFile 
/etc/svn/repos1/authz.conf
Require vaild-user
</Location>

创徏用户和密码:${apache}/bin/htpasswd /etc/svn/repos1/authz.comf user1

authz.conf的配|:
[groups]
group1 
= user1
group2 
= user1,user2

[
/]
* = r

[project1
:/path1]
@group1 = rw

[project1
:/path2]
@group2 = rw

取出Qsvn co file:///etc/svn/report1

另外需要修改两个地方,不然无法提交修改的文Ӟ

  1. chown -R sysuser:sysuser /etc/svn/report1
    chmod -R 700 /etc/svn/report1
  2. ?{apache}/conf/httpd.conf中找刎ͼ
    User daemon
    Group daemon
    改ؓ
    User sysuser
    Group sysuser
    以root用户启动apache后,自动切换到sysuserw䆾q行


阿姆斯壮 2006-12-21 13:38 发表评论
]]>
Apache + Subversion 安装http://www.aygfsteel.com/pepsixp/archive/2006/12/04/85237.html阿姆斯壮阿姆斯壮Mon, 04 Dec 2006 05:16:00 GMThttp://www.aygfsteel.com/pepsixp/archive/2006/12/04/85237.htmlhttp://www.aygfsteel.com/pepsixp/comments/85237.htmlhttp://www.aygfsteel.com/pepsixp/archive/2006/12/04/85237.html#Feedback0http://www.aygfsteel.com/pepsixp/comments/commentRss/85237.htmlhttp://www.aygfsteel.com/pepsixp/services/trackbacks/85237.html环境QSunOS 5.9 Generic、Apache-2.2.3、Subversion-1.4.2

Apache

  1. 下蝲httpd-2.2.3.tar.gzQ解?
  2. 查path是否加入了:/usr/ccs/binQ这是我make报错的根源,之后׃马^川了
  3. $ ./configure --enable-dav --enable-so --prefix=/usr/local/apache2/
  4. $ make;make install
  5. 修改/usr/local/apache2/conf/httpd.conf中的ServerName的配|,写上服务器的IP地址和端口号Q例如ServerName  12.34.56.78:80
  6. q入bin目录启动(需要root)Q? ./apachectl start
  7. 打开览?a href="http://ip_address/">http://ip_address/Q等待测试页"It works!"的出?:_)

Subversion

  1. 下蝲neon-0.26.2.tar.gzQ解?
  2. $ ./configure --prefix=/usr/local/neon; make; make install
  3. 下蝲subversion-1.4.2.tar.gzQ解?
  4. $ ./configure --prefix=/usr/local/subversion --with-apxs=/usr/local/apache2/bin/apxs --with-apr=/usr/local/apache2 --with-apr-util=/usr/local/apache2 --with-neon=/usr/local/neon --with-ssl --with-zlib
  5. $ make;make install
  6. 修改apache配置文ghttpd.confQ?br />LoadModule dav_svn_module modules/mod_dav_svn.so 
    LoadModule authz_svn_module modules/mod_authz_svn.so 
    <Location /svn>
    DAV svn 
    SVNParentPath /home/svnroot/
    </Location>
  7. 创徏仓库Q?br />$ mkdir /home/svnroot/
    $ cd /usr/local/subversion/bin
    $ ./svnadmin create /home/svnroot/test
    $ ./svn import /home/user/import file:///home/svnroot/test –m "import files test"
  8. 重启Apache
    $ ./usr/local/apache2/bin/apachectl restart
    打开览器:http://localhost/svn/test Q应该能看到些什么东?


阿姆斯壮 2006-12-04 13:16 发表评论
]]>
Ubuntu6.10 - 初始?/title><link>http://www.aygfsteel.com/pepsixp/archive/2006/11/12/80654.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Sat, 11 Nov 2006 16:52:00 GMT</pubDate><guid>http://www.aygfsteel.com/pepsixp/archive/2006/11/12/80654.html</guid><wfw:comment>http://www.aygfsteel.com/pepsixp/comments/80654.html</wfw:comment><comments>http://www.aygfsteel.com/pepsixp/archive/2006/11/12/80654.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pepsixp/comments/commentRss/80654.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pepsixp/services/trackbacks/80654.html</trackback:ping><description><![CDATA[升了一下ubuntuQ记录一?br /><ol><li>Ȁzroot用户Q?br /> sudo passwd root</li><li>修改源:<br /> sudo gedit /etc/apt/sources.list<br />删除所有内容ƈd如下信息(江苏省常州市电信)Q?br />deb http://ubuntu.cn99.com/ubuntu/ edgy main restricted universe multiverse<br />deb http://ubuntu.cn99.com/ubuntu/ edgy-security main restricted universe multiverse<br />deb http://ubuntu.cn99.com/ubuntu/ edgy-updates main restricted universe multiverse<br />deb http://ubuntu.cn99.com/ubuntu/ edgy-proposed main restricted universe multiverse<br />deb http://ubuntu.cn99.com/ubuntu/ edgy-backports main restricted universe multiverse<br />deb http://ubuntu.cn99.com/ubuntu-cn/ edgy main restricted universe multiverse</li><li>升pȝQ?br />sudo apt-get update<br /> sudo apt-get dist-upgrade</li><li>讄本地local环境Q?br />sudo dpkg-reconfigure locales</li><li>安装中文语言支持:<br />do apt-get install language-pack-gnome-zh language-pack-gnome-zh-base language-pack-zh language-pack-zh-base language-support-zh<br /></li><li> 安装中文字体Q?br />sudo apt-get install ttf-arphic-ukai ttf-arphic-uming</li><li>安装~译环境:<br /> sudo apt-get install build-essential</li><li>更改 GRUB 菜单内开机系l的预设?br />sudo vi /boot/grub/menu.lst<br />修改 ... default 0 ...<br /></li></ol>好了Q注销一下电脑,再次d后按 Ctrl + I格?Ȁz输入法) 应该可以使用Qƈ且整个界面都是中文的了?img src ="http://www.aygfsteel.com/pepsixp/aggbug/80654.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pepsixp/" target="_blank">阿姆斯壮</a> 2006-11-12 00:52 <a href="http://www.aygfsteel.com/pepsixp/archive/2006/11/12/80654.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用DbUnithttp://www.aygfsteel.com/pepsixp/archive/2005/09/05/12124.html阿姆斯壮阿姆斯壮Mon, 05 Sep 2005 15:05:00 GMThttp://www.aygfsteel.com/pepsixp/archive/2005/09/05/12124.htmlhttp://www.aygfsteel.com/pepsixp/comments/12124.htmlhttp://www.aygfsteel.com/pepsixp/archive/2005/09/05/12124.html#Feedback0http://www.aygfsteel.com/pepsixp/comments/commentRss/12124.htmlhttp://www.aygfsteel.com/pepsixp/services/trackbacks/12124.html当我刚开始编写和数据库有关的单元试Ӟq道这些测试代码在下次q行的时候可能无法完全通过Q因为它和数据紧密的联系在一P但也想不Z个好的解x案。它只保证了当时的代码是没有问题的,一个星期后Q不Q可能在q次单元试q行完后Q就应该丢进垃圾桶了?BR>q种吃力不讨好的行ؓ持箋了一D|_直到引入了DbUnit之后。它实能够的保证数据库处于一个稳定的状态,无须对其q行人工q预Q操作也非常单?BR>
创徏一?STRONG>DbUnit Test Case
。。?BR>



阿姆斯壮 2005-09-05 23:05 发表评论
]]>
加班l束?/title><link>http://www.aygfsteel.com/pepsixp/archive/2005/03/26/2492.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Sat, 26 Mar 2005 15:49:00 GMT</pubDate><guid>http://www.aygfsteel.com/pepsixp/archive/2005/03/26/2492.html</guid><wfw:comment>http://www.aygfsteel.com/pepsixp/comments/2492.html</wfw:comment><comments>http://www.aygfsteel.com/pepsixp/archive/2005/03/26/2492.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pepsixp/comments/commentRss/2492.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pepsixp/services/trackbacks/2492.html</trackback:ping><description><![CDATA[从上个星期五Q到q个星期五,整整一个星期,每天8:30上班Q?2Q?0下班Q感觉是整个人都买给公司了,回到家能做的事情剩睡觉了。第一ơ这Lq箋奋战Qh倒是没怎么感到累,也许都习惯了吧,反正在家的时候也常常12多才睡觉的。唯一的不满就是伙食,早饭是用饼干解决的,起床发现眼睛肿或眼圈发黑,再奖赏自己一袋牛Ӟ中午把胃买给了科技园的食堂Q食堂的饭是那宁愉K择泡面也不d它饭的那U,但没办法Q垄断经营,不吃的话Q就要吃两顿泡面了,防腐剂涉入太多,人就ҎLQ晚饭光临可的,主食除了方便面,再加些没营养的豆腐干、薯片之cȝ雉。把w体折腾了一个星期,肚子l于忍不住反抗了Q星期五的晚上咕咕直叫,星期六就跑肚拉稀的过了一个上午,看看镜子里的我,ȝ一只?BR><BR>好不Ҏ坚持了一个星期的晨跑Q被q突入其来的加班冲的不知哪边M。不知下个星期还能不能l坚持下去,w体啊n体啊Q老了可别怪我Q谁让你q么懒的。工作了一q多Q现在一直感到脖子痛Q白发也多了不少Q背部时不时的也会生一늖痛,一直怀疑是不是脊椎Z什么问题,正好那时在看《白影》,江直发病时痛苦的表情Q害我恐惧了整一个星期,后来和同事的交流中才发现Q是凛_的问题,他们也有q种情况发生Q现在换凛_了,q个症状也没有出C。在q箋一个星期的晨跑坚持下来后,_和n子骨出奇的爽朗,跑\脚底都觉得很ȝQ但是早?点爬hQ对我来说太有难度了Q这可比加一个星期的班难多了。想想现在这U用w体换金q方式Q和民工有什么区别,可能q民工都不如吧。什么事情都贵在坚持Q晨跑是q样Q工作也是这栗?BR><BR>研究生很厉害Q不见得Q只能说是良莠不齐!q次加了q么多的班,有部分原因就是他们造成的。公司外包给他们的程序,最后由我做试和修改,看看源代码,q最L的变量名首字母小写都不能遵守Q还指望在代码中扑ֈ一D优雅的代码以供学习吗?异常处理Q日志输出,代码重用Q随心所Ʋ的做,好像完全是ؓ了完成Q务而做的,当我把代码测试ƈ修改完后Q发现有些类剩下的代码数量甚臌原来的一半都不到Q哈哈,修啊修啊改啊改啊Q一个星期的光阴很快pMQ失M一些,也得C一些?BR><BR>最q被《钢之炼金术士》感动不Ԍ没有牺牲没有获得,惌得到什么,必M出同{的代hQ这是炼金术中的{h交换原则Q也是现实中的等价交换原则!<img src ="http://www.aygfsteel.com/pepsixp/aggbug/2492.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pepsixp/" target="_blank">阿姆斯壮</a> 2005-03-26 23:49 <a href="http://www.aygfsteel.com/pepsixp/archive/2005/03/26/2492.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习FreeMarkerQ二Q?/title><link>http://www.aygfsteel.com/pepsixp/archive/2005/03/11/1941.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Fri, 11 Mar 2005 03:08:00 GMT</pubDate><guid>http://www.aygfsteel.com/pepsixp/archive/2005/03/11/1941.html</guid><wfw:comment>http://www.aygfsteel.com/pepsixp/comments/1941.html</wfw:comment><comments>http://www.aygfsteel.com/pepsixp/archive/2005/03/11/1941.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pepsixp/comments/commentRss/1941.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pepsixp/services/trackbacks/1941.html</trackback:ping><description><![CDATA[<P><STRONG>用户定义指o</STRONG>Q用@W合来调?BR>有两U不同的cdQMacro(?和transform(传递器)QMacro是在模板中用macro指o定义Q而transform是在模板外由E序定义(基本上都是基于Java?Q这里通过Macro来介l自定义指o?BR>例一Q?BR><#macro greet><BR>  <font size="+2">Hello Joe!</font><BR></#macro>  <BR>使用Q?lt;@greet><<A>/@greet</A>> ?<@greet/><BR>l果Q?lt;font size="+2">Hello Joe!</font></P> <P>参数Q在macro指o中可以在宏变量之后定义参?BR>例二Q?BR><#macro greet person><BR>  <font size="+2">Hello ${person}!</font><BR></#macro> <BR>使用Q?lt;@greet person="Fred"/> and <@greet person="Batman"/> <BR>l果Q?<font size="+2">Hello Fred!</font> and <font size="+2">Hello Batman!</font></P> <P>macro可以有多个参敎ͼ参数的次序是无关的,在macro指o中只能用定义的参数Qƈ且必d所有参数赋|可以在定义参数时指定~省|</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#macro </SPAN><SPAN style="COLOR: #ff0000">greet person color</SPAN><SPAN style="COLOR: #0000ff">="black"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">font </SPAN><SPAN style="COLOR: #ff0000">size</SPAN><SPAN style="COLOR: #0000ff">="+2"</SPAN><SPAN style="COLOR: #ff0000"> color</SPAN><SPAN style="COLOR: #0000ff">="${color}"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Hello ${person}!</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">font</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#macro</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"> <BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV> <P><BR><STRONG>在自定义指o嵌套内容</STRONG>Q模板片断中使用<#nested>指o</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#macro </SPAN><SPAN style="COLOR: #ff0000">border</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">table </SPAN><SPAN style="COLOR: #ff0000">border</SPAN><SPAN style="COLOR: #0000ff">=4 </SPAN><SPAN style="COLOR: #ff0000">cellspacing</SPAN><SPAN style="COLOR: #0000ff">=0 </SPAN><SPAN style="COLOR: #ff0000">cellpadding</SPAN><SPAN style="COLOR: #0000ff">=4><tr><td><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    </SPAN><SPAN style="COLOR: #ff0000"><#nested</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">tr</SPAN><SPAN style="COLOR: #0000ff">></</SPAN><SPAN style="COLOR: #800000">td</SPAN><SPAN style="COLOR: #0000ff">></</SPAN><SPAN style="COLOR: #800000">table</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#macro</SPAN><SPAN style="COLOR: #0000ff">></SPAN></DIV></DIV> <P>使用Q?lt;@border>The bordered text<<A>/@border</A>><BR>l果Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">table </SPAN><SPAN style="COLOR: #ff0000">border</SPAN><SPAN style="COLOR: #0000ff">=4 </SPAN><SPAN style="COLOR: #ff0000">cellspacing</SPAN><SPAN style="COLOR: #0000ff">=0 </SPAN><SPAN style="COLOR: #ff0000">cellpadding</SPAN><SPAN style="COLOR: #0000ff">=4><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #ff0000"><tr</SPAN><SPAN style="COLOR: #0000ff">><</SPAN><SPAN style="COLOR: #800000">td</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">The bordered text<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">tr</SPAN><SPAN style="COLOR: #0000ff">></</SPAN><SPAN style="COLOR: #800000">td</SPAN><SPAN style="COLOR: #0000ff">></</SPAN><SPAN style="COLOR: #800000">table</SPAN><SPAN style="COLOR: #0000ff">></SPAN></DIV></DIV> <P><#nested>指o可以被多ơ调用:</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#macro </SPAN><SPAN style="COLOR: #ff0000">do_thrice</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#nested</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#nested</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#nested</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#macro</SPAN><SPAN style="COLOR: #0000ff">></SPAN></DIV></DIV> <P>使用Q?BR><@do_thrice>Anything.<<A>/@do_thrice</A>>  <BR>l果Q?BR>Anything.<BR>Anything.<BR>Anything. </P> <P><STRONG>注意</STRONG>Q嵌套内Ҏ无法讉K到macro中的局部变量的?BR>例如Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#macro </SPAN><SPAN style="COLOR: #ff0000">repeat count</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#local </SPAN><SPAN style="COLOR: #ff0000">y </SPAN><SPAN style="COLOR: #0000ff">= "test"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#list </SPAN><SPAN style="COLOR: #ff0000">1..count as x</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    ${y} ${count}/${x}: </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#nested</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#macro</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">@repeat </SPAN><SPAN style="COLOR: #ff0000">count</SPAN><SPAN style="COLOR: #0000ff">=3>${y?default("?")} </SPAN><SPAN style="COLOR: #ff0000">${x?default("?")} ${count?default("?")}</@repeat</SPAN><SPAN style="COLOR: #0000ff">></SPAN></DIV></DIV> <P>l果Q?BR>test 3/1: ? ? ?<BR>test 3/2: ? ? ?<BR>test 3/3: ? ? ?</P> <P><BR>下面是一个嵌套用自定义指o的例子:</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">@border</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">ul</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">@do_thrice</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">><</SPAN><SPAN style="COLOR: #800000">@greet </SPAN><SPAN style="COLOR: #ff0000">person</SPAN><SPAN style="COLOR: #0000ff">="Joe"</SPAN><SPAN style="COLOR: #0000ff">/></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">@do_thrice</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">ul</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">@border</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"> </SPAN></DIV></DIV> <P>l果Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">table </SPAN><SPAN style="COLOR: #ff0000">border</SPAN><SPAN style="COLOR: #0000ff">=4 </SPAN><SPAN style="COLOR: #ff0000">cellspacing</SPAN><SPAN style="COLOR: #0000ff">=0 </SPAN><SPAN style="COLOR: #ff0000">cellpadding</SPAN><SPAN style="COLOR: #0000ff">=4><tr><td><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top> </SPAN><SPAN style="COLOR: #ff0000"><ul</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">><</SPAN><SPAN style="COLOR: #800000">font </SPAN><SPAN style="COLOR: #ff0000">size</SPAN><SPAN style="COLOR: #0000ff">="+2"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Hello Joe!</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">font</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">><</SPAN><SPAN style="COLOR: #800000">font </SPAN><SPAN style="COLOR: #ff0000">size</SPAN><SPAN style="COLOR: #0000ff">="+2"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Hello Joe!</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">font</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">li</SPAN><SPAN style="COLOR: #0000ff">><</SPAN><SPAN style="COLOR: #800000">font </SPAN><SPAN style="COLOR: #ff0000">size</SPAN><SPAN style="COLOR: #0000ff">="+2"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Hello Joe!</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">font</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">ul</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">tr</SPAN><SPAN style="COLOR: #0000ff">></</SPAN><SPAN style="COLOR: #800000">td</SPAN><SPAN style="COLOR: #0000ff">></</SPAN><SPAN style="COLOR: #800000">table</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">  </SPAN></DIV></DIV> <P>在macro?STRONG>使用循环变量</STRONG>Q作为nested指o的参C递@环变量的实际|而在调用用户定义指oӞ?lt;@?gt;开始标记的参数后面指定循环变量的名字:</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#macro </SPAN><SPAN style="COLOR: #ff0000">repeat count</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#list </SPAN><SPAN style="COLOR: #ff0000">1..count as x</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#nested </SPAN><SPAN style="COLOR: #ff0000">x, x/2, x</SPAN><SPAN style="COLOR: #0000ff">==count><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #ff0000"></#list</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#macro</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">@repeat </SPAN><SPAN style="COLOR: #ff0000">count</SPAN><SPAN style="COLOR: #0000ff">=4 </SPAN><SPAN style="COLOR: #ff0000">; c, halfc, last</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  ${c}. ${halfc}</SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#if </SPAN><SPAN style="COLOR: #ff0000">last</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"> Last!</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#if</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><A>/</SPAN><SPAN style="COLOR: #800000">@repeat</SPAN><SPAN style="COLOR: #0000ff"></A></SPAN></DIV></DIV> <P> l果Q?BR>1. 0.5<BR>2. 1<BR>3. 1.5<BR>4. 2 Last!</P> <P><STRONG>注意</STRONG>Q@环变量和用户定义指o开始标记指定的数目可以不同Q调用时指定@环变量,则多指定的g可见Q调用时多指定@环变量,多余的@环变量不会被创徏?BR><BR><STRONG>模板中的变量</STRONG>Q有三种cdQ?BR>1.) <STRONG>plain(全局)变量</STRONG>Q可以在模板的Q何地方访问,包括使用include指o插入的模板,使用assign指o创徏和替?BR>2.) <STRONG>局部变?/STRONG>Q在macro中有效,使用local指o创徏和替?BR>3.) <STRONG>循环变量</STRONG>Q只能存在于指o的嵌套内容,由指?如list)自动创徏Q宏的参数是局部变量,而不是@环变?/P> <P>用assign指o创徏和替换的例子Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">x </SPAN><SPAN style="COLOR: #0000ff">= 1>  </SPAN><SPAN style="COLOR: #ff0000"><#-- create variable x --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${x}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">x </SPAN><SPAN style="COLOR: #0000ff">= x </SPAN><SPAN style="COLOR: #ff0000">+ 3</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">replace variable x --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${x}  </SPAN></DIV></DIV> <P>l果Q?BR>1<BR>4</P> <P>局部变量隐?而不是覆?同名的plain变量Q@环变量隐藏同名的局部变量和plain变量Q下面是一个例子:</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">x </SPAN><SPAN style="COLOR: #0000ff">= "plain"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>1. ${x}  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">we see the plain var. here --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">@test</SPAN><SPAN style="COLOR: #0000ff">/></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>6. ${x}  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">the value of plain var. was not changed --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#list </SPAN><SPAN style="COLOR: #ff0000">["loop"] as x</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    7. ${x}  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">now the loop var. hides the plain var. --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">x </SPAN><SPAN style="COLOR: #0000ff">= "plain2"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">replace the plain var, hiding does not mater here --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    8. ${x}  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">it still hides the plain var. --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>9. ${x}  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">the new value of plain var. --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top> <BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#macro </SPAN><SPAN style="COLOR: #ff0000">test</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  2. ${x}  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">we still see the plain var. here --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#local </SPAN><SPAN style="COLOR: #ff0000">x </SPAN><SPAN style="COLOR: #0000ff">= "local"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  3. ${x}  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">now the local var. hides it --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#list </SPAN><SPAN style="COLOR: #ff0000">["loop"] as x</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    4. ${x}  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">now the loop var. hides the local var. --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  5. ${x}  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">now we see the local var. again --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#macro</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">  </SPAN></DIV></DIV> <P>l果Q?BR>1. plain<BR>  2. plain<BR>  3. local<BR>    4. loop<BR>  5. local<BR>6. plain<BR>    7. loop<BR>    8. loop<BR>9. plain2</P> <P>内部循环变量隐藏同名的外部@环变量,例如Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#list </SPAN><SPAN style="COLOR: #ff0000">["loop 1"] as x</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  ${x}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#list </SPAN><SPAN style="COLOR: #ff0000">["loop 2"] as x</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    ${x}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#list </SPAN><SPAN style="COLOR: #ff0000">["loop 3"] as x</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>      ${x}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    ${x}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  ${x}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">></SPAN></DIV></DIV> <P>l果Q?BR>loop 1<BR>    loop 2<BR>      loop 3<BR>    loop 2<BR>  loop 1 </P> <P>模板中的变量会隐藏(而不是覆盖)数据模型中同名变量,如果需要访问数据模型中的同名变量,使用Ҏ变量globalQ下面的例子假设数据模型中的user的值是Big JoeQ?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">user </SPAN><SPAN style="COLOR: #0000ff">= "Joe Hider"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${user}          </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">prints: Joe Hider --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${.globals.user} </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000">prints: Big Joe --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">  </SPAN></DIV></DIV> <P><STRONG>命名(namespaces)I间</STRONG>Q通常情况Q只使用一个命名空_UCؓd名空?main namespace)Q但你是不会意识到这些的Qؓ了创建可重用的macro、transforms或其它变量的集合(通常U库)Q必M用多命名I间Qؓ了防止同名冲H?/P> <P>首先创徏一个库(假设保存在lib/my_test.ftl?Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#macro </SPAN><SPAN style="COLOR: #ff0000">copyright date</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Copyright (C) ${date} Julia Smith. All rights reserved.<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">br</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Email: ${mail}</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#macro</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">  <BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">mail </SPAN><SPAN style="COLOR: #0000ff">= "jsmith@acme.com"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"> </SPAN></DIV></DIV> <P>使用import指o导入库到模板中,Freemarker会ؓ导入的库创徏新的命名I间Qƈ可以通过import指o中指定的hash(散列)变量讉K库中的变量:</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#import </SPAN><SPAN style="COLOR: #ff0000">"/lib/my_test.ftl" as my</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">mail</SPAN><SPAN style="COLOR: #0000ff">="fred@acme.com"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">@my</SPAN><SPAN style="COLOR: #ff0000">.copyright date</SPAN><SPAN style="COLOR: #0000ff">="1999-2002"</SPAN><SPAN style="COLOR: #0000ff">/></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${my.mail}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${mail}  </SPAN></DIV></DIV> <P>l果Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Copyright (C) 1999-2002 Julia Smith. All rights reserved.<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">br</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Email: jsmith@acme.com</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>jsmith@acme.com<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>fred@acme.com  </SPAN></DIV></DIV> <P>上面的例子中使用的两个同名变量ƈ没有冲突Q因为它们位于不同的命名I间</P> <P>可以使用assign指o在导入的命名I间中创建或替代变量Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#import </SPAN><SPAN style="COLOR: #ff0000">"/lib/my_test.ftl" as my</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${my.mail}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">mail</SPAN><SPAN style="COLOR: #0000ff">="jsmith@other.com"</SPAN><SPAN style="COLOR: #ff0000"> in my</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${my.mail}  </SPAN></DIV></DIV> <P>l果Q?BR><A href="mailto:jsmith@acme.com"><FONT color=#000000>jsmith@acme.com</FONT></A><BR><A href="mailto:jsmith@other.com"><FONT color=#000000>jsmith@other.com</FONT></A>  </P> <P>数据模型中的变量M地方都可见,也包括不同的命名I间Q下面修改了刚才创徏的库Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#macro </SPAN><SPAN style="COLOR: #ff0000">copyright date</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Copyright (C) ${date} ${user}. All rights reserved.</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#macro</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">mail </SPAN><SPAN style="COLOR: #0000ff">= "${user}@acme.com"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">   </SPAN></DIV></DIV> <P>假设数据模型中的user变量的值是FredQ?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#import </SPAN><SPAN style="COLOR: #ff0000">"/lib/my_test.ftl" as my</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">@my</SPAN><SPAN style="COLOR: #ff0000">.copyright date</SPAN><SPAN style="COLOR: #0000ff">="1999-2002"</SPAN><SPAN style="COLOR: #0000ff">/></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${my.mail}</SPAN></DIV></DIV> <P> l果Q?BR> <p>Copyright (C) 1999-2002 Fred. All rights reserved.</p><BR><A href="mailto:Fred@acme.com"><FONT color=#000000>Fred@acme.com</FONT></A>  <BR><BR><BR>参考:   <A blog - FreeMarker设计指南</A><BR>            <A >FreeMarker  in sourceforge.net</A></P><img src ="http://www.aygfsteel.com/pepsixp/aggbug/1941.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pepsixp/" target="_blank">阿姆斯壮</a> 2005-03-11 11:08 <a href="http://www.aygfsteel.com/pepsixp/archive/2005/03/11/1941.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习FreeMarkerQ一Q?/title><link>http://www.aygfsteel.com/pepsixp/archive/2005/03/11/1685.html</link><dc:creator>阿姆斯壮</dc:creator><author>阿姆斯壮</author><pubDate>Fri, 11 Mar 2005 03:00:00 GMT</pubDate><guid>http://www.aygfsteel.com/pepsixp/archive/2005/03/11/1685.html</guid><wfw:comment>http://www.aygfsteel.com/pepsixp/comments/1685.html</wfw:comment><comments>http://www.aygfsteel.com/pepsixp/archive/2005/03/11/1685.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.aygfsteel.com/pepsixp/comments/commentRss/1685.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/pepsixp/services/trackbacks/1685.html</trackback:ping><description><![CDATA[<P>FreeMarker是一个用Java~写的模板引擎,主要用来生成HTML Web面Q特别是ZMVC模式的应用程序。虽然FreeMarkerh一些编E的能力Q但不像PHPQ通常由JavaE序准备要显C的数据Q由FreeMarker模板生成面?nbsp; FreeMarker可以作ؓWeb应用框架一个组Ӟ但它与容器无养I在非Web应用E序环境也能工作的很好?FreeMarker适合作ؓMVC的视囄Ӟq能在模板中使用JSP标记库?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">html</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">head</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">title</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Welcome!</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">title</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">head</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">body</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">h1</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Welcome ${user}!</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">h1</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Our latest product:<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">a </SPAN><SPAN style="COLOR: #ff0000">href</SPAN><SPAN style="COLOR: #0000ff">="${latestProduct.url}"</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">${latestProduct.name}</SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">a</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">!<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">body</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">html</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">  <IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV> <P>上面的例子中Q在单的HTML中加入了一些由${…}包围的特定FreeMarker的指令,q个文gq为模板了。而user、latestProduct.url和latestProduct.name来自于数据模型,由JavaE序提供Q模板设计者就不用兛_数据从哪来的?/P> <P>FreeMarker模板中可以包括下面四U特定部分:<BR>一.) <STRONG>文本</STRONG>Q直接输?BR>?) <STRONG>FTL标记</STRONG>(FreeMarker模板语言标记)Q类gHTML标记Q名字前?(有些以@开始,用户自定义标?予以区分Q不会输出?BR><STRONG>字符?/STRONG>Q?使用单引h双引号限定;如果包含Ҏ字符需要{义符Q?{"It's \"quoted\" andthis is a backslash: \\"}<BR>有一cȝD的字符?${r"C:\foo\bar"}Q输出结构ؓQC:\foo\barQ在引号前面加r被认为是U文本?<BR>数字Q直接输入,不需要引受?{08}, ${+8}, ${8.00} and ${8} 都是相同?<BR><STRONG>布尔?/STRONG>Qtrue和falseQ不使用引号<BR><STRONG>Sequences(序列)</STRONG>Q由逗号分隔的变量列表,由方括号限定Q类似java中的一l数l:</P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#list </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>["winter", "spring", "summer", "autumn"] as x</FONT></SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${x}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV> <P>输出l果Q?BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>winter<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>spring<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>summer<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>autumn<BR><BR>例二Q[2 + 2, [1, 2, 3, 4], "whatnot"]<BR>例三Q?..5Q等同于[2, 3, 4, 5]Q?..2Q等同于[5,4,3,2]。注意方括号是不需要的?BR><BR><STRONG>Hashes(散列)</STRONG>Q由逗号分隔的键-值列表,由大括号限定Q键和g间用冒号分隔Q{"name":"green mouse", "price":150}Q键和值都是表辑ּQ但是键必须是字W串?/P> <P><STRONG>获取变量</STRONG>Q?{variable}Q变量名只能是字母、数字、下划线?、@?的组合,且不能以数字开头。下列表辑ּ是等LQ?BR>book.author.name<BR>book["author"].name<BR>book.author.["name"]<BR>book["author"]["name"]<BR><BR>获取Sequence(序列)片断Q用[startindex..endindex]Q例如:seq中存储了"a", "b", "c", "d","e"Q那么seq[1..2]包含了b和c两个倹{?BR><BR>可以使用.variablename语法讉KFreeMarker内置变量?/P> <P><STRONG>字符串操?/STRONG><BR>{"Hello ${user}!"} <==> ${"Hello " + user + "!"}<BR>${"${user}${user}${user}${user}"} <==> ${user + user + user + user}</P> <P>${…}只能在文本中使用Q下面是错误的代码:<BR><#if ${isBig}>Wow!</#if> <BR><#if "${isBig}">Wow!</#if>  //此处的代码也是错误的Q因为if指o需要的是booleanQ实际的却是个字W串</P> <P>子字W串的操作,假设user的gؓ"Big Joe"Q?BR>${user[0]}${user[4]}  <==>  BJ<BR>${user[1..4]}  <==> ig J </P> <P><STRONG>Sequences(序列)操作</STRONG></P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#list </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>["Joe", "Fred"] + ["Julia", "Kate"] as user</FONT></SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>- ${user}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV> <P>l果Q?BR>- Joe<BR>- Fred<BR>- Julia<BR>- Kate</P> <P><STRONG>Hashes(散列)操作</STRONG></P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><STRONG><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></STRONG><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>ages</FONT> </SPAN><SPAN style="COLOR: #0000ff">= <FONT color=#000000>{"Joe":23, </FONT></SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>"Fred":25} + {"Joe":30, "Julia":18}</FONT></SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>- Joe is ${ages.Joe}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>- Fred is ${ages.Fred}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>- Julia is ${ages.Julia}  </SPAN></DIV></DIV> <P>l果Q?BR>- Joe is 30<BR>- Fred is 25<BR>- Julia is 18  </P> <P><STRONG>术q算</STRONG></P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><STRONG><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></STRONG><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>x的D定ؓ5</FONT> --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${x * x - 100}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${x / 2}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${12 % 10}</SPAN></DIV></DIV> <P>l果Q?BR>-75<BR>2.5<BR>2 <BR><BR>注意Q?操作W两边必L数字Q?+"Ӟ如果一Ҏ数字Q一Ҏ字符Ԍ׃自动数字{换ؓ字符丌Ӏ?BR><BR>使用内徏的指令int<STRONG>获得整数部分</STRONG>Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV>${(x/2)?int}<BR>${1.1?int}<BR>${1.999?int}<BR>${-1.1?int}<BR>${-1.999?int}</DIV></DIV> <P>l果Q?BR>2<BR>1<BR>1<BR>-1<BR>-1</P> <P><STRONG>比较操作W?/STRONG>Q?lt;#if expression>...</#if><BR>1.)使用=Q或==Q完全相{)试两个值是否相{,使用!= 试两个值是否不相等<BR>2.)=?=两边必须是相同类型的|否则会生错误,例如<#if 1 = "1">会引起错?BR>3.)Freemarker是精比较,所?x"?x  "?X"是不相等?BR>4.)Ҏ字和日期可以使用<?lt;=?gt;?gt;=Q但不能用于字符?BR>5.)׃Freemarker会将>解释成FTL标记的结束字W,所以对?gt;?gt;=可以使用括号来避免这U情况,例如<#if (x > y)>Q另一U替代的Ҏ是,使用lt、lte、gt和gte来替?lt;?lt;=?gt;?gt;=</P> <P><STRONG>逻辑操作W?/STRONG>Q?amp;&(and)、||(or)?(not)Q只能用于布|否则会生错?BR><#if x < 12 && color = "green"><BR>  We have less than 12 things, and they are green.<BR></#if><BR><#if !hot> <#-- here hot must be a boolean --><BR>  It's not hot.<BR></#if>  </P> <P><STRONG>内置函数</STRONG>Q用法类D问hash(散列)的子变量Q只是??"替代"."Q例如:user?upper_case<BR>下面列出常用的一些函敎ͼ<BR><U>对于字符?/U><BR>htmlQ对字符串进行HTML~码<BR>cap_firstQ字符串第一个字母大?BR>lower_caseQ将字符串{换成写<BR>trimQ去掉字W串前后的空白字W?BR><U>对于Sequences(序列)<BR></U>sizeQ获得序列中元素的数?BR><U>对于数字<BR></U>intQ取得数字的整数部分Q如-1.9?int的结果是-1Q?BR><BR>例一Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>test的gؓTom & Jerry</FONT> --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${test?html}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${test?upper_case?html}</SPAN></DIV></DIV> <P>l果Q?BR>Tom &amp; Jerry<BR>TOM &amp; JERRY <BR><BR>例二Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>seasons的gؓ"winter", "spring", "summer", "autumn"</FONT> --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"> <BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${seasons?size}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${seasons[1]?cap_first} </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>left side can by any expression</FONT> --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${"horse"?cap_first}  </SPAN></DIV></DIV> <P>l果Q?BR>4<BR>Spring<BR>Horse  </P> <P><STRONG>Ҏ的调?/STRONG><BR>${repeat("What", 3)} <BR>${repeat(repeat("x", 2), 3) + repeat("What", 4)?upper_case} <BR>l果Q?BR>WhatWhatWhat<BR>xxxxxxWHATWHATWHATWHAT </P> <P><STRONG>操作W优先顺?/STRONG><BR>后缀            [subvarName] [subStringRange] . (methodParams)<BR>一?nbsp;           +expr?expr?<BR>内徏            ?<BR>乘法            *?/ ?<BR>加法            +?<BR>关系            <?gt;?lt;=?gt;=Qlt、lte、gt、gteQ?BR>相等            =?=<BR>逻辑            &&<BR>逻辑            ||<BR>数字范围      ..</P> <P>?) <STRONG>Interpolation</STRONG>Q由${...}?{...}两种cdQ输|可以定义输出的格?BR>例一Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#setting </SPAN><SPAN style="COLOR: #ff0000">number_format</SPAN><SPAN style="COLOR: #0000ff">="currency"</SPAN><SPAN style="COLOR: #0000ff">/></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">answer</SPAN><SPAN style="COLOR: #0000ff">=42/><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>${answer}<BR></FONT><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><FONT color=#000000>${answer?string}</FONT>  <FONT color=#000000><#-- the same as ${answer} --</FONT></SPAN><SPAN style="COLOR: #0000ff"><FONT color=#000000>></FONT></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${answer?string.number}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${answer?string.currency}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${answer?string.percent} </SPAN></DIV></DIV> <P>l果Q?BR>$42.00<BR>$42.00<BR>42<BR>$42.00<BR>4,200%</P> <P>例二Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">${lastUpdated?string("yyyy-MM-dd HH:mm:ss zzzz")}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${lastUpdated?string("EEE, MMM d, ''yy")}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>${lastUpdated?string("EEEE, MMMM dd, yyyy, hh:mm:ss a '('zzz')'")}  </SPAN></DIV></DIV> <P>l果Q?BR>2003-04-08 21:24:44 Pacific Daylight Time<BR>Tue, Apr 8, '03<BR>Tuesday, April 08, 2003, 09:24:44 PM (PDT)</P> <P>例三Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#assign </SPAN><SPAN style="COLOR: #ff0000">foo</SPAN><SPAN style="COLOR: #0000ff">=true/><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>${foo?string("yes", "no")}</FONT></SPAN></DIV></DIV> <P>l果Q?BR>yes</P> <P>例四Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#000000>x is 2.582 and y is 4</FONT> --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>#{x; M2}   </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#--<FONT color=#0000ff> </FONT></SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>2.58</FONT> --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>#{y; M2}   </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>4 </FONT>   --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>#{x; m1}   </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>2.6</FONT> --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>#{y; m1}   </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>4.0</FONT> --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>#{x; m1M2} </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>2.58</FONT> --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>#{y; m1M2} </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#-- </SPAN><SPAN style="COLOR: #ff0000"><FONT color=#0000ff>4.0</FONT>  --</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">  </SPAN></DIV></DIV> <P>说明QmXQ小数部分最X位;MXQ小数部分最大X位?/P> <P>?) <STRONG>注释</STRONG>Q?lt;#--?-> </P> <P>下面是一个常用的模板例子Q?/P> <DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid"> <DIV><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">p</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">We have these animals:<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">table </SPAN><SPAN style="COLOR: #ff0000">border</SPAN><SPAN style="COLOR: #0000ff">=1><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #ff0000"><tr</SPAN><SPAN style="COLOR: #0000ff">><</SPAN><SPAN style="COLOR: #800000">th</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Name</SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">th</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">Price<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#list </SPAN><SPAN style="COLOR: #ff0000">animals as being</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">tr</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">td</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>      </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#if </SPAN><SPAN style="COLOR: #ff0000">being.size </SPAN><SPAN style="COLOR: #0000ff">= "large"</SPAN><SPAN style="COLOR: #0000ff">><</SPAN><SPAN style="COLOR: #800000">b</SPAN><SPAN style="COLOR: #0000ff">></</SPAN><SPAN style="COLOR: #800000">#if</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>      ${being.name}<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>      </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#if </SPAN><SPAN style="COLOR: #ff0000">being.size</SPAN><SPAN style="COLOR: #0000ff">="large"</SPAN><SPAN style="COLOR: #0000ff">></</SPAN><SPAN style="COLOR: #800000">b</SPAN><SPAN style="COLOR: #0000ff">></</SPAN><SPAN style="COLOR: #800000">#if</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">td</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000">${being.price} Euros<BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">#list</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff"></</SPAN><SPAN style="COLOR: #800000">table</SPAN><SPAN style="COLOR: #0000ff">></SPAN><SPAN style="COLOR: #000000"> <BR><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff"><</SPAN><SPAN style="COLOR: #800000">#include </SPAN><SPAN style="COLOR: #ff0000">"/copyright_footer.html"</SPAN><SPAN style="COLOR: #0000ff">></SPAN></DIV></DIV> <P><STRONG>注意?/STRONG>Q?BR>1.) FreeMarker是区分大写的;<BR>2.) FTL标记不能位于另一个FTL标记内部Q例如:<#if <#include 'foo'>='bar'>...</if>Q?BR>3.) ${…}只能在文本中使用Q?BR>4.) 多余的空白字W会在模板输出时去除Q?BR>5.) 如果使用的指令不存在Q会产生一个错误消息?/P> <P><BR>参考:    <A blog - FreeMarker设计指南</A><BR>              <A >FreeMarker  in sourceforge.net</A></P><img src ="http://www.aygfsteel.com/pepsixp/aggbug/1685.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/pepsixp/" target="_blank">阿姆斯壮</a> 2005-03-11 11:00 <a href="http://www.aygfsteel.com/pepsixp/archive/2005/03/11/1685.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>J2EE中的分页(译)http://www.aygfsteel.com/pepsixp/archive/2005/02/22/1429.html阿姆斯壮阿姆斯壮Tue, 22 Feb 2005 14:33:00 GMThttp://www.aygfsteel.com/pepsixp/archive/2005/02/22/1429.htmlhttp://www.aygfsteel.com/pepsixp/comments/1429.htmlhttp://www.aygfsteel.com/pepsixp/archive/2005/02/22/1429.html#Feedback3http://www.aygfsteel.com/pepsixp/comments/commentRss/1429.htmlhttp://www.aygfsteel.com/pepsixp/services/trackbacks/1429.html阅读全文

阿姆斯壮 2005-02-22 22:33 发表评论
]]>
Tom猫Q让我看清你的五脏六腑(三) http://www.aygfsteel.com/pepsixp/archive/2005/02/18/1305.html阿姆斯壮阿姆斯壮Fri, 18 Feb 2005 14:41:00 GMThttp://www.aygfsteel.com/pepsixp/archive/2005/02/18/1305.htmlhttp://www.aygfsteel.com/pepsixp/comments/1305.htmlhttp://www.aygfsteel.com/pepsixp/archive/2005/02/18/1305.html#Feedback0http://www.aygfsteel.com/pepsixp/comments/commentRss/1305.htmlhttp://www.aygfsteel.com/pepsixp/services/trackbacks/1305.htmlServletqo?/STRONG>
在Java Servlet2.3中定义,能够对Servlet容器的请求和响应对象q行查和修改。所有的qo器类都必d现javax.servlet.Filter接口Q其?STRONG>有三个需要实现的Ҏ
Q?BR>init(FilterConfig)Q一个初始化ҎQServlet容器创徏qo器类后将调用q个ҎQ在此方法中可以dweb.xml文g中的Servletqo器的初始化参数?BR>doFilter(ServletRequest,ServletResponse,FilterChain)Q实际的qo操作QFilterChain参数用于讉K后面的过滤器?BR>destroy()Q用来释放某些Servletqo器占用的资源?/P>

下面是一个解决中文ؕ码问题很有用的一个过滤器Q?/P>

public class SetCharacterEncodingFilter implements Filter {
    
    
public void destroy() {}
  
    
public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain)
       throws IOException, ServletException 
{

    request.setCharacterEncoding(
"GB2312");
    chain.doFilter(request, response);
    }


    
public void init(FilterConfig filterConfig) throws ServletException {}
}

发布Servletqo?/STRONG>Q在web.xml在文件中加入<filter>元素?lt;filter-mapping>元素

下面的例子中Servletqo器会qo所有的URLQ?/P>

<filter> 
<filter-name>Set Character Encoding</filter-name> 
<filter-class>SetCharacterEncodingFilter</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern> 
</filter-mapping>

串连Servletqo?/STRONG>
多个Servletqo器可以协同工作,Servlet容器根据它们在web.xml中定义的先后序Q依ơ调用它们的doFilter()Ҏ?BR>工作程如下Q?BR> Code1; // 表示调用chain.doFilter()前面的代?BR> chain.doFilter();  // 表示调用下一个过滤器的doFilter()Ҏ
 Code2; // 表示调用chain.doFilter()后面的代?/P>

自定义JSP标签?BR>此技术在JSP 1.1版本中才出现Q用来重用某些复杂的逻辑q算和事务,或定义JSP王爷的输出内容和格式。制作一个完整的自定义标{序,包含3个步骤:

1. 创徏标签的处理类
此类必须扩展javax.servlet.jsp.TagSupportcL者javax.servlet.jsp.BodyTagSupportcR?BR>以TagSupportcMؓ例,先了解一下这个类的主要方法:
doStartTag()QJSP容器遇到自定义标{起始标志时调用该ҎQ?BR>doEndTag()QJSP容器遇到自定义标{l束标志时调用该ҎQ?BR>setValue(String k,Object o)Q在标签处理cM讄key/value;
getValue(String k)Q在标签处理cMҎkeyq回匚w的value;
removeValue(String k)Q在标签处理cM删除key/value;
setPageContext(PageContext pc)Q设|PageContext对象Q该Ҏ在调用doStartTag()和doStartTag()前调用;
setParent(Tag t)Q设|嵌套当前标{上层标签的处理类Q该Ҏ在调用doStartTag()和doStartTag()前调用;
getParent()Q返回嵌套当前标{上层标签的处理类?BR>
首先调用setPageContext(PageContext pc)和setParent(Tag t)Q设|TagSupportcȝ两个重要属性倹{?BR>
如果遇到起始标志Q调用doStartTag()Q此Ҏq回一个整数|它有两个可选|Tag.SKIP_BODY(标签之间的内容被忽略)和Tag.EVAL_BODY_INCLUDE(标签之间的内Ҏ常执??BR>例如Q?lt;prefix:mytag>test</prefix:mytag>Q如果遇上Tag.SKIP_BODYQtest字符串不会显C在面上;如果遇上Tag.EVAL_BODY_INCLUDEQtest字符串将会显C在面上?BR>
如果遇到l束标志Q调用doEndTag()Q此Ҏ也返回一个整数|它有两个可选|Tag.SKIP_PAGE(表示立刻停止执行JSP面Q网上未处理的静态内容和JSPE序均别忽略QQ何已有的输出内容立刻q回到客LQ?和Tag.EVAL_PAGE(表示按正常流El执行JSP面)?BR>
如果自定义标{֌含自定义的属性,例如Q?lt;prefix:mytag attribute1="value1">Q那么处理类中应该将q个属性做为成员变量,q提供一lget和setҎQ?BR>private int attribute1;
public void setAttribute1(int value){
 this.attriubte1 = value;
}
public int getAttribute1(){
 return attribute1;
}

下面是一个用来验证用L陆的标签处理cM子:

public class ValidateLoginTag extends TagSupport{
    
private String name;
    
private String password;
    
private Log log = LogFactory.getLog(ValidateLoginTag.class);

    
public int doEndTag() throws JspException{

       
if(name.equals("pepsixp"&& password.equals("888888")){
             
return(EVAL_PAGE);
          }

        
return (SKIP_PAGE);
    }


    
public String getName() {
        
return name;
    }


    
public void setName(String name) {
        
this.name = name;
    }


    
public String getPassword() {
        
return password;
    }


    
public void setPassword(String password) {
        
this.password = password;
    }

}

2.创徏TLDQTag Library Descriptor(标签库描q文?
TLD文g中元素可以分Zc:<tablib>?lt;tag>?lt;attribute>
<tablib>Q设定标{ֺ的相关信息,包含的子元素有tlibversion、jspversion、shortname、uri、info、tag?BR><tag>Q用来定义一个标{,包含的子元素有name、tagcalss、bodycontent、info、attribute?BR>bodycontent的说明:有三个可选值empty、JSP、tagdependentQempty表示标签中没有bodyQJSP表示body中可以加入JSPE序代码Qtagdependent表示body的内Ҏ标签q行处理?BR><attribute>Q用来定义标{属性,包含的子元素有name、required、rtexprvalue?BR>rtexprvalue的说明:表示是否可以使用<%=...%>cd的表辑ּQ?BR>例如Q?lt;prefix:mytaglib attribute1="<%=name%>">
下面是一个简单的TLD文gQ?/P>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">

<taglib>
    
<tlibversion>1.2</tlibversion>
    
<jspversion>1.1</jspversion>
    
<shortname>MY Tag Library</shortname>
    
<uri>http://www.aygfsteel.com/pepsixp/</uri>
    
<info></info>
    
<tag>
        
<name>ifLogin</name>
        
<tagclass>com.akazam.struts.taglib.ValidateLoginTag</tagclass>
        
<bodycontent>empty</bodycontent>
        
<info></info>
        
<attribute>
            
<name>name</name>
            
<required>true</required>
            
<rtexprvalue>true</rtexprvalue>
        
</attribute>
        
<attribute>
            
<name>password</name>
            
<required>true</required>
            
<rtexprvalue>true</rtexprvalue>
        
</attribute>
    
</tag>
</taglib>

实际中的使用Q?BR><%@ taglib uri="/tags/test" prefix="test" %>
<test:ifLogin name="pepsixp" password="888888"/>

3.在web应用中用标{?/STRONG>
先要在web.xml文g加入声明引用标签所在的标签Q?BR>

<taglib>
        
<taglib-uri>/tags/test</taglib-uri>
        
<taglib-location>/WEB-INF/test.tld</taglib-location>
</taglib>


参考:《Tomcat与JavaWeb开发技术详解?/FONT>



阿姆斯壮 2005-02-18 22:41 发表评论
]]>
Tom猫Q让我看清你的五脏六腑(二)http://www.aygfsteel.com/pepsixp/archive/2005/02/16/1261.html阿姆斯壮阿姆斯壮Wed, 16 Feb 2005 15:29:00 GMThttp://www.aygfsteel.com/pepsixp/archive/2005/02/16/1261.htmlhttp://www.aygfsteel.com/pepsixp/comments/1261.htmlhttp://www.aygfsteel.com/pepsixp/archive/2005/02/16/1261.html#Feedback0http://www.aygfsteel.com/pepsixp/comments/commentRss/1261.htmlhttp://www.aygfsteel.com/pepsixp/services/trackbacks/1261.html

安全?/STRONG>
q是Tomcat服务器用来保护Web应用资源的一U机制。一个用户可以拥有一个或多个角色Q每个角色限定了可访问的Web资源Q这样就用户和Web资源对应h了。在org.apache.catalina.Realm接口中声名了用户名、口令和角色相管理的ҎQTomcat5提供?个实现这一接口的类Q分别ؓQMemoryRealm(XML文gd)、JDBCRealm(JDBC驱动E序d)、DataSourceRealm(JNDI数据源读?、JNDIRealm(JNDI providerdLDAP的目录服务器信息)?/FONT>

Web资源的设|?BR>需要在web.xml文g中加?lt;security-constraint>?lt;login-config>?lt;security-role>元素?BR>例如在Tomcat的admin应用中的配置Q?/FONT>

<security-constraint>
    <display-name>Tomcat Server Configuration Security Constraint</display-name>
    <web-resource-collection>
    <web-resource>Protected Area</web-resource>
        <url-pattern>*.htm</url-pattern>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.do</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>

上面的代码表明:只有admin角色才能讉Kadmin应用中的*.jsp?.do?.html资源?BR>另一个例子是jsp-examples应用Q?BR>

<sercurity-constraint>
    <display-name>Tomcat Server Configuration Security Constraint</display-name>
    <web-resource-collection>
        <web-resource>Protected Area</web-resource>
        <url-pattern>/security/protected/*</url-pattern>
        <http-method>DELETE</http-method>
     
<http-method>GET</http-method>
     
<http-method>POST</http-method>
     
<http-method>PUT</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>tomcat</role-name>
     
<role-name>role1</role-name>
    
</auth-constraint>
</security-constraint>

上面的代码表明:只要tomcat和role1角色才可以以DELETE、GET、POST和GET方式讉Kjsp-exzmples应用URL?security/protected/下的资源?BR>在web.xml中加?lt;login-config>元素Q系l会以对话框的方式进行登?BR>

<login-config>
    <auth-method>FORM</auth-method>
 
<realm-name>Tomcat Configuration Form-Baseed Authenticaton Area</realm-name>
 
<from-login-config>
       
<from-login-page>/login/login.jsp</from-login-page>
    
<from-error-page>/error.jsp</from-error-page>
 
<from-login-config>
</login-config>

<auth-method>有三个可选项QBASIC、DIGEST、FORM?BR>BASICQ基本验证:讉K受保护资源时Q会弹出一对话框。要求输入用户名和密码,如果q箋3ơ失败后Q会昄一个错误页面。这个方法的~点是用户名和密码的数据传输采用的是Base64~码(可读文本)Q是非常不安全的?BR>DIGESTQ摘要验证:数据采用MD5对用户名和密码进行加密,然后再传输,昄q种Ҏ很安全?BR>FORMQ表单验证:可以使用自定义的登陆面Q但用户名对应的文本框名U必Lj_username,密码为j_passwordQ且表单actiongؓj_security_check?BR>在web.xml中加?lt;security-role>元素Q指明这个Web应用应用的所有角色的名字

<security-role>
    <description>The role that is required to lon in to the Administration Application.</description>
 
<role-name>admin</role-name>
 
<role-name>friend</role-name>
</security-role>

你可以调用HttpRequeset接口的getRemoteUser()Ҏq回当前用户的名字:<%=request.getRemoteUser()%>


内存?/STRONG>Q由org.apache.catalina.realm.MemoryRelamcd?BR>猫启动Ӟ自动d<%CATALINA_HOME%>/conf/tomcat-users.xml文gQ要在Web应用中用,可以在对应的<Context>元素内加入如下内容:<Realm className="org.apache.catalina.realm.MemoryRelam"/>

JDBC?/STRONG>Q通过JDBC驱动从数据库中直接读取验证信息,通过验证后,信息会存储在session中?BR>在mysql中新Z张表Q?/P>

create table users{user_name varchar(15not null primary key,user_pass varchar(15not null };
create table usr_roles{usr_name varchar(15not null,role_name varchar(15not null,
  primary key(user_name,role_name)};

然后在server.xml中加入:

<Realm className="org.apache.catalina.realm.JDBCRealm" driverName="com.mysql.jdbc.Driver" 
             debug
="0" connectionURL="jdbc:mysql://localhost/tomcatusers" connectionName="roor" 
             connectonPassword
="" userTable="users" userNameCol="user_name" 
             userCredCol
="user_pass" userRoleTable="user_roles" roleNameCol="role_name">

DataSource?/STRONG>Q和JDBC域很cMQ只不过讉K数据库的方式不同Q这个是使用JNDI DataSource来访问数据库的?BR>先在web.xml中加入安全约束,在和JDBC域一hZ张表Q然后在server.xml文g?lt;GlobalNamingResources>元素下添加如下内容:

<Resource name="jdbc/tomcatusers" auth="Container" type="javx.sql.DataSource"/>
<ResourceParams name="jdbc/tomcatusers">
    <parameter>
    
<name>factory</name>
    
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
 
</parameter>
 
<parameter>
     
<name>maxActiove</name>
    
<value>100</value>
 
</parameter>
 
<parameter>
    
<name>maxIdle</name>
    
<value>30</value>
 
</parameter>
 
<parameter>
     
<name>maxWait</name>
    
<value>10000</value>
 
</parameter>
 
<parameter>
     
<name>username</name>
     
<value>root</value>
 
</parameter>
 
<parameter>
     
<name>password</name>
    
<value></value>
 
</parameter>
 
<parameter>
     
<name>driverClassName</name>
    
<value>com.mysql.jdbc.Driver</value>
 
</parameter>
 
<parameter>
     
<name>url</name>
    
<value>jdbc:mysql://localhost/tomcatusers?autoReconnect=true</value>
  
</parameter>
</ResourceParams>

注意QTomcat的JNDI资源必须配置?lt;GlobalNamingResources>元素下,服务器才能找刎ͼ否则会出现NameNotFoundExceptionQ低于Tomcat5.0.12的版本,即正确配置了DataSourceRealmQ也会出现找不到JNDI DataSource的异常,q个猫的一个bugQ在web.xml中是不需要配|?lt;resource-ref>元素的,因ؓWeb应用q不会访问这个DataSource?BR>当然server.xmlq需要添加和JDBC域几乎相同的代码Q?/P>

<Realm className="org.apache.catalina.realm.DataSourceRealm" 
             driverName
="com.mysql.jdbc.Driver" debug="0" 
             connectionURL
="jdbc:mysql://localhost/tomcatusers" connectionName="roor" 
             connectonPassword
="" userTable="users" userNameCol="user_name" 
             userCredCol
="user_pass" userRoleTable="user_roles" roleNameCol="role_name">

Tomcat阀
由org.apache.Catalina.Value接口定义Q能够对Catalina容器接收的HTTP Requestq行预处理,是小猫特有的功能Q可以加入到3U容器中(Engine、Host、Context)?BR>
客户讉K日志阀(Access Log Value)Q?能够可以的Request信息写入到日志中。可以记录页面访问的ơ数、用户Sessionzd和用户验证信息等?BR>例如Q?lt;Value className="org.apache.catalina.AccessLogValue" directory="logs" prifix="localhost_access_log" suffix=".txt" pattern="%h%l%u%t%s%r%s%b" resolveHost="true">
上面的pattern值可以用commonQ一个默认的倹{?BR>pattern属性规定日志的格式和内容:%aQ远EIP地址Q?AQ本地IP地址Q?bQ发送的字节敎ͼ不包括HTTP HeaderQ?hQ远E主机名Q?HQ客戯求所用的协议Q?lQ?-";%mQ请求的ҎQ?pQ接受请求的本地服务器断开Q?qQ查询字W串Q?rQ用戯求的W一行内容;%sQ响应HTTP Request的状态码Q?SQ用户Session IDQ?tQ时_%uQ验证的用户名;%UQ请求URL路径Q?vQ本地服务器名?BR>
q程地址qo?/STRONG>(Remote Address Filter)Q根据IP地址军_是否接受客户的请求?BR>例如Q?lt;Value className="org.apache.catalina.RemoteAddrValue" allow="127.0.0.1" deny="127.111.*"/>

q程Lqo?/STRONG>(Remot Host Filter)Q根据主机名军_是否接受h?BR><Value className="org.apache.catalina.RemoteHostValue" allow="localhost" deny="monster*"/>

客户h记录?/STRONG>(Request Dumper)Q把客户h的详l信息记录在日志文g中,q里的日志文件是?lt;Logger>元素?BR>假定在server.xml中localhost?lt;Host>元素下已l配|了<Logger>元素Q?BR>

<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="localhos_log." 
              suffix
=".txt" timestamp="true"/>

然后再添?lt;Value>元素Q?/P>

<Value className="org.apache.catalina.RequestDumperValue"/>


参考:《Tomcat与JavaWeb开发技术详解?/FONT>



阿姆斯壮 2005-02-16 23:29 发表评论
]]>
վ֩ģ壺 Ͽ| | | | ն| ϰ| | Ѱ| ɽ| ۳| | | | | | ԭ| ¹Ȫ| ɽ| | | | | | | ؿ˹| ֣| | ½| | ߺ| ޻| Ѿ| | ¡| Ϫ| | ӽ| | ǹ| ¬| |