论坛首页 Java版 Webwork

使用UrlRewriteFilter转换Tapestry的蹩脚的URL

浏览 7597 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2005-03-08
第一:在web.xml添加
如下代码:
第一:web.xml里添加

[code:1] <filter>
  <filter-name>rewriteFilter</filter-name>
  <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>rewriteFilter</filter-name>
  <url-pattern>/*.html</url-pattern>
</filter-mapping>[/code:1]
第二
[code:1]

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 1.0//EN"
    "http://tuckey.org/res/dtd/urlrewrite1.dtd">
<!-- See the manual for configuring: http://tuckey.org/urlrewrite/manual/   -->
<!-- This filter is disabled by default in metadata/web/filter-mappings.xml -->
<urlrewrite>
    <rule>
        <from>/view/([0-9]+).html</from>
        <to type="forward">/app?service=external/ViewContent&sp=$1</to>
    </rule>
    <rule>
        <from>/archive/([0-9]+)/([0-9]+).html</from>
        <to type="forward">/app?service=external/Archive&sp=$1&sp=$2</to>
    </rule>
    <rule>
        <from>/category/([0-9]+).html</from>
        <to type="forward">/app?service=external/CategoryPage&sp=$1</to>
    </rule>
    <rule>
        <from>/(.*).html</from>
        <to type="forward">/app?service=page/$1</to>
    </rule>
</urlrewrite>[/code:1]
保存为urlrewrite.xml,在web-inf目录下



demo site:http://blog.tomxp.com
   
最后更新时间:2005-03-08
哈, Tapestry 的本意是让开发人员不需要关注URL啊, 如果不是特殊的需要,也不一定非要Friendly URLs 啊
   
0 请登录后投票
最后更新时间:2005-03-08
呵呵,必定有时候为了讨好搜索引擎,还是要Friendly URL的好呀。
   
0 请登录后投票
最后更新时间:2005-03-12
不错.能把客户端原TAPESTRY转换成HTML,但是,
网页中*.html链接如何构造出来的?
   
0 请登录后投票
最后更新时间:2005-03-15
[code:1]<a jwcid="@Any" href="ognl:'/'+page.visit.blog.host+'/view/'+content.contentId+'.html'">
<span jwcid="@Insert" value="ognl:content.title"/>
</a>[/code:1]
   
0 请登录后投票
最后更新时间:2005-03-16
赞:)

我觉得Ewave的想法很好。呵呵,套用我们帮主常说的话:“21世纪最重要的是人才。”我个人觉得衡量人才的最好标准就是是否有创新精神。。。我欣赏Tapestry并不是因为它实现表现层的方式,也不仅仅是因为Tapestry能够实现项目和技术积累。最重要的是Tapestry带来的思维革新。。。


不好意思,很久没有来这里晃悠。昨天在群里听朋友们说起UrlRewriteFilter,我一google就跑到其官网上了。呵
   
0 请登录后投票
最后更新时间:2005-11-10
urlrewrite有很多有用的功能,美化url,对搜索引擎友好都是很重要的功能。
在一些内容管理系统中,用户名为url的一部分也是一种对用户友好的方法,这些功能的开发可以带来很多易用性的改善。
其实看到一个blog或者某一个相册以你自己的用户名为目录,不要以为他们真的给你建了一个目录,只是一次url rewrite而已。
   
0 请登录后投票
最后更新时间:2005-11-13
发现这个urlrewriter是个好东西,但是,却让我乱了。

Tapestry 3.0 中url的定义和组成:
[code:1]Tapestry Service URLs and query parameters
All URLs generated by the framework consist of the the path to the servlet, and up to three query parameters.

service: the name of the service that will be used to processes the request.

context: contextual information needed by the service; typically the name of the page or component involved. Often there are several pieces of information, separated by slashes.

sp: additional parameters that can be made available to the component. This is used by a DirectLink component. If there is more than one service parameter, then there will be multiple sp parameters in the URL.[/code:1]

Service 种类有:
ACTION_SERVICE/ASSET_SERVICE/DIRECT_SERVICE/EXTERNAL_SERVICE/HOME_SERVICE/PAGE_SERVICE/RESET_SERVICE/RESTART_SERVICE 等.

从实例分析至少有下面几种常见的Tapestry3.0 url:

[code:1]1、PageLink/ExternalLink(EXTERNAL_SERVICE 和 PAGE_SERVICE)的连接
http://localhost:8080/test/app?service=page/PurOrder
http://localhost:8080/demo/app?service=external/ClassInfoEdit&sp=Sedit

2、DirectLink(ACTION_SERVICE 和 DIRECT_SERVICE)的连接
href="/workbench/app?service=direct/1/Fields/$Border.pageLink&sp=SLocalization"

3、form(ACTION_SERVICE 和 DIRECT_SERVICE)的连接
<form method="post" name="Form1" action="/workbench/app">
<input type="hidden" name="service" value="direct/1/Fields/$Form$0"/>
<input type="hidden" name="sp" value="S1"/>
<input type="hidden" name="Form1" value="inputDate,inputInt,inputDouble,inputBigDecimal,inputLong,inputString,inputEmail,$ImageSubmit,$LinkSubmit"/>[/code:1]

问题:
那么该如何将上面几种形式的guly url,rewrite成friendly url呢?
向各位请教了,因为我的正则表达式,一头昏,.....

如page的连接,去掉?service=page换成page:
[code:1]<outbound-rule>
<from>/app?service=page/(\?.*)$</from>
        <to>/app/page?$1</to>
</outbound-rule>

<rule>
<from>/app/page?(\?.*)$</from>
<to type="forward">/app?service=page/$1</to>
</rule>

<outbound-rule>
<from>/app?service=external/(\?.*)$</from>
        <to>/app/external?$1</to>
</outbound-rule>

<rule>
<from>/app/external?(\?.*)$</from>
<to type="forward">/app?service=external/$1</to>
</rule>[/code:1]

(ACTION_SERVICE 和 DIRECT_SERVICE)的连接好似改了也没有什么friendly的效果。
。。。。。。

。。。。。。有点乱。。。
   
0 请登录后投票
最后更新时间:2005-11-13
是不是我想错了,这个功能只能在自己写 a 写 href中使用呢?

如要象Ewaves说的那样,是在前台使用的自己定义的url的时候,才在后台使用转换的rule跟他相对应。
引用
<a jwcid="@Any" href="ognl:'/'+page.visit.blog.host+'/view/'+content.contentId+'.html'">
<span jwcid="@Insert" value="ognl:content.title"/>
</a>


引用
<rule>
        <from>/view/([0-9]+).html</from>
        <to type="forward">/app?service=external/ViewContent&sp=$1</to>
</rule>

换句话,后台想要使用rule作转换,前台就是自己定义的href,而不是将tapestry的东西转化?
象这个:
[code:1]from
/app?service=external/ClassInfoEdit&sp=Sedit
to
/app/external/ClassInfoEdit&sp=Sedit [/code:1]的转化意义也不是太大。
   
0 请登录后投票
最后更新时间:2005-11-13
另外,有没有人,研究过http://www.theserverside.com/tss上面的连接呢?
tss是一个tapestry3.0上运行的大型网站。
   
0 请登录后投票
论坛首页 Java版 Webwork

跳转论坛:
JavaEye推荐