| Author |
How To Iterate String[] in JSP Without Using Scriptlets (In Struts1.2)
|
prasad boini
Greenhorn
Joined: Nov 22, 2012
Posts: 5
|
|
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: 8259
|
|
|
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: 5
|
|
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.
|
 |
 |
|
|
subject: How To Iterate String[] in JSP Without Using Scriptlets (In Struts1.2)
|
|
|