cancel
Showing results for 
Search instead for 
Did you mean: 

URGENT! How to call a java class from JSP.

Former Member
0 Kudos

Hi all,

I am a novice in java.

I am working on a synchronous scenario .I am working on NWDS. i have developed a web module project in the same i have generated a java class which calls a webservice(suggestions as to how a java class can send a request to a webservice and obtain response from the same are welcome)

I hav developed a jsp and i want to know how i can call the method implemented in my java class. i dont need to pass any parameters to my java class test.java .I just need to call it on the click of a button and i need to view the response from the webservice on the JSP.

please suggest how this can be achieved.

thanks in advance.

.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi ,

Here is the solution .

<%@ page import="package.class"%>

and then inside instantiate an object

<%

MyClass mc = new MyClass(parameters if any);

mc.theMethodYouWantToCall();

%>

or

use the JSP tags

<jsp:useBean id="anyname" class="classname"/>

and use get property tag .

Or Use Custome tags .

Regards ,

venkat

Former Member
0 Kudos

Hello,

It's easy.

Put your class (or classes) into the WEB-INF/classes folder. If you are using NetWeaver Developer Studio, just drop it there. Then you can call your class and its methods from the JSP as follow (let's assume your fully qualified class name is org.acme.common.Tool):


<%@page import="org.acme.common.*"%>
...
<%
Tool t = new Tool();
t.doSomething();
%>
...

If you need to call it on a button click, then you might use a port/get parameter for this purpose. For example:


<%@page import="org.acme.common.*"%>
...
<%
// check if the parameter "clickMe" has value "please",
// i.e. if the form was submitted
if ("please".equals(request.getParameter("clickMe"))) {
  Tool t = new Tool();
  t.doSomething();
}

%>
...

<form method="POST">
<input type="hidden" name="clickMe" value="please">
<input type="submit" value="Go!">
</form>
...

Is that what you need?

Kind regards,

Tsvetomir