Accessing ArrayList to place in table on jsp page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JoeMac3313
    New Member
    • Jul 2007
    • 16

    Accessing ArrayList to place in table on jsp page

    I have been flailing widely about trying to get the information from the arrayList to the jsp page to print to a table on the jsp page.

    The information on the txt file is

    Name:Department :Job Title:Year Hired:Gender


    Code:
    
    <%@page import="java.io.*"%>
    
    <%@ page session="false"%>
    
    
    
    
    <html>
    
    <head><title>Employees Hired</title></head>
    <head><description>Employee Listing</description></head>
    <form method="post" action="hiredEmployee.jsp"/> 
    
    
    <table border='2' cellspacing='0' cellpadding='4'>
       <tr><th> Name </th><th> Department <th> Job Title </th><th> Year Hired </th><th> Gender </th></tr>
    
    
    </html>
    
    
    
    
    ////////////////////////////////////////////////////////////////////////////////////////
    
    package domain;
    
     import java.util.Scanner;
     import java.io.*;
     import java.util.ArrayList;
     import java.lang.*;
     
    public class HiredEmployee {
        
        public ArrayList line = new ArrayList();
        private String temp="";	
        private String[] words; 
        private Scanner sInput = null;
        
        	
        public ArrayList<String> getLine(){
       
    		words=new String[line.size()];
      		try{
        			sInput = new Scanner(new FileReader("hired.txt"));
        	
        		
        			while (sInput.hasNextLine()){
        				temp=sInput.nextLine();
        				line.add(temp);
        				//words = temp.split(":");
        				 	
        			}
        	}
        	catch (FileNotFoundException exception) {}
        		sInput.close();
        		 return line;
        	}
       	
    }
    Any insights woudl be greatly appreciated!

    Thanks,
    JoeMac
  • itsraghz
    New Member
    • Mar 2007
    • 124

    #2
    As per your query on the title, "Accessing ArrayList to place in table on jsp page" the logic goes as follows.
    1. Create an arraylist somewhere - preferably in a Java class
    2. Store the arraylist in one of the available scopes - request, session for eg.,
    3. Access the arraylist object from the scope in JSP page
    4. Iterate the array list inside the <tr> tags of your JSP page using the scriptlets <%..%>


    Hope this helps.

    Comment

    Working...