Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Retrive values from an arraylist and display in a jsp

Reply
Thread Tools

Retrive values from an arraylist and display in a jsp

 
 
Deepa
Guest
Posts: n/a
 
      07-31-2006
Hi,

I need help in jsp to display values of an arraylist in jsp.

There is a java file containing a method which is returning an
arraylist.

I want to display the record of arrayList in jsp in tabular form say 10
records.

can anyone help me on this.

Thanks in advance.
Deepa

 
Reply With Quote
 
 
 
 
hiwa
Guest
Posts: n/a
 
      07-31-2006
Deepa のメッセージ:

> Hi,
>
> I need help in jsp to display values of an arraylist in jsp.
>
> There is a java file containing a method which is returning an
> arraylist.
>
> I want to display the record of arrayList in jsp in tabular form say 10
> records.
>
> can anyone help me on this.
>
> Thanks in advance.
> Deepa

Is is like this? :
<TD><%= arrayList.get(n) %></TD>

 
Reply With Quote
 
 
 
 
Deepa
Guest
Posts: n/a
 
      07-31-2006
I have added in arrayList like this

retArrayList.add(rs.getString(5));
log.debug("First name of terminated emp : " +
rs.getString(5));
retArrayList.add(rs.getString(6));
log.debug("Last name of terminated emp : " +
rs.getString(6));

say if there are 7 records then arrayList returning its size as 14 (7
for firstname and 7 for lastname). but according to me its size shod be
7.

hiwa wrote:
> Deepa のメッセージ:
>
> > Hi,
> >
> > I need help in jsp to display values of an arraylist in jsp.
> >
> > There is a java file containing a method which is returning an
> > arraylist.
> >
> > I want to display the record of arrayList in jsp in tabular form say 10
> > records.
> >
> > can anyone help me on this.
> >
> > Thanks in advance.
> > Deepa

> Is is like this? :
> <TD><%= arrayList.get(n) %></TD>


 
Reply With Quote
 
simhani jagadeesh simhani jagadeesh is offline
Junior Member
Join Date: Mar 2012
Posts: 7
 
      03-01-2012
This code is in Struts how to collect listobjects from actionclass,helper,DAo and get that list in jsp using struts tags
objuserDatalist = objLoginHelper.getUserDataList();
request.setAttribute(USER_DATALIST, objuserDatalist);

-<---objUserDataList = objLoginDAO.getUserDataList();<---objEmpList = (ArrayList) session.createQuery("from EmployPOJO where empStatus='A'").list();
---------------------------------------------------------------------------
request.setAttribute(USER_DATALIST, objuserDatalist);

<logic:notEmpty name="userDataList">
<logic:iterate name="userDataList" id="userlist">
<td> <bean:write name="userlist" property="empId"/></td>
<td> <bean:write name="userlist" property="empName"/></td>
<td> <bean:write name="userlist" property="empDesg"/></td>
<td> <bean:write name="userlist" property="empComp"/></td>
<td> <bean:write name="userlist" property="empLoc"/></td>
<td> <bean:write name="userlist" property="empMob"/></td>
<td> <bean:write name="userlist" property="empPhone"/></td>
<td> <bean:write name="userlist" property="empMail"/></td>


</tr>
</logic:iterate>
</logic:notEmpty>
 

Last edited by simhani jagadeesh; 03-01-2012 at 11:04 AM..
Reply With Quote
 
simhani jagadeesh simhani jagadeesh is offline
Junior Member
Join Date: Mar 2012
Posts: 7
 
      03-01-2012
Quote:
Originally Posted by Deepa View Post
Hi,

I need help in jsp to display values of an arraylist in jsp.

There is a java file containing a method which is returning an
arraylist.

I want to display the record of arrayList in jsp in tabular form say 10
records.

can anyone help me on this.

Thanks in advance.
Deepa

