Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parameters, headers, and attributes

 
Dave Segal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic