Solved

arrays in jsp

Posted on 2004-04-08
15
269 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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
 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jason format for rest webservices and sub resourcing 1 89
Jquery - parsing the results returned from webmethod 1 112
report generation frameworks 1 64
lessBy10  challenge 15 95
Data breaches are on the rise, and companies are preparing by boosting their cybersecurity budgets. According to the Cybersecurity Market Report (http://www.cybersecurityventures.com/cybersecurity-market-report), worldwide spending on cybersecurity …
This problem is more common than not and I will show you some things to check to solve this problem.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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