from jdbc or hibernate return List (with db data either using jdbc or hibernate)and set that list into request is best practice (or session ) like request.setAttribute("objList", objuserDatalist); and get list in jsp by using JSTL or EL expressions(like $list)
  1. <C:IF test="${not empty names}">
  2. <C:FOREACH var="objList" items="${objList}">
  1. <C:OUT value="${objList.name}"></C:OUT>
  2. <C:OUT value="${objList.id}"></C:OUT>
  3. </C:FOREACH></C:IF>
 
Reply With Quote
 
simhani jagadeesh simhani jagadeesh is offline
Junior Member
Join Date: Mar 2012
Posts: 7
 
      03-01-2012
<td> <a href="viewEmploy.do?id=<bean:write name="userlist" property="empId"/>">viewEmployee</a></td>---->this if multiple records table data but when click on viewEmployee link it only has to display only one employ data depend on passed empId as parameter.in viewEmploy Action (becoz of viewEmploy.do)
if( request.getParameter("id")!=null)
{
empId=Integer.parseInt(request.getParameter("id")) ;
} EmployActionForm objEmpForm=(EmployActionForm)form;
UserDataBean objUserBean=objLoginHelper.retrieveEmployDetailsby Id(empId);-<---objEmpList = (ArrayList) session.createQuery("from EmployPOJO where empStatus='A' and empId = " + id).list();
objPojo = (EmployPOJO) objEmpList.get(0);
BeanUtils.copyProperties(objUserBean, objPojo);
return objUserBean;
objLoginHelper.popuateDataIntoActionForm(objUserBe an,objEmpForm);
return mapping.findForward(SUCCESS);
<table border="1">
<tr>
<td>Employee Id :
</td>
<td>Employee Name :
</td>
<td>Employee Designation :
</td>
<td>Employee Company :
</td>
<td>Employee Location :
</td>
<td>Employee Mobile :
</td>
<td>Employee Email :
</td>
</tr>
<tr>
<td><bean:write name="EmployActionForm" property="empId"></bean:write>
</td>
<td><bean:write name="EmployActionForm" property="empName"></bean:write>
</td>
<td><bean:write name="EmployActionForm" property="empDesg"></bean:write>
</td>
<td><bean:write name="EmployActionForm" property="empComp"></bean:write>
</td>
<td><bean:write name="EmployActionForm" property="empLoc"></bean:write>
</td>
<td><bean:write name="EmployActionForm" property="empMob"></bean:write>
</td>
<td><bean:write name="EmployActionForm" property="empMail"></bean:write>
</td>
</tr>
</table>
 
Reply With Quote
 
simhani jagadeesh simhani jagadeesh is offline
Junior Member
Join Date: Mar 2012
Posts: 7
 
      03-01-2012
