• 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

Need to access a variable in jsp from action class

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have my result in action class and want to use those variables in jsp. I am using Struts2 which is different from struts 1.x in session variable's. Can some one let me know easy way to handle this?

Thanks
Anil
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

anilkumar potu wrote:I have my result in action class and want to use those variables in jsp.



Just add a getter in your action class that returns the value you'd like to show on the page and use the property tag to output its value. If it's a Collection or array, you can loop through its elements with iterator.
 
anilkumar potu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply. If i am not wrong Property will be used as a static display. But i want my result in some variable and i need to use it in my jsp's.

Any suggestions?

anil
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

anilkumar potu wrote: But i want my result in some variable and i need to use it in my jsp's.



You shouldn't have Java code in your JSP, it's against the principles of the MVC pattern, if you do that, you might as well throw out Struts and put all your code in JSPs!
 
anilkumar potu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its not that i have my java code in jsp. I need to use the result variables in my jsp for further processing and displaying results to user accordingly.
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

anilkumar potu wrote:Its not that i have my java code in jsp. I need to use the result variables in my jsp for further processing and displaying results to user accordingly.



What kind of "further processing" are you doing then? Can't it be done with struts tags..?

You could add your variables to the http servlet request, for instance, like this.
 
anilkumar potu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got my result. I used sessionaware and session get/set attribute.

 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

anilkumar potu wrote:I got my result. I used sessionaware and session get/set attribute.



Make sure you remove them from session when they're no longer needed!
 
anilkumar potu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure Thanks
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't need them in the session, don't put them there in the first place: the normal way to expose data to a JSP in Struts 2 is to create an action property with a public getter and use the Struts 2 tags, or JSP EL, on the JSP side--which was the first answer you received.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic