Tapestry4新特性(五)-Friendly URLs ServletTapestryXMLApacheHTML
程序员文章站
2024-02-20 18:26:52
...
Tapestry4.0以前版本中的URL一直被人所诟病,当然现在已经有很多的解决方
案,4.0版本中已经对此做了改进,
因为现在的版本需要通过hivemind来配置,所以需要设置hivemind.xml中的一些属
性,具体配置如下:
<?xml version="1.0"?>
<module id="tapestry4" version="1.1.0">
<contribution configuration-id="tapestry.url.ServiceEncoders">
<page-service-encoder id="page" extension="html" service="page"/>
<direct-service-encoder id="direct" stateless-extension="direct"
stateful-extension="sdirect"/>
<asset-encoder id="asset" path="/assets/"/>
<extension-encoder id="extension" extension="svc" after="*"/>
</contribution>
</module>
同时web.xml中加入映射:
<servlet>
<servlet-name>tapestry4</servlet-name>
<servlet-class> org.apache.tapestry.ApplicationServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>tapestry4</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tapestry4</servlet-name>
<url-pattern>*.direct</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tapestry4</servlet-name>
<url-pattern>*.sdirect</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tapestry4</servlet-name>
<url-pattern>/assets/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tapestry4</servlet-name>
<url-pattern>*.svc</url-pattern>
</servlet-mapping>
如果希望首页的调用不是通过/app来映射,可以在web.xml中更改redirect:
<filter-name>redirect</filter-name>
<filter-class>org.apache.tapestry.RedirectFilter</filter-class>
<init-param>
<param-name>redirect-path</param-name>
<param-value>/Home.html</param-value>
</init-param>
</filter>
这样键入http://localhost:8080/tapestry4,系统导航到http://localhost:
8080/tapestry4/Home.html,
添加一个Page页面例如Test.page,在Home.html中加入<a href="#"
jwcid="@PageLink" page="Test">test</a>,
在生成的Home.html中生成的test的链接地址为:http://localhost:
8080/tapestry4/Test.html
案,4.0版本中已经对此做了改进,
因为现在的版本需要通过hivemind来配置,所以需要设置hivemind.xml中的一些属
性,具体配置如下:
<?xml version="1.0"?>
<module id="tapestry4" version="1.1.0">
<contribution configuration-id="tapestry.url.ServiceEncoders">
<page-service-encoder id="page" extension="html" service="page"/>
<direct-service-encoder id="direct" stateless-extension="direct"
stateful-extension="sdirect"/>
<asset-encoder id="asset" path="/assets/"/>
<extension-encoder id="extension" extension="svc" after="*"/>
</contribution>
</module>
同时web.xml中加入映射:
<servlet>
<servlet-name>tapestry4</servlet-name>
<servlet-class> org.apache.tapestry.ApplicationServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>tapestry4</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tapestry4</servlet-name>
<url-pattern>*.direct</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tapestry4</servlet-name>
<url-pattern>*.sdirect</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tapestry4</servlet-name>
<url-pattern>/assets/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tapestry4</servlet-name>
<url-pattern>*.svc</url-pattern>
</servlet-mapping>
如果希望首页的调用不是通过/app来映射,可以在web.xml中更改redirect:
<filter-name>redirect</filter-name>
<filter-class>org.apache.tapestry.RedirectFilter</filter-class>
<init-param>
<param-name>redirect-path</param-name>
<param-value>/Home.html</param-value>
</init-param>
</filter>
这样键入http://localhost:8080/tapestry4,系统导航到http://localhost:
8080/tapestry4/Home.html,
添加一个Page页面例如Test.page,在Home.html中加入<a href="#"
jwcid="@PageLink" page="Test">test</a>,
在生成的Home.html中生成的test的链接地址为:http://localhost:
8080/tapestry4/Test.html