File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "parameters, headers, and attributes" Watch "parameters, headers, and attributes" New topic

parameters, headers, and attributes

Dave Segal

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
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
Welcome to the JavaRanch! Please adjust your display name to meet
the JavaRanch Naming Policy. You can change it here.
and welcome to the JavaRanch!

A space between them would do it
I agree. Here's the link:
subject: parameters, headers, and attributes
It's not a secret anymore!