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

  • 相关阅读:
    【转】织梦为栏目添加图片的方法
    写在php设计模式前
    memcache 开机启动
    php 列出当前目录
    print echo 的区别
    php 报错等级
    nginx 启动脚本
    centos 编译 安装php
    修改linux iptable规则
    linux yum 安装软件
  • 原文地址:https://www.cnblogs.com/jiangzhengbin/p/5669077.html
Copyright © 2011-2022 走看看