aspose file tools*
The moose likes Struts and the fly likes How To Iterate String[] in JSP Without Using Scriptlets  (In Struts1.2) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How To Iterate String[] in JSP Without Using Scriptlets  (In Struts1.2)" Watch "How To Iterate String[] in JSP Without Using Scriptlets  (In Struts1.2)" New topic
Author

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

prasad boini
Greenhorn

Joined: Nov 22, 2012
Posts: 8
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

Joined: Oct 29, 2001
Posts: 8708
    
    6

Have a look at the iterate tag.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
prasad boini
Greenhorn

Joined: Nov 22, 2012
Posts: 8
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How To Iterate String[] in JSP Without Using Scriptlets (In Struts1.2)
 
Similar Threads
Generating user details in form as ReadOnly
in which method shuld i use at the servlet code for request
can not forward after response has been committed
SqlException accured at processing Jsp
strut exception