Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help for JSP to call C API using JNI

 
Bill Ngu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

Sorry, not sure if this the right forum to post this question..

I need to use C API in my JSP. I have a class file which define all the native method and load the C API in public class MyClass like this:-

public native static byte[] myMethod();

static
{
System.loadLibrary("mycompanycapi");
}

I had compiled this class and the .h file and put it in my webapps/ROOT/WEB-INF/classes/com/mycompany folder under tomcat.

The libmycompanycapi.so I put it under /lib and I call this class in jsp like this:-

<jsp:useBean id="MyClass" class="MyClass" scope="request">
</jsp:useBean>

But, when the jsp give me the following error:-

exception

org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:591)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:137)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause

java.lang.ClassNotFoundException: org.apache.jsp.test_005fbank_jsp
java.net.URLClassLoader$1.run(URLClassLoader.java:199)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:187)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:158)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:71)
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:137)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Can anyone help and advise what is the possible problem to this? Thanks.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the JSP works if you remove the call to the bean?
 
Bill Ngu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, if I remove the call to the useBean it mean I have to remove all the call to API.

Yup, my jsp work without JNI calling. I had tested with normal useBean, it working too.. so I suppose it is the JNI call that I am having problem.

Can you point me to a step by step guide on how to use an C API in JSP for Tomcat? Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic