Hi :-/

I have a java function that I want to call inside my JSP page. My function has got parameters.Now the problem is I cannot call it using JavaScript and if I put it inside <% %> tags it just executes while loading the webpage itself. I need to call my java function with a button.

Would appreciate some guidance :)

Thanks

Recommended Answers

First you need to create a page with .java extension and place this page in java resources folder.
For example:

public class Test 
{
public void printHello()
{
System.out.println("Hello world!");
}
}

And call this function in jsp like:

<%
if(request.getParameter("submit") != null)
{ …
Jump to Post

All 3 Replies

First you need to create a page with .java extension and place this page in java resources folder.
For example:

public class Test 
{
public void printHello()
{
System.out.println("Hello world!");
}
}

And call this function in jsp like:

<%
if(request.getParameter("submit") != null)
{
Test t= new Test();
t.printHello();
}
%>

All the best...

Thanks Shanti .... It really helped. Why didn't I think that ... lol.
Perhaps because I am new to JSP.

Thanks

what about this type of function

public void printHello()
{
for (int i=0; i<=5;i++)
System.out.println("i="+1);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.