Problem with jsp

Hi,

I am doing templates. I was hard coded one class value by the name Student. Instead of hard coding this class name i need to pass this class name from other jsp page.Is it possible in a jsp.

<% String s = ((Student)l.get(u)).getRoleCode(); %>

Student is a bean object with setters and getters.

Regards,

ahmed

[358 byte] By [ahamad15a] at [2007-11-26 15:46:52]
# 1

it sounds like you are conditionally trying to cast an object, so sometimes it will be a student, sometimes it will be something else, like a teacher.

it sounds like what you actually need is an abstract class that student or teacher extend.

so you will have

public abstract class SchoolPerson {}

public class Student extends SchoolPerson {}

public class Teacher extends SchoolPerson {}

so, you put your common fields in the SchoolPerson abstract class. e.g. roleCode could go in here with a getter and setter.

when you instantiate your bean, which will be an instance of student or taecher, you have it set the correct properties in the super class (by calling super in the constructor).

now you dont need to ****** around with casting objects because both objects are of the same type.

TimSparqa at 2007-7-8 22:06:16 > top of Java-index,Java Essentials,Java Programming...
# 2

> i need to pass this class name from

> other jsp page.Is it possible in a jsp.

>

> <% String s = ((Student)l.get(u)).getRoleCode(); %>

>

> Student is a bean object with setters and getters.

If I understand the question, you should store the bean in one of these scopes, depending on your needs:

- Request

- Session

- Application

And typically by using the [url=http://java.sun.com/products/jsp/tags/11/syntaxref11.fm14.html]<jsp:useBean/>[/url] tag.

karma-9a at 2007-7-8 22:06:17 > top of Java-index,Java Essentials,Java Programming...