• Post Reply Bookmark Topic Watch Topic
  • New Topic

create object within jsp

 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First of all this is a great forum - very motivating and informative for a newbie like me.
I have a basic ques. regarding j2ee which is:

I have a class file which works fine when I run it using j2sdk. Let's say for now its a simple class like this in Simple1.java/.class:

public class Simple1 {
public boolean go(){
return true;
}
}

Now I want to call the go method of this class via the web on the click of a form submit.
What I did was put the Simple1.class file in the WEB-INF/classes folder
and created a jsp page say test1.jsp which was like this:

<html>
<body>

something here

<%
Simple1 sg = new Simple1();
%>

</body>
</html>

Now, the problem is I get an error saying that Simple1 class not found.
Am I doing something wrong here ?

I understand a good way to do this is call a servlet which then creates the class object but this is how I want to try for now... create object within the jsp itself.
How do I achieve this ?
Regarding web/application servers, I tried this on apache-tomcat aswell as oc4j... but can't get it to work.

Thanks!
[ October 19, 2005: Message edited by: Bear Bibeault ]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting the class in a package and then use the full name when you are trying to reference it.

Once that is working you can then try to use it as a bean with appropriate getter/setter. You will also need the usebean tag in your JSP.
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bosun,

Thanks a lot!
The package tip you gave made it to work.
Tks again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!