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提交过来的数据。

  • 相关阅读:
    Python-单例模式
    Django 内置模板标签和过滤器
    Python Built-in Function 学习笔记
    Django 中间件
    Django Form
    Ajax
    Django中cookie和session
    Django中的QuerySet
    Django模型和ORM
    wordpress添加子主题
  • 原文地址:https://www.cnblogs.com/jiangzhengbin/p/5669077.html
Copyright © 2011-2022 走看看