from servlet and from dao list and to jsp display jsp.
in displaylist.java servlet inside processRequest or service or doget or dopost method
ArrayList aListUsersData = null;
String strPath = "home.jsp";
try {
DisplayDAO objDAO = new DisplayDAO();
aListUsersData = objDAO.retriveUsersList();
request.setAttribute("usersList", aListUsersData);
RequestDispatcher dispatcher = request.getRequestDispatcher(strPath);
dispatcher.forward(request, response);
} catch (Exception ex) {
ex.printStackTrace();
}
------------------------------
DisplayDAO.java
ArrayList aListUsersData = null;
UserDataBean objUserBean = null;
try {
con = objDBCon.getConnection();
pstmtRef = con.prepareStatement(QueryConstants.getUserDataLis t);
rs = pstmtRef.executeQuery();
aListUsersData = new ArrayList();
while (rs.next()) {
objUserBean = new UserDataBean();
objUserBean.setEmpId(rs.getInt("emp_id"));
objUserBean.setEmpName(rs.getString("emp_name"));
objUserBean.setEmpDesg(rs.getString("emp_desg"));
objUserBean.setEmpComp(rs.getString("emp_comp"));
objUserBean.setEmpLoc(rs.getString("emp_loc"));
objUserBean.setEmpMob(rs.getString("emp_mob"));
objUserBean.setEmpPhone(rs.getString("emp_phone")) ;
objUserBean.setEmpMail(rs.getString("emp_email"));
aListUsersData.add(objUserBean);
}public static final String getUserDataList = "select * from employee where emp_status='A'";inside QueryConstants.java
home.jsp
<%
String userName = "";
ArrayList alistUsersList = null;
UserDataBean objUserBean = null;
if (session.getAttribute("user") != null) {
userName = (String) session.getAttribute("user");
} else {
response.sendRedirect("logout.jsp");
}
if (request.getAttribute("usersList") != null) {
alistUsersList = (ArrayList) request.getAttribute("usersList");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<table align="center" width="80%"> <tr><td align="left">Welcome <%=userName%></td> <td align="right"><a href="logout">Logout</a></td></tr> </table>


<%
if (alistUsersList != null && !alistUsersList.isEmpty()) {
%>
<table border="1" width="80%" align="center">
<tr>
<td>Emp Id</td>
<td>Emp Name</td>
<td>Designation</td>
<td>Company</td>
<td>Location</td>
<td>View</td>
<td>Edit</td>
<td>Delete</td>
</tr>
<%
for(int i=0; i< alistUsersList.size(); i++){
objUserBean = (UserDataBean) alistUsersList.get(i);
%>
<tr>
<td><%=objUserBean.getEmpId()%></td>
<td><%=objUserBean.getEmpName()%></td>
<td><%=objUserBean.getEmpDesg()%></td>
<td><%=objUserBean.getEmpComp() %></td>
<td><%=objUserBean.getEmpLoc() %></td>
 
Reply With Quote
 
simhani jagadeesh simhani jagadeesh is offline
Junior Member
Join Date: Mar 2012
Posts: 7
 
      03-01-2012
in home.jsp after display list.
<td><a href="viewuser?id=<%=objUserBean.getEmpId()%>">Vie w</a> </td>
String strId = "", strPath = "view.jsp";
try {
if (request.getParameter("id") != null) {
strId = request.getParameter("id");
}
UserDAO objDAO = new UserDAO();
UserDataBean objBean = null;
objBean = objDAO.retriveUserDataUser(strId);
request.setAttribute("userBean", objBean);
RequestDispatcher dispatcher = request.getRequestDispatcher(strPath);
dispatcher.forward(request, response);
---------------------------------------------------------------------------------
INSIDE view.jsp
<%if (request.getAttribute("userBean") != null) {
objBean = (UserDataBean) request.getAttribute("userBean"); }%>
<table align="center" width="80%"> <tr><td align="left">Welcome <%=userName%></td> <td align="right"><a href="logout">Logout</a></td></tr> </table>
<table width="80%" border="1">
<tr>
<td>Employee Id : </td>
<td><%=objBean.getEmpId()%></td>
</tr>
<tr>
<td>Employee Name : </td>
<td><%=objBean.getEmpName()%></td>
</tr>
<tr>
<td>Designation : </td>
<td><%=objBean.getEmpDesg()%></td>
</tr>
<tr>
<td>Company : </td>
<td><%=objBean.getEmpComp()%></td>
</tr>
<tr>
<td>Location : </td>
<td><%=objBean.getEmpLoc()%></td>
</tr>
<tr>
<td>Mobile : </td>
<td><%=objBean.getEmpMob()%></td>
</tr>
<tr>
<td>Phone : </td>
<td><%=objBean.getEmpPhone()%></td>
</tr>
<tr>
<td>E-Mail : </td>
<td><%=objBean.getEmpMail()%></td>
</tr>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to retrive the folder structure on the server and display on an applet on the client side. bala Java 3 12-18-2004 01:52 PM
Retrive the values in the list Box Amit D.Shinde ASP General 0 05-20-2004 12:24 PM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting ASP .Net 1 02-10-2004 07:45 PM
EJB: How to retrive foreign key values from a 1-N relation? Eric Ford Java 0 01-14-2004 03:58 PM
Iterate through ArrayList using an another ArrayList Saravanan Rathinavelu ASP .Net 3 08-19-2003 07:03 AM



Advertisments