• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with respect to String Array in Struts

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
We are facing an issue as shown below.



Java code as shown below ::



When I tokenize the Strings I get 3 independent strings.which I need to display in the jsp page using logic:iterate one below the other how do I do that
In jsp output should be


Mumbai
Calcutta
Bangalore


Could you please help me with the code in JSP and how to set the countries in Java.(Action class)...

 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set the String array in the request or session attribute and then use it in the jsp.

e.g. request.setAttribute("countryList",countries) in the action class

then in the jsp



or if you have array property int he form then set the country array inthe form property then use it in the jsp as below

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or if you have array property in the form then set the country array in the form property then use it in the jsp as below



Hi Siva,
what changes do i need to make in in my form and in action class and jsp...could you help me out with that for the above code to work in jsp.

Thanks and Regards
Deepak Lal
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let say this is the ActionForm



Then in the action class



In struts-config.xml,you might have something like this



the name in the iterate tag should match the name you defined inthe form-beans in struts-config.xml

In jsp


Additionally you may add logivc:prsent tag to check if the array is not empty before using iterate tag.i.e put the logic:iterate tag inside logic:present tag.
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Siva,
Thanks for the inputs.Let me check and get back to you in case i face any issues..
Thanks and Regards
Deepak Lal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic