使用openCV和jsp会导致UnsatisfiedLinkError?

时间:2014-01-09 20:11:00

标签: java jsp opencv

这是我在jsp页面中提供的代码,只是为了测试它是否正常工作。 jsp页面工作正常,没有使用opencv类。 但是在使用opencv库的对象时出现了这个错误。

<%@ page import="org.opencv.core.*" %>
<%@ page import="org.opencv.highgui.Highgui" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Title</title>
</head>
<body>
<%
System.loadLibrary("opencv_java248");
Mat img = Highgui.imread("F:/project/im2.jpg");
%>

</body>
</html>

附加错误页面以获取详细信息: enter image description here

错误代码是:

Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:442)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause 
javax.servlet.ServletException: java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_1(Ljava/lang/String;)J
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
    org.apache.jsp.first_jsp._jspService(first_jsp.java:79)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause 
java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_1(Ljava/lang/String;)J
    org.opencv.highgui.Highgui.imread_1(Native Method)
    org.opencv.highgui.Highgui.imread(Highgui.java:359)
    org.apache.jsp.first_jsp._jspService(first_jsp.java:68)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

1 个答案:

答案 0 :(得分:1)

未满足的链接错误告诉您,找不到具有此类名称的库。 见这里:OpenCV + Java = UnsatisfiedLinkError

另一方面,您确实不应该在JSP中使用代码。创建一个对图像执行所需操作的Servlet,将其路径/ URL添加为属性request.setAttribute("key", "value")

使用RequestDispatcher

getServletContext().getRequestDispatcher("/path/to/page.jsp").forward(request, response)

将请求和响应转发给JSP。然后,您可以使用${key}引用它。