JSP page getting data dynamically

I am new to JSP  but can do a bit of Java ...I am trying out my first JSP Pages


I have a File which I parse at Run time using a Tokenizer and display it in a table ..which I was sucessful ..As I am learning to do this (though the project is a real time one ...in bioinformatics) ..I was wondering if there is a better of way of doing this ..by say using a Java Class which stores the Table in some sort of a HashMap and I get the table on the fly ..at run time .

<div align="center">
<u><font face="Verdana, Arial, Helvetica, sans-serif"><b>Supplementtal Table1</b></font></u>
<br/>
<hr/>
<br/>
<table border=1 width="100%" align="center">
      <TR bgcolor="#B3D8D1">
    <TH ALIGN="LEFT">
    Common Name
    </TH>
    <TH ALIGN="LEFT">
    Expression Value
    </TH>
    <TH ALIGN="LEFT">
    Gene Acession Number
    </TH>
    <TH ALIGN="LEFT">
      Unigene Name
      </TH>
    <TH ALIGN="LEFT">
    GO Biological Process
    </TH>
    <TH ALIGN="LEFT">
    GO Cellular Component
    </TH>
    <TH ALIGN="LEFT">
    G0 Molecular Functions
    </TH>
        </TR>
        
<%
      try{
            int index = 0;
            while((line = in.readLine())!= null) {
                  if (index%2 == 0) {
%>            
      <TR bgcolor="#EFEFEF">
<%                  
                  } else {
%>
      <TR>
<%
                  }
                  st = new StringTokenizer(line, "\t");
                  int count = st.countTokens();
                  if (count == Header.length) {
                      while (st.hasMoreTokens()) {
%>                  
    <TD ALIGN="LEFT">
<%        
                              out.println(st.nextToken());
%>                              
    </TD>
<%      
                        }
                        index++;
                }
%>
      </TR>
<%
            }
            in.close();
      } catch(Exception e) {
            System.out.println("SupplyTable1Results.txt: " +e);
      }
%>
</table>
</div>
</body>
</html>

<%!
      private static final String[] Header = {"Common Name", "Expression Value", "Gene Acession Number",
                  "Unigene Name", "GO Biological Process", "GO Cellular Component", "G0 Molecular Functions"};
%>                  

##########################################################################################
micro_learnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

boonlengCommented:
You can add in servlet to manipulate the data from inputstream, set the data to HttpRequest attribute.
Then use the jsp to retrieve data from HttpRequest and render the data on screen.

Serlvet tutorial
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/ (Chapter 11)

Regards,
Boon Leng
bloodredsunCommented:
The correct data structure for you would not be a hashmap but a List such as an ArrayList and the best way to do it would be to read the file in the init method of the jsp (jspInit). This is run only once when the jsp is instantiated making it a more efficient way of loading the file.

AN example of calling the init method for a jsp can be seen below, this goes at the top of the page (I can't give you the exact code to create the ArrayList from the File as it's a marked assignment)

  <%!
  String name;
  public void jspInit() {
    javax.servlet.ServletConfig servletConfig = getServletConfig();
    name = servletConfig.getServletContext().getInitParameter("authorName");
  }
  %>

You don't need to use use a separate java class although if you did you should instantiate it in the init method as above. You don't really need to use a servlet either unless you want to start dealing with binary data, a jsp is fine.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.