Archive for 01月 30th, 2010

Resin中配置URL重写

Jan 30 2010 Published by Tony under Java

web项目中url rewright的功能是一个很常见得功能,实现的方式多种多http://ohacker.com/wp-admin/post-new.php样,最常见的莫过于在web服务器中设置,例如在Apache中设置。而如果你使用Java开发,那么还有个更多的方案供你选择如使用url rewrite filter ,而如果你是使用resin(版本需要>3.1)作为你的application server,那么你还可以使用resin自带的url 重写功能。

首先,你必须使用resin-web.xml代替常规的web.xml作为你的项目部署描述文件,其次,你需要在描述文件中指定一个url重写的配置文件。再在这个文件中配置。

resin-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://caucho.com/ns/resin"
         xmlns:resin="http://caucho.com/ns/resin/core">
 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <rewrite-dispatch>
     <import path='WEB-INF/rewrite.xml'/>
  </rewrite-dispatch>
</web-app>

rewrite.xml

<rewrite-dispatch xmlns="http://caucho.com/ns/resin"
	xmlns:resin="http://caucho.com/ns/resin/core">
	<redirect regexp="^/tst" target="https://ohacker.com/tst">
		<when secure="false" />
	</redirect>
</rewrite-dispatch>

No responses yet