Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
prasad boini
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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//

 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the iterate tag.
 
prasad boini
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic