Servlet中Request的getAttribute getParameter 區別


1.從更深的層次考慮,request.getParameter()方法傳遞的數據,會從Web客戶端傳到Web服務器端,代表HTTP請求數據。 request.getParameter()方法返回String類型的數據。
   request.setAttribute()和getAttribute()方法傳遞的數據只會存在於Web容器內部,在具有轉發關系的Web組 件之間共享。這兩個方法能夠設置Object類型的共享數據。
   request.getParameter()取得是通過容器的實現來取得通過類似post,get等方式傳入的數據。
   

   request.setAttribute()和getAttribute()只是在web容器內部流轉,僅僅是請求處理階段。
   getAttribute是返回對象,getParameter返回字符串
 

   總的來說:request.getAttribute()方法返回request范圍內存在的對象,而 request.getParameter()方法是獲取http提交過來的數據。

 

2.request is something that comes from the user, attributes come from the session

 

3.Use request.getParameter() when u are planning to fetch values from a html/jsp page, and use requets.getAttribute() when u want to fetch attribute values which are set using request.setAttribute() IN A SERVLET.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM