• 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

parameters, headers, and attributes

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Your mother was a hamster and your father was a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic