File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes HELP required in my assignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HELP required in my assignment" Watch "HELP required in my assignment" New topic
Author

HELP required in my assignment

mohan gandhi
Greenhorn

Joined: Feb 18, 2001
Posts: 6
Hi Friends,
I'm learning java currently and taking a course on servlets and jsp.I need your help ine of my assignments.
1.I've to write a servlet which displays a list of students and when i click on a student it shows a list of courses that student is taking and list of courses available.
2.In the same page the servlet should have facilities to add or remove a course for a particular student.I did this with sql tables and it worked fine.
I'm asked to hardcode the student list, and the courses list, and the student and course information in the servlet.
I've no idea how to do this ,which type of collections to use for add and delete.how to relate between students and courses.
Your help in this regard is greatly appreciated.
Thanks,
Gandhi
Ajan Balakrishnan
Ranch Hand

Joined: Jan 04, 2001
Posts: 71
I think you can use HashTable by keeping your student Id as the Key and the courses as "value"{courses will be in ArrayList, Vector or a simple String array) . Now you can use the put,remove and get methods to insert, retreive and remove records based on the key. The following example is not complete but will give you a basic idea. I'm using Vector here since i'm a big fan of it.


Let me know if this helps
Ajan


[This message has been edited by Ajan Balakrishnan (edited February 20, 2001).]
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Ajan Balakrishnan:
I think you can use HashTable

The use of the Collection API (HashMap and ArrayList in lieu of HashTable and Vector) will no doubt gain you extra educational kudos.
If you want even more kudos, you wrap your hardwired data in such a way that you can easily exchange it for a database back-end. For example, if you define an interface to retrieve (lists of) your students, courses and whatnot, you can later change your hardwired data implementation for a database-drive implementation without (theoretically) changing anything else.
That may be taking it a step too far, though.
- Peter
mohan gandhi
Greenhorn

Joined: Feb 18, 2001
Posts: 6
thanks a lot friends.I got it.
Mohan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HELP required in my assignment