zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    [LeetCode]N-Queens
    [LeetCode]Anagrams
    [LeetCode]Permutations II
    [LeetCode]Permutations
    [STL]heap和priority_queue
    [STL]deque和stack、queue
    10、小易记单词--2017网易春招
    29、剑指offer--最小的K个数
    28、剑指offer--数组中出现次数超过一半的数字
    9、涂棋盘--2017网易春招
  • 原文地址:https://www.cnblogs.com/printN/p/6580798.html
Copyright © 2011-2022 走看看