• 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

working with hashmap using struts2

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am very new to struts 2.
I have a requirement to pass HashMap object as argument to execute method in action class.... and display its contents in JSP.

How to make variables stateless in struts 2?

IS there any example or any book to refer?

Please help me !
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never tried, but I don't see any facility to pass an argument to an action method in the documentation.
Exactly what are you trying to do? Where does this hashmap come from? In order to be passed to the execute method it has to come from a form or an interceptor. Is there any way for the action method to fetch the information it needs?
 
Aditi Gandy
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NO actually, I have hardcoded a HashMap in execute method. When i try to display the contents of Hashmap in JSP, it is not displaying it.
My code goes here:






And also, i am not able to trace, where exactly values of System.out.println is printing..i am not able to figure out where is console output in Tomcat 6.0

Can anyone please help.
 
Aditi Gandy
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please help me.

Regards,
Ashvini
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi ashvini pradeep ,

First of all understand hasMap concept. HasMap contains key and value fields.

In your code
# myMap.put("Sun", "Java");
# myMap.put("MS", "Net");
# myMap.put("SAP", "ABAP");
# myMap.put("SQL", "DataBase");

"Sun","MS"...etc are your key value and "Java","Net"...etc are your value so,

If you want to display it in jsp

Use this code:


<s:iterator value="myMap">
<s:property value="key" /> <s:property value="value" />
</s:iterator>

The first <s:property value="key" /> will display "Sun","MS"...etc your key value.

And second <s:property value="value" /> will display "Java","Net"...etc display your value.


 
Aditi Gandy
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Nishan,
Thank you very much for your reply.

Even after adding your code to display key and value, I am not able to see the contents of my Hashmap on the web page.
Can't understand where i am going wrong.

my log entries as follows:



 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello Again,

Change your code in struts.xml.


# <action name="it" class="Iterate">
# <result>/pages/Iterate.jsp</result>
# </action>

Remove and change code as belove

# <action name="it" class="Iterate">
# <result name="success">/pages/Iterate.jsp</result>
# </action>


 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have declared two actions, "doLogin" and "it". Your log indicates you are invoking an action "HelloWorld":

 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually change your Helloword form action type to "it".


You are submitting from with action "Helloword " which is not found so please change it to "it" in your jsp

<s:form action="it" method="post" />

</s:form>

 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic