zoukankan      html  css  js  c++  java
  • getAttribute()与getParameter的区别

           当两个Web组件之间为转发关系时,转发源会将要共享 request范围内的数据先用setAttribute将数据放入到HttpServletRequest对象中,然后转发目标通过 getParametergetParameter()方法来获得请求参数,例如假定welcome.jsp和authenticate.jsp之间为链接关系,welcome.jsp中有以下代码:

    authenticate.jsp

    或者:


    请输入用户姓名:

    在authenticate.jsp中通过request.getParameter("username"); %>

    (3)getAttribute()方法来和转发源组件共享request,session范围内的数据。

    假定 authenticate.jsp和hello.jsp之间为转发关系。authenticate.jsp希望向hello.jsp传递当前的用户名字, 如何传递这一数据呢?先在authenticate.jsp中调用setAttribute()方法:

    <%
    String username=request.%>

    在hello.jsp中通过getAttribute("username"); %>
    Hello: <%=username %>

    从更深的层次考虑,request.getParameter()方法返回String类型的数据。

    request.setAttribute()和getParameter()取得是通过容器的实现来取得通过类似post,get等方式传入的数据。

    request.setAttribute()和getAttribute是返回对象,getAttribute()方法返回reques,sessiont范围内存在的对象,而request.getParameter()方法是获取http提交过来的数据。

  • 相关阅读:
    对象实例化过程分析
    对象实例化过程分析
    QuickHit游戏
    QuickHit游戏
    java继承向上转型和向下转型和动态绑定
    java继承向上转型和向下转型和动态绑定
    洛谷:P1095 守望者的逃离(贪心+dp)
    Manacher算法-最长回文子串
    numpy array()
    CNN 卷积神经网络结构
  • 原文地址:https://www.cnblogs.com/jiangzhengbin/p/5669077.html
Copyright © 2011-2022 走看看