Solved

arrays in jsp

Posted on 2004-04-08
15
266 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stuck in Bootstrap WysiHtml Editor 3 37
console vs log file 16 77
countXY challenge 28 144
equalIsNot  challenge 43 132
Facing problems with you memory card? Cannot access your memory card? All stored data, images, videos are lost? If these are your questions...than this small article might help you out in retrieving your lost or inaccessible data.
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

939 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

10 Experts available now in Live!

Get 1:1 Help Now