aspose file tools*
The moose likes Servlets and the fly likes i do not understand servlet request.setAttribute ~ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "i do not understand servlet request.setAttribute ~" Watch "i do not understand servlet request.setAttribute ~" New topic
Author

i do not understand servlet request.setAttribute ~

Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
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!
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Since your question is really about the Servlet API, I'm going to move this to Servlets.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Attributes are retrieved from the request using HttpServletRequest.getAttribute(). A quick example is:



Simple, easy, like God intended.
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
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

Joined: Jul 18, 2001
Posts: 2712
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

Joined: Jan 08, 2004
Posts: 834
thanks , chris , i have better understanding now ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i do not understand servlet request.setAttribute ~