This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes parameters, headers, and attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "parameters, headers, and attributes" Watch "parameters, headers, and attributes" New topic
Author

parameters, headers, and attributes

Dave Segal
Greenhorn

Joined: Aug 13, 2002
Posts: 20
the servlet request object provides methods to get and set headers, parameter, and attribute objects. I'm trying to get a clear picture of the differences between them and when to select one over the other. (f
Ror example, if I want to add something to a request, then forward it to another servlet for processing, which should I use?
If anyone can share some insight on this topic, that would be great.
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Originally posted by DaveSegal:
Ror example, if I want to add something to a request, then forward it to another servlet for processing, which should I use?

Use get/setAttributes to pass objects around your webapp. See this
link.
Ken Robinson
Ranch Hand

Joined: Jul 25, 2002
Posts: 52
Headers are usually not required for what you are doing. The headers are created by the browser and they tell the server what is being request, how it is being requested and from who. Usually, the info you need from the headers are available as a set of methods on the HttpServletRequest object (getRequestType() and so on).
Parameters are what is coming from page the user was on when the request was made. If you have an HTML page with a UserName and Password ...

... the method getParameter("userName") will return what the user entered in that field. This is alwasy a String, so you will need to convert/validate non String values (numbers, dates).
Attributes are set by the web app(Servlet/Filter/JSP). Usually, a Servlet will get a bunch of parameters, do work based on those parameters (DB Query) and place the results in the request as an Attribute. If a user logs in correctly, you may create a UserBean object. You could then place this bean in the Request (Usually you would place this in the Session, which also has a setAttribute method) and forward to a JSP page. The JSP page can get the UserBean from the Request (via getAttribute) and show user info as needed.
Hope this helps.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
DaveSegal
Welcome to the JavaRanch! Please adjust your display name to meet
the JavaRanch Naming Policy. You can change it here.
Thanks!
and welcome to the JavaRanch!

A space between them would do it
 
jQuery in Action, 2nd edition
 
subject: parameters, headers, and attributes
 
Similar Threads
response.setHeader not working
Request. ServerVariables ( REMOTE_USER") equalent in jsp
How to set http headers in servlet request ?
Can anybody help to getrid of this error?
setting request header