Solved

generate a dynamic table on JSP page

Posted on 2009-04-03
6
752 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.

820 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