小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Spring MVC過濾器-HiddenHttpMethodFilter

 老鼠愛上美貓 2012-08-09
瀏覽器form表單只支持GET與POST請求,而DELETE、PUT等method并不支持,spring3.0添加了一個過濾器,可以將這些請求轉(zhuǎn) 換為標準的http方法,使得支持GET、POST、PUT與DELETE請求,該過濾器為HiddenHttpMethodFilter。

        HiddenHttpMethodFilter的父類是OncePerRequestFilter,它繼承了父類的doFilterInternal方 法,工作原理是將jsp頁面的form表單的method屬性值在doFilterInternal方法中轉(zhuǎn)化為標準的Http方法,即GET,、 POST、 HEAD、OPTIONS、PUT、DELETE、TRACE,然后到Controller中找到對應(yīng)的方法。例如,在使用注解時我們可能會在 Controller中用于@RequestMapping(value = "list", method = RequestMethod.PUT),所以如果你的表單中使用的是<form method="put">,那么這個表單會被提交到標了Method="PUT"的方法中。

        需要注意的是,由于doFilterInternal方法只對method為post的表單進行過濾,所以在頁面中必須如下設(shè)置:

  1. <form action="..." method="post">  
  2.         <input type="hidden" name="_method" value="put" />  
  3.         ......  
  4. </form>  

        而不是使用:

  1. <form action="..." method="put">  
  2.         ......  
  3. </form>  

        同時,HiddenHttpMethodFilter必須作用于dispatcher前,所以在web.xml中配置HiddenHttpMethodFilter時,需參照如下代碼:

  1.       <filter>    
  2.               <filter-name>HiddenHttpMethodFilter</filter-name>    
  3.               <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>    
  4.       </filter>    
  5.       <filter-mapping>    
  6.               <filter-name>HiddenHttpMethodFilter</filter-name>    
  7.               <servlet-name>spring</servlet-name>    
  8.       </filter-mapping>  
  9.       <servlet>  
  10. <servlet-name>spring</servlet-name>  
  11. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  12. <init-param>  
  13.     <param-name>contextConfigLocation</param-name>  
  14.     <param-value>classpath:dispatcher.xml</param-value>  
  15. </init-param>  
  16. lt;/servlet>  
  17.       <servlet-mapping>  
  18. <servlet-name>spring</servlet-name>  
  19. <url-pattern>*.html</url-pattern>  
  20. lt;/servlet-mapping>  

        同樣的,作為Filter,可以在web.xml中配置HiddenHttpMethodFilter的參數(shù),可配置的參數(shù)為methodParam,值必須為GET,、POST、 HEAD、OPTIONS、PUT、DELETE、TRACE中的一個。

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多