How can i use Factpry method in my JSP??

Joined
Dec 11, 2007
Messages
2
Reaction score
0
Hi all, this is my first post and i don't speak english very well...excuse me for that. And i am a novice of JSP / JAVA :-(

I have created in my Java application a Factory Method ( example with 2 different class):

interface Interf {

public void myfunction(); }

class Class1 / Class2 implements Interf {
public void myfunction() { ...... }
}

abstract class FactoryObj {
abstract Interf createobj();
}

class FactoryClass1 extends FactoryObj {
Interf createobj() { return (Interf) new Class1(); }
}
class FactoryClass2 extends FactoryObj {
Interf createobj() { return (Interf} new Class2(); }
}

And in my java application i can use this linecode for execute the myfunction of CLass1.....
FactoryObj a = new FactoryClass1();
Interf o = a.createobj();
o.myfunction();

Now i must add all this factory method in my EXAMPLE.JSP. After that i import the page Project.Factory when i have all the code that i have posted , and i make
<% FactoryObj a = new FacotryCLass1(); %> i can see the error :
FactoryObj cannot be resolved to a type ( maybe because is a static object...) and cannot execute le myfunction() :-( :-( :-(

Anyone can help me??? Maybe i must use another implementation of Factory without an abstract class....
Thank, Andrea
 
Joined
Dec 11, 2007
Messages
2
Reaction score
0
I have create another implementation of factory with the prototype version but the problem is the same....now i no have an abstract class but i dont' try to load in my JSP page this architecture...

NEW VERSION:

Interface Interf {

public void myfunction(); }

class Class1 / Class2 implements Interf {
public void myfunction() { ...... }
}

class FactoryObj {
Interf createobj ( String classname ) {
Class c = Class.forname(classname);
return /Interf)c.newistance();
}
}

And in my java application i can use this linecode for execute the myfunction of CLass1.....
Interf a = new FactoryObj().createobj("Class1");
a.myfunction();

TESTED WITH NETBEANS and run correctly.....this times there's not abstract class...

In a WEB-APPS folder ( for example Myfolder ) of my web application i have a file factory.java and i must insert all this code here but i don't known in which manner.....
In JSP if i use <% page import="Myfolder.factory" %> i cannot use the command Interf a = new FactoryObj etc.. etc.. because don't see nothing...
Maybe i must use other directives or i must put all these classes in the class factory of Myfolder.factory.java....
I no have idea please anyone can help me???
Thank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top