Basic JSP question

Hi,

I'm starting to use JSP, and I have a few basic questions. I've found some tutorials online, such as the J2EE tutorial, and some others through Google, that have been helpful. However, after reading some tutorials, I still have a basic question:

If I have a Java class file, can I access that class' methods through my web page using JSP, and then retrieve information from that class?

For example, if I have a class MyClass, a method myMethod, and an ArrayList<String> arr, would I be able to do something like this from my web page?

MyClass.myMethod();

MyClass.arr.get(0);

If anyone can give me some advice, or possibly link me to a tutorial that will explain this, I will be very appreciative.

[752 byte] By [Djaunla] at [2007-11-26 16:20:07]
# 1

Yes you can, here is a quick example of how you could do that.

<%@ page language="java" contentType="text/html"

pageEncoding="ISO-8859-1"%>

<jsp:useBean id="myObject" scope="session" class="mypackage.MyClass" />

<html>

<body>

<%

myObject.myMethod();

%>

<%= myObject.arr.get(0) %>

</body>

</html>

aaa-mana at 2007-7-8 22:43:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Ah I see, that's where jsp:useBean comes into play. Thanks a lot for the example. Is there any tutorial that can elaborate on this?
Djaunla at 2007-7-8 22:43:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
The J2EE tutorial is probably the one I would use. Here is a direct link to the JSP topic in the 1.4 J2EE tutorial, http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro.html#wp100465Good luck :)
aaa-mana at 2007-7-8 22:43:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Alright I'll read through that some more. Thanks a lot for the help.
Djaunla at 2007-7-8 22:43:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...