• 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

i do not understand servlet request.setAttribute ~

 
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm newbie in struts, i do have difficulty of understanding on how request.setAttribute work , what is the value i get after request.setAttribute?

SignupAction1.java


MessageBean.java



Q1) from SignupAction1.java , how do i get the values/attribute after the setAttribute method ?

Q2) what i guess on retrieved attribute here is "message" , can anyone kindly please guide or show me the way how this attribute been retrieve ?

thank you very much for helping!
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since your question is really about the Servlet API, I'm going to move this to Servlets.
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Attributes are retrieved from the request using HttpServletRequest.getAttribute(). A quick example is:



Simple, easy, like God intended.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
chris, you means setAttribute not necessary for only retrieve form data right ? in my case, it actually get "message" variable from MessageBean.java ? if so , how to i show the output it ?
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpServletRequest.getAttribute() and HttpServletRequest.setAttribute() go together like peas and carrots. The existance of one is only justified by the existance of the other.

But to your question, setAttribute() is used for putting Objects into the request and getAttribute() is used for getting those previously placed Objects back out. If your application never uses setAttribute than consequently there will never be a reason to call getAttribute().

Now, I get the feeling what you are really trying to do is get at the HTTP request parameters. This is a slightly different beast. HTTP parameters are all passed as Strings (as opposed to Objects) and are available via readonly access. The way to get to these parameters is by using HttpServletRequest.getParameter(). As you seem to be pretty new to the Servlet/JSP world I highly that you run out and pick up a copy of a good Servlet book (see the Bunkhouse for some ideas). Otherwise you are in for a world of pain as you learn the ropes.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks , chris , i have better understanding now ...
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic