0

This is the code I have put up in my jsp page just to test if it works or not correctly. The jsp page works fine without any use of opencv classes. But I got this error while using objects of the opencv library.

<%@ 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>

Attaching the error page for the details: enter image description here

The error code is :

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)
Ondrej Skopek
  • 778
  • 10
  • 27
kirtan403
  • 7,293
  • 6
  • 54
  • 97

1 Answers1

1

The unsatisfied link error is telling you, that there was no library with such a name found. See here: OpenCV + Java = UnsatisfiedLinkError.

On a side note, you really shouldn't be using code inside JSPs. Create a Servlet that does what you want with the image, add it's path/URL as an attribute request.setAttribute("key", "value").

Use a RequestDispatcher:

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

to forward the request and response to the JSP. You can then reference it there with ${key}.

Community
  • 1
  • 1
Ondrej Skopek
  • 778
  • 10
  • 27
  • Thanks for the answer @oskopek .. Can I know the reason why i shouldn't use code inside jsp? I searched a lot but also didn't find anything with jsp and opencv ? why ? – kirtan403 Jan 09 '14 at 20:58
  • So called scriptlets are deprecated since taglibs appeared. They are tough to work with: non-reusable code, painful debugging and the html gets messy. See Oracle's [Code conventions for JSP](http://www.oracle.com/technetwork/articles/javase/code-convention-138726.html). Also, [this answer](http://stackoverflow.com/a/3180202/2713162) sums it up very nicely. – Ondrej Skopek Jan 09 '14 at 21:21
  • Regarding OpenCV and JSPs: You didn't find anything, because they don't have anything in common. JSPs could be used for displaying the result of OpenCV's operations in the background. If you want to transform an image on the server using OpenCV that's fine, but you should do it in a server-side POJO and display the result as you would a regular image using a JSP. For example: Say a client connects to your server, visits a JSP, uploads an image. You then store/transform the image server-side, and let him have the result by forwarding him to another JSP using a Servlet. – Ondrej Skopek Jan 09 '14 at 21:28
  • I have done what you have suggested. It worked one time and now it giving me an error ClassDefNotFoundError .. Finding for the whole day but couldn't find any solution. – kirtan403 Jan 10 '14 at 15:32
  • Could you post your code and stacktrace somewhere, and paste a link here? – Ondrej Skopek Jan 10 '14 at 18:53