日期:2014-05-19  浏览次数:20742 次

弱弱的问下urlrewriter的问题
例如:

  <rule>
  <from>^/forum/thread/([0-9]+).html$</from>
  <to type="forward">/forum/list.action?id=$1</to>
  </rule>


这样,from处都没配置参数选项值, to处 id=$1 却声明接收参数,这如何解释?


实际上我想提问的是,假如有一个链接 

http://localhost:8080/test/test.do?method=edit&id=123


然后想要以 http://localhost:8080/test/test.html来表示上面的链接,能不能实现?如果能实现
那么 http://localhost:8080/test/test.html 怎么传递参数的呢

------解决方案--------------------
这个当然可以实现
假如这个是你的Action链接:http://localhost:8080/test/test.do?method=edit&id=123
然后想要以:http://localhost:8080/test/test.html来表示上面的链接
那么:urlrewriter配置如下
<rule>
<from>^/test/test.html$</from>:这里是你在浏览器输入的地址
<to type="forward">/test/test.do?method=edit&id=123</to>:这里是根据浏览器输入的地址后,转入到你的Action
</rule>

如果在:to 中 id=$1 ,那么证明在:from 中 一个括号

比如from中:<from>^/forum/(.*)/([0-9]+).html$</from>
to中:<to type="forward">/test/test.do?method=$1&id=$2</to>
那么你的浏览器地址:http://localhost:8080//forum/xxxxxxx/111111.html
那么to中的:$1 = xxxxxxx , $2 = 111111
实际访问Action为/test/test.do?method=xxxxxxx&id=111111