i have a java application which have some open APIs. i want to use those APIs from jsp page. i don't have any idea about this.As of now my understanding is i have to get the instance of running java application.
please correct me if i am wrong.
i have a java application which have some open APIs. i want to use those APIs from jsp page. i don't have any idea about this.As of now my understanding is i have to get the instance of running java application.
please correct me if i am wrong.
You have to import the class at the top of the JSP
<%@ page import="my.class.path.MyClass" %>
see How do you import classes in JSP? for details.
Then you can use that class in your Code like this:
<% MyClass myClassInstance = new MyClass();
myClassInstance.myMethod();
%>
If you want to output something you can use:
<%= myClassInstance.aMethodThatReturnsAString() %>
The method can return anything (but must return something). If its not a String
then it will be handled like any other non-String Value in this expression:
"Begin " + aMethodThatReturnsSomething() + " End";
So, an int
is displayed like an int
, an Object gets its toString()
called etc.
If above two assumptions are correct then you can call API of that java application by putting it in class path of your application server running jsp and then including it in your jsp.
Now assuming that you want to get some in memory data from your running java application.
The bottom line is , if you can provide some more specific use case details, which java application, what kind of API etc people can help you better
To get the instance of java application through jsp
use following simple steps:
import java clas as
<%@ page import="classPath.className" %>
Create Object of class
and use its method and variable
as
<%
Mycalss test = new Myclass();
test.sum();
%>