This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Difference between request parameter and request attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Difference between request parameter and request attribute" Watch "Difference between request parameter and request attribute" New topic
Author

Difference between request parameter and request attribute

Akhilesh Murthy
Greenhorn

Joined: Oct 07, 2009
Posts: 24

Hi,

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

Thanks
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1628
    
  23

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
    Sharad Kharya
    Ranch Hand

    Joined: Oct 15, 2008
    Posts: 68
    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
    Bartender

    Joined: Apr 07, 2010
    Posts: 1628
        
      23

    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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Difference between request parameter and request attribute
     
    Similar Threads
    Difference between attributes and parameters
    dout in request scoped attribute and parameter
    request.getAttribute vs request.getParameter
    parameter vs attributes?
    Request parameter and Attribute??