Restful风格的简单实现办法

如果实在着急上Restful的URL在项目里 , 可以使用turkey的urlrewrite.

先在web.xml中加入如下代码

<!-- URL ReWrite -->
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- URL ReWrite -->

然后再在WEB-INF目录中新建一个urlrewrite.xml , 内容类似如下

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd"> <!-- Configuration file for UrlRewriteFilter
http://tuckey.org/urlrewrite/ -->
<urlrewrite> <rule>
<note>XXX Restful</note>
<from>^/nihao$</from>
<to>/user/nihao.do</to>
</rule> </urlrewrite>
上一篇:在Linux和Windows系统上安装Nginx服务器的教程


下一篇:System.Runtime.InteropServices.COMException 检索COM类工厂中CLSID{xxxxxxxxx}的组件时失败解决方法