Solved

generate a dynamic table on JSP page

Posted on 2009-04-03
6
757 Views
Last Modified: 2012-06-27
Hi Experts,
           I am displaying the attached chart on my jsp page, Every new month is added in the X-axis as soon as the month gets populated in the Database Table.
           What I want to achieve is , Display the data (SLA Compliance column of the table) present in the chart in a tabular Form, with Column names as months, and with the addition of a new month, a new column should automatically be generated.
           Can someone please help me out with this.

           I have attached the Chart snap shot along with  a snippet of backend Table, used for this chart
           
Chart.PNG
back-Table.PNG
0
Comment
Question by:aman0711
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
TheVeee earned 500 total points
ID: 24059506
1.  First create a bean with Application, Month, Year, SLA_COMPLIANCE and then Total_Metrics attributes and for example we will call it BeanA.

2.  Next in the servlet create a ArrayList named BeanA_ArrayList.

3.  Next loop thru database resultset and as you read each row from the result set, create a new BeanA.

4.  Once done creating BeanA from step3, then add it to a ArrayList called BeanA_ArrayList.

5.  Then store the ArrayList to the request object.

5.  Once done call your jsp page you want to display your table in.

6.  Next in your jsp add addressibility to the ArrayList from the request object.

7.  Next loop thru the arraylist and build the html on the fly.

Look at the below tutorial then go to booklist.jsp... will show you...
http://www.laliluna.de/first-java-servlets-jsp-tutorial.html
0
 
LVL 10

Author Comment

by:aman0711
ID: 24059547
Hi Vee,
             I am very new to Java.. I never worked with JSP and Servlet. Just know a little about jsp
0
 
LVL 5

Expert Comment

by:TheVeee
ID: 24059604
thats ok, we all hav to learn.. np....
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:aman0711
ID: 24059653
What I was doing till now is this.
just the scratch..

Its giving me the first column fine as Jul, but all others vertically below it

<table border="1" cellspacing="1" bgcolor="#FFFFFF" WIDTH=99.5%>
	<tr>
		<th>Application</th>
		
 
 
	<%
		Connection conn = null;
		conn = db.getConnection();
 
		String sql = "";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
 
		sql = "Select * from WEB_EXSUMM_12MONTH_APPL_V WHERE APPLICATION='ED' ORDER BY DECODE(UPPER(MONTH), 'JAN', 7, 'FEB', 8, 'MAR', 9, 'APR', 10, 'MAY', 11, 'JUN', 12, 'JUL', 1, 'AUG', 2, 'SEP', 3, 'OCT', 4, 'NOV', 5, 'DEC', 6)";
		pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
		rs = pstmt.executeQuery(sql);
		
		while (rs.next()) {
	%>
        <th align='center'><%=rs.getString(2) %></th>
     </tr>   
	<tr>
 
		<td><%=rs.getString(1)%></td>
		
		
	</tr>
 
	<%
		}
		rs.close();
		pstmt.close();
		conn.close();
	%>
 
</table>

Open in new window

0
 
LVL 5

Assisted Solution

by:TheVeee
TheVeee earned 500 total points
ID: 24059661
Heres their example, notice that arraylist books is retrieved from the request object.  The servlet prior to calling the jsp, set the attribute of books with the ArrayList they wanted.

<%                                    ArrayList arrayList = (ArrayList)request.getAttribute("books");                            //loope über die Liste von Büchern und gibt die Eigenschaften aus              for (Iterator iter = arrayList.iterator(); iter.hasNext();) {                    Book element = (Book) iter.next();                                      out.println("<tr>");                  out.println("<td>" + element.getAuthor() + "</td>");                  out.println("<td>" + element.getTitle() + "</td>");                  if(element.isAvailable())                        out.println("<td><input type="checkbox" name="available" value="true" disabled checked></td>");                  else                        out.println("<td><input type="checkbox" name="available" value="true" disabled></td>");                                    out.println("<td><a href="bookEdit?do=edit&id=" + element.getId() + "">Edit</a></td>");                  out.println("<td><a href="bookEdit?do=delete&id=" + element.getId() + "">Delete</a></td>");                  out.println("</tr>");              }        %>
0
 
LVL 10

Author Comment

by:aman0711
ID: 24059712
ok, I will try
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSV file parsing thru Java 13 52
SequenceInputStream example 3 34
Crystal Reports Licensing Questions 4 81
Java program running SQL query 5 60
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question