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

  • 相关阅读:
    1292
    explicit_defaults_for_timestamp
    比较好的平台工具
    git回退到指定版本的代码
    解决catalina.out文件过大的方法
    json字符串转化成对象列表数据
    Java LIST做批量分组切割
    Activiti数据库表结构
    MySQL修改数据库时区
    集合工具类的使用
  • 原文地址:https://www.cnblogs.com/jiangzhengbin/p/5669077.html
Copyright © 2011-2022 走看看