views:

319

answers:

2

I have added native method in java bean code.

Then i have copied .dll file in System32 folder.

while using javabean in JSP.

it gives an Error:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.UnsatisfiedLinkError: BeanDir.mysimplebean.sayHello()Ljava/lang/String;
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

javax.servlet.ServletException: java.lang.UnsatisfiedLinkError: BeanDir.mysimplebean.sayHello()Ljava/lang/String;
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
    org.apache.jsp.jsp.callbean_jsp._jspService(callbean_jsp.java:124)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.UnsatisfiedLinkError: BeanDir.mysimplebean.sayHello()Ljava/lang/String;
    BeanDir.mysimplebean.sayHello(Native Method)
    org.apache.jsp.jsp.callbean_jsp._jspService(callbean_jsp.java:112)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs. Apache Tomcat/6.0.20

Java bean code:

package BeanDir;
import java.util.*;
//This file must be compiled Manually using javac 
//cd D:\tomcat\webapps\examples\WEB-INF\classes\BeanDir\mysimplebean.java
public class mysimplebean 
{
    static
    {
     String s=System.getProperty("java.library.path");
     System.setProperty("java.library.path",s);
     System.loadLibrary("HelloWorld");
    }
    public String getceoname() 
    {   
     String ceonameval = "Tom Hanks CEO of Tom Hanks INC";   
     return ceonameval;
    }  
    public String ceoemail() 
    {   
     String ceoemailval = "[email protected]";   
     return ceoemailval;
    } 
    public double findtakehome(int salary,String designation) 
    {     
     double takehomeamt;
     if(designation=="Developer")
     {
      takehomeamt = salary+salary*0.15; //15 % Raise in Salary
     }
     else
     {
      takehomeamt = salary+salary*0.10; //10 % Raise in Salary
     }
     return takehomeamt;
    }
    public native String sayHello();  
}
A: 

I cant leave a comment, but..

  1. is your servlet container on the same windows machine that the dll is on?
  2. does the System.getProperty("java.library.path") include the system32 folder (from within a jsp)?

the answer to both questions should be 'yes' for this to work

Ryan Fernandes
hi ryan,i used the same .dll(inside system32 folder) for servlet it works fine.And i run the seperate console pgm to find the "java.library.path"it also shows system32 folder .
krishnakumar
You need to do something like:test.jsp:<% out.print("My dll should be somewhere here: "+System.getProperty("java.library.path"));%>
Ryan Fernandes
hi ryan,i tried use the same .dll in another servlet page.It shows an error ".dll loaded in another class loader".So that i m trying to createthe JNI wrapper in Java bean.with that i can create many instance my mentioning its scope attribute as "application" in use bean tag.If you have any suggestion about this let me know.thanks
krishnakumar
A: 

Hi i got the solution for this post.

but not with Java bean.

i writen the JNI wrapper in a class.

and i created the object in JSP program.

krishnakumar