• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between request parameter and request attribute

 
Ranch Hand
Posts: 31
1
Oracle Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

What are the key differences between request parameter and request attribute?

Thanks
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

What are the key differences between request parameter and request attribute?


Parameter:
  • Read only
  • Contains submitted data
  • Strings


  • Attribute:
  • Read/Write
  • Doesn't contain submitted data
  • Can be any Object


  • Regards,
    Frits
     
    Ranch Hand
    Posts: 68
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Request Parameter are submitted with request URL and you can get thos parameter values using getParameter(String name)

    Later if you want, you can set parameters in request scope, which will be accessed in other included/forwarded servlet/JSP while using RequestDispatcher mechanism.


    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.

    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.
     
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Posts: 3411
    320
    Android Eclipse IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Later if you want, you can set parameters in request scope, which will be accessed in other included/forwarded servlet/JSP while using RequestDispatcher mechanism.


    Be careful here: there is no ServletRequest.setParameter() or HttpServletRequest.setParameter() method, nor is there a RequestDispatcher.addParameter() of RequestDispatcher.setParameter() method.

    What you are describing is a mechanism in a JSP where you can use the <jsp:param> in following tag:

    These additional parameters are added to the request, but only for the duration of the include or forward.

    Regards,
    Frits
     
    reply
      Bookmark Topic Watch Topic
    • New Topic