Solved

arrays in jsp

Posted on 2004-04-08
15
265 Views
Last Modified: 2010-04-01
i need to store the following values in an array as i loop through a mysql table retrieving them. how would i enter them in an array if there was more than one person in the table?

ResultSet rs = stmt.executeQuery("SELECT fName,lName FROM register");             
            String name = "";
            String surname = "";
      
            while(rs.next())
            {
                       name = rs.getString(1);
                       surname = rs.getString(2);           
                 }
0
Comment
Question by:Raftor
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10788411
Better off using a Collection instead of an array, as they can dynamically increase in size as required.
you should create a new class to store your person details and then use something like:

List people = new ArrayList();
while(rs.next())
{
    name = rs.getString(1);
    surname = rs.getString(2);
    people.add(new Person(name, surname));
}
0
 

Author Comment

by:Raftor
ID: 10788437
sorry objects but thats went way over my head can you show me please.
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 10788497
your Person class would look like:

public class Person
{
   private String Name = null;
   private String Surname = null;

   public Person(String name, surname)
   {
      Name = name;
      Surname = surname;
   }

   public String getName()
   {
      return Name;
   }

   public String getSurname()
   {
      return Surname;
   }
}
0
 

Author Comment

by:Raftor
ID: 10788606
how do i get the jsp page to recoginise the jave class after i compile the java class?
0
 

Author Comment

by:Raftor
ID: 10788750
it says,

C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Project\applicants_jsp.java:102: cannot resolve symbol
symbol  : class Person

location: class org.apache.jsp.applicants_jsp
             
 people.add(new Person(name, surname));
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 10789173
Use import in your JSP
<%@ page import = "Person" %>
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 10789180
Hi,
If your Person class in the package then import the class with the package path. Eg: Your Person class is in com\jsp\util\Person.class then the import will be like

<%@ page import = "com.jsp.util.Person"%>

I hope it help.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Raftor
ID: 10790331
ive tried to import the file but it is giving me the error.

C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Project\applicants_jsp.java:9: package classfiles does not exist
import classfiles.*;


my folder structure is C:\Project\WEB-INF\classes\classfiles
and i import the class files like this <%@ page import="classfiles.*" %>







0
 
LVL 2

Expert Comment

by:anthony_castillon
ID: 10790569
Did you create the Person class as objects did above?  If so, add a package declaration (e.g. package com.raftor). Then in your JSP, your import should be <%@ page import="com.raftor.*" %>.
0
 

Author Comment

by:Raftor
ID: 10790639
ya i created the class as objects showed.  I packaged it like the other java file with 'package classfiles;' and imported                                                <%@ page import="classfiles.*" %>
0
 
LVL 92

Expert Comment

by:objects
ID: 10795042
what directory is your jsp file in?
0
 

Author Comment

by:Raftor
ID: 10795103
my jsp file is in C:\Project and the java file i want to include is in C:\Project\WEB-INF\classes with the class file in C:\Project\WEB-INF\classes\classfiles
0
 
LVL 92

Expert Comment

by:objects
ID: 10795370
have u restarted tomcat?
0
 

Author Comment

by:Raftor
ID: 10796421
Got it cheers
Raftor.
0
 
LVL 92

Expert Comment

by:objects
ID: 10799278
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A Short Story about the Best File Recovery Software – Acronis True Image 2017
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now