我在 java bean 代码中添加了本地方法。
然后我在 System32 文件夹中复制了 .dll 文件。
在 JSP 中使用 javabean 时。
它给出了一个错误:
HTTP 状态 500 -
类型异常报告
信息
描述 服务器遇到一个内部错误 () 阻止它完成这个请求。
例外
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)
根本原因
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)
根本原因
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 Apache Tomcat/6.0.20 日志中提供了根本原因的完整堆栈跟踪。Apache Tomcat/6.0.20
Java bean 代码:
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 = "tom@tomhanksinc.com";
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();
}