adeelzzz
asked on
Get Array List in a JSP Page.
hi every one..
i m going to develop my first application in JSP+Struts. and i got some problem.
i want to display the whole data of my DB Table in a JSP Page.
i get all data through SQL Query and put that in a arrayList.
Here's the code for that
ArrayList allBulletin = null;
HashMap bulletins= null;
while (rset.next()) {
bulletins = new HashMap();
bulletins.put("BULLETIN_TY PE_OID", new Integer(rset.getInt("BULLE TIN_TYPE_O ID")));
bulletins.put("BULLETIN_TY PE_CD",rse t.getStrin g("BULLETI N_TYPE_CD" ));
bulletins.put("BULLETIN_TY PE_DESC",r set.getStr ing("BULLE TIN_TYPE_D ESC"));
bulletins.put("CREATE_BY", rset.getSt ring("CREA TE_BY"));
bulletins.put("ACTIVE_IND" ,rset.getS tring("ACT IVE_IND")) ;
bulletins.put("CREATE_DATE ",rset.get String("CR EATE_DATE" ));
allBulletin.add(bulletins) ;
}//end of while (rset.next())
request.setAttribute("RS", allBulletin);
return("success");
========================== ========== ========== ========== ==
now i m in my JSP and here i try to access data with this ArrayList but it display that in wrong format..
can any body help me abt this issue.
the code ro access ArrayList is Following
<%
ArrayList allBulletin= null;
//To see the Elements of the arraylist
allBulletin = (ArrayList)request.getAttr ibute("RS" );
System.out.println("The size of arraylist ="+ allBulletin.size());
System.out.println("The arraylist is Empty? ="+ allBulletin.isEmpty());
if (!allBulletin.isEmpty()){
for (int i=1 ;i <= allBulletin.size();i++)
{
%>
<tr>
<td class="style22" width="66" height="17"><%=allBulletin .get(2)%>< /td>
<td class="style22" width="213" height="17"><%=allBulletin .get(3)%>< /td>
<td class="style22" width="87" height="17"><%=allBulletin .get(4)%>< /td>
<td class="style22" width="79" height="17"><%=allBulletin .get(5) %></td>
<td class="style22" width="65" height="17">
<%
if (allBulletin.get(6).equals ("A"))
{out.println("Active");}
else
{out.println("In-Active"); }
%>
</td>
<td width="41" height="17"><p align="center"><a href="Bulletin_Type.jsp">E dit</p></a ></td>
</tr>
<%
i m going to develop my first application in JSP+Struts. and i got some problem.
i want to display the whole data of my DB Table in a JSP Page.
i get all data through SQL Query and put that in a arrayList.
Here's the code for that
ArrayList allBulletin = null;
HashMap bulletins= null;
while (rset.next()) {
bulletins = new HashMap();
bulletins.put("BULLETIN_TY
bulletins.put("BULLETIN_TY
bulletins.put("BULLETIN_TY
bulletins.put("CREATE_BY",
bulletins.put("ACTIVE_IND"
bulletins.put("CREATE_DATE
allBulletin.add(bulletins)
}//end of while (rset.next())
request.setAttribute("RS",
return("success");
==========================
now i m in my JSP and here i try to access data with this ArrayList but it display that in wrong format..
can any body help me abt this issue.
the code ro access ArrayList is Following
<%
ArrayList allBulletin= null;
//To see the Elements of the arraylist
allBulletin = (ArrayList)request.getAttr
System.out.println("The size of arraylist ="+ allBulletin.size());
System.out.println("The arraylist is Empty? ="+ allBulletin.isEmpty());
if (!allBulletin.isEmpty()){
for (int i=1 ;i <= allBulletin.size();i++)
{
%>
<tr>
<td class="style22" width="66" height="17"><%=allBulletin
<td class="style22" width="213" height="17"><%=allBulletin
<td class="style22" width="87" height="17"><%=allBulletin
<td class="style22" width="79" height="17"><%=allBulletin
<td class="style22" width="65" height="17">
<%
if (allBulletin.get(6).equals
{out.println("Active");}
else
{out.println("In-Active");
%>
</td>
<td width="41" height="17"><p align="center"><a href="Bulletin_Type.jsp">E
</tr>
<%
Right now in your above code you are not dieplaying the data instead you are displaying the hashmaps.
i.e
<td class="style22" width="66" height="17"><%=allBulletin .get(2)%>< /td>
<td class="style22" width="213" height="17"><%=allBulletin .get(3)%>< /td>
<td class="style22" width="87" height="17"><%=allBulletin .get(4)%>< /td>
<td class="style22" width="79" height="17"><%=allBulletin .get(5) %></td>
instead if you want to display data inside the hash map loop through the hashMap using one more for loop.
for (int i=1 ;i <= allBulletin.size();i++)
{
for(int j =0;j<allBulletin.get(i).si ze();;j++)
{
// now here you loop through the hashMap and display the data inside it.
i.e
<td class="style22" width="66" height="17"><%=allBulletin
<td class="style22" width="213" height="17"><%=allBulletin
<td class="style22" width="87" height="17"><%=allBulletin
<td class="style22" width="79" height="17"><%=allBulletin
instead if you want to display data inside the hash map loop through the hashMap using one more for loop.
for (int i=1 ;i <= allBulletin.size();i++)
{
for(int j =0;j<allBulletin.get(i).si
{
// now here you loop through the hashMap and display the data inside it.
In first place, why to keep the results in hashmap? You can directly use the List of java beans to hold the information.
If you need further info, please ask back.
If you need further info, please ask back.
ASKER
well fargo i got ur point i try to do that in this way and first put data in HashMap and then pass to Array list and while getting that i gte that array list and pass that to hashmap.
and try to get data through that hash map with .get method.
but now it gave me null pointer exception.
can u put the exact code of this process
regards
and try to get data through that hash map with .get method.
but now it gave me null pointer exception.
can u put the exact code of this process
regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
THANKS EVERY BODY I DID THAT
<%
ArrayList allBulletin = null;
HashMap bulletin = null;
allBulletin= (ArrayList)request.getAttr ibute("Bul letins");
//bulletin.get(allBulletin );
System.out.println("IS empty??" + allBulletin.isEmpty());
if (null != allBulletin){
out.println("Total no of Records are= " + allBulletin.size());
for (int i=0 ;i < allBulletin.size();i++)
{
bulletin = (HashMap)allBulletin.get(i );
%>
<tr>
<td class="TD.OddRowBG" width="66" height="17"><%=bulletin.ge t("BULLETI N_TYPE_CD" )%></td>
<td class="TD.OddRowBG" width="66" height="17"><%=bulletin.ge t("BULLETI N_TYPE_DES C")%></td>
<td class="TD.OddRowBG" width="66" height="17"><%=bulletin.ge t("CREATE_ Date")%></ td>
<td class="TD.OddRowBG" width="66" height="17"><%=bulletin.ge t("CREATE_ BY")%></td >
<td class="TD.OddRowBG" width="66" height="17">
<%
if (bulletin.get("ACTIVE_IND" ).equals(' A'))
out.println("Active");
else
out.println("In Active"); %>
</td>
</tr>
<%
}//end for
}//end if
%>
<%
ArrayList allBulletin = null;
HashMap bulletin = null;
allBulletin= (ArrayList)request.getAttr
//bulletin.get(allBulletin
System.out.println("IS empty??" + allBulletin.isEmpty());
if (null != allBulletin){
out.println("Total no of Records are= " + allBulletin.size());
for (int i=0 ;i < allBulletin.size();i++)
{
bulletin = (HashMap)allBulletin.get(i
%>
<tr>
<td class="TD.OddRowBG" width="66" height="17"><%=bulletin.ge
<td class="TD.OddRowBG" width="66" height="17"><%=bulletin.ge
<td class="TD.OddRowBG" width="66" height="17"><%=bulletin.ge
<td class="TD.OddRowBG" width="66" height="17"><%=bulletin.ge
<td class="TD.OddRowBG" width="66" height="17">
<%
if (bulletin.get("ACTIVE_IND"
out.println("Active");
else
out.println("In Active"); %>
</td>
</tr>
<%
}//end for
}//end if
%>
adeel, you must be happy that the problem is solved. But keep in mind the way it generally handled with struts (which i mentioned). Keep yourself open to change the handling later on...
hI Adeel,
I believe this post deserves a point split with other experts. Why haven't u split the points?
I believe this post deserves a point split with other experts. Why haven't u split the points?
Moreover, why a grade of B? If you have further questions please ask.
adeelzzz you may want to see the byundt's comment at the bottom here:
https://www.experts-exchange.com/questions/21820101/I-cannot-'save-as'-or-open-files-in-Office-2003-This-is-a-new-problem-today.html
Also you may read about grading in the site's help section.
https://www.experts-exchange.com/questions/21820101/I-cannot-'save-as'-or-open-files-in-Office-2003-This-is-a-new-problem-today.html
Also you may read about grading in the site's help section.
1) What is the idea of
for (int i=1 ;i <= allBulletin.size();i++)
I don't see to use "i" nowhere in the body of the loop
So you're trying to output several times the same??
2) allBulletin.get(2) - isn't this one that you're trying to print a hashmap?
3) why allBulletin.get(2) to allBulletin.get(6)?