struts結合urlwriter的使用

 struts結合  urlwriter的好處

        1.滿足搜索引擎的要求。

        2.隱藏技術實現,提高網站的移植性。

實現步驟

       1 將struts所用用到的jar包 和urlwriter的jar包導入到WEB-INF的lib目錄下

       2 在WEB-INF下的web.xml下  加入如下配置                 

  <filter>
   <filter-name>strutFilter</filter-name>
   <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
 <filter-mapping>
   <filter-name>strutFilter</filter-name>
   <url-pattern>/*</url-pattern>
   <dispatcher>REQUEST</dispatcher>
      <dispatcher>FORWARD</dispatcher>
 </filter-mapping>

 <!--<urlrewrite> 重寫 -->
 <filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

   3 WEB-INF 下新建一個urlwriter.xml配置  添加內容如下

               <urlrewrite>

                      <rule>
                       <note>test</note>
                       <from>^/test/([a-z]+).html$ </from>
                       <to>/test/$1.action</to>
                      </rule>

             </urlrewrite>

  #rule節點主要是定義請求的地址規則  to是實際的請求 from是轉換後的請求 比如

http://localhost:8080/Weather/test/one.html 它調用的action請求時 http://localhost:8080/Weather/test/one.action

  4 在WEBROOT下新建兩個xml  如 one.jsp 和two.jsp

  5 啓動tomcat 測試結果 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章