getParameter和getAttribute的区别是什么?

楼主xxmm(晓箫)2001-07-22 21:18:05 在 Java / Web 开发 提问

问题点数:20、回复次数:5Top

src="/Include/Board.htm?Tags=null,getattribute,getparameter,参数,lang,getparametervalues,attribute,parameters,request,exist" frameborder="0" scrolling="no">

1 楼yelz(断弦)回复于 2001-07-22 21:55:46 得分 8

getParameter   返回上个页面提交得参数,getAttribute返回系统属性,不同jsp服务器可能不同。Top

2 楼xxmm(晓箫)回复于 2001-07-22 22:10:33 得分 0

系统属性指什么?能不能给一个例子?Top

3 楼muwenyi(咔咔)回复于 2002-02-10 13:17:46 得分 8

getParameter可以获得客户端传送给服务器端的参数值。  
   
  getAttribute可以得到由setAttribute设置的参数值,就相当于是使用getAttribute得到一个自己定义的参数,而不是从客户端得到的参数。我是这样理解的!Top

4 楼gzwrj(我无知,所以我有智慧.)回复于 2002-02-11 12:31:38 得分 2

getAttribute  
  public   java.lang.Object   getAttribute(java.lang.String   name)  
  Returns   the   value   of   the   named   attribute   as   an   Object,   or   null   if   no   attribute   of   the   given   name   exists.    
  Attributes   can   be   set   two   ways.   The   servlet   container   may   set   attributes   to   make   available   custom   information   about   a   request.   For   example,   for   requests   made   using   HTTPS,   the   attribute   javax.servlet.request.X509Certificate   can   be   used   to   retrieve   information   on   the   certificate   of   the   client.   Attributes   can   also   be   set   programatically   using   setAttribute(java.lang.String,   java.lang.Object).   This   allows   information   to   be   embedded   into   a   request   before   a   RequestDispatcher   call.    
   
  Attribute   names   should   follow   the   same   conventions   as   package   names.   This   specification   reserves   names   matching   java.*,   javax.*,   and   sun.*.  
   
  Parameters:  
  name   -   a   String   specifying   the   name   of   the   attribute  
  Returns:  
  an   Object   containing   the   value   of   the   attribute,   or   null   if   the   attribute   does   not   exist  
   
  //  
  getParameter  
  public   java.lang.String   getParameter(java.lang.String   name)  
  Returns   the   value   of   a   request   parameter   as   a   String,   or   null   if   the   parameter   does   not   exist.   Request   parameters   are   extra   information   sent   with   the   request.   For   HTTP   servlets,   parameters   are   contained   in   the   query   string   or   posted   form   data.    
  You   should   only   use   this   method   when   you   are   sure   the   parameter   has   only   one   value.   If   the   parameter   might   have   more   than   one   value,   use   getParameterValues(java.lang.String).    
   
  If   you   use   this   method   with   a   multivalued   parameter,   the   value   returned   is   equal   to   the   first   value   in   the   array   returned   by   getParameterValues.    
   
  If   the   parameter   data   was   sent   in   the   request   body,   such   as   occurs   with   an   HTTP   POST   request,   then   reading   the   body   directly   via   getInputStream()   or   getReader()   can   interfere   with   the   execution   of   this   method.  
   
  Parameters:  
  name   -   a   String   specifying   the   name   of   the   parameter  
  Returns:  
  a   String   representing   the   single   value   of   the   parameter  
  See   Also:    
  getParameterValues(java.lang.String)  
  Top

5 楼armyshu(~!@#$%^&*)回复于 2002-02-19 11:41:06 得分 2

getParameter只能传递string类型的变量,getAttribute能传递vector! 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值