• 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

How To Iterate String[] in JSP Without Using Scriptlets (In Struts1.2)

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I Have One Registration.jsp, in that text boxes, radio buttons, check boxes are there.
Once the User is Registered , i want to display the data which is entered.
Let's Have a Look at on My Code.
DTO:
===
package com.strutsexp.dto;

public class NewUserInfoDTO {
private Integer id;
private String sex;
private String address;
private Integer age;
private String name;
private String[] knowntechnologies;
private String country;

//getters and Setters

}


package com.strutsexp.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.strutsexp.dto.NewUserInfoDTO;
import com.strutsexp.form.RegisternewuserForm;


public class RegisternewuserAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
RegisternewuserForm registernewuserForm = (RegisternewuserForm) form;
NewUserInfoDTO dto = new NewUserInfoDTO();
dto.setId(registernewuserForm.getId());
dto.setName(registernewuserForm.getName());
dto.setAge(registernewuserForm.getAge());
dto.setAddress(registernewuserForm.getAddress());
dto.setCountry(registernewuserForm.getCountry());
dto.setKnowntechnologies(registernewuserForm.getKnowntechnologies());//Here I Get String[]
dto.setSex(registernewuserForm.getSex());
request.setAttribute("userinfo", dto);
return mapping.findForward("sucess");
}
}
================
Sucess.jsp
===========
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<html>
<body bgcolor="cyan">
<center>
<h1>
You Are Sucessfully Register
<br>
</h1>
<font color="RED" size="5" style="font-style: ">
Id:${userinfo.id }<br> Name:${userinfo.name }<br>
Sex:${userinfo.sex}<br> Age:${userinfo.age}<br>
Address:${userinfo.address }<br> Country:${userinfo.country}<br>
Known Technologies:${userinfo.knowntechnologies}<br> </font>//How to iterate Here.
</center>
</body>
</html>

OutPut:
=======
You Are Sucessfully Register

Id:11
Name:john
Sex:male
Age:24
Address:Hyderabad
Country:India
Known Technologies:[Ljava.lang.String;@41b635//

 
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
Have a look at the iterate tag.
 
prasad boini
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Ess wrote:Have a look at the iterate tag.




Thank You Joe Ess.
But Here the problem is String[] is property in Java Bean, That Java Bean Object i stored in The Request Scope.
We can iterate collection object/string[] using foreach loop/iterate tag .
But till now I haven't get an idea. How can iterate it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic