• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error calling a native method in Java bean

 
krish rajini
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}

I added native method sayHello() in Java bean.

While using it in JSP

the code is

<%@ page import = "BeanDir.mysimplebean" %>

<jsp:useBean
id="mybeanid"
class="BeanDir.mysimplebean"
scope="session"/>

<jsp:setProperty
name="mybeanid"
property="*"/>

<html>
<head><title>JSP - Java Bean Demo : James Smith : </title></head>
<body bgcolor="white">

<center><strong>Simple JSP with JAVA Beans Demo Application Form</strong>

<%
//Auto Compiled by JSP Engine dont use Javac
//No Parameters Passed into Bean
//cd E:/tomcat/webapps/examples/jsp/testdir/testme2.jsp

String ceoname_ret;
ceoname_ret=mybeanid.getceoname();
out.println("<br>CEO Name : "+ceoname_ret);

//No Parameters Passed into Bean
String ceoemail_ret;
ceoemail_ret=mybeanid.ceoemail();
out.println("<br>CEO Email : "+ceoemail_ret);

out.println("<br><br>");
out.println("<table border=1 bordercolor='maroon' cellspacing=4 cellpadding=4 align=center>");
out.println("<tr align=center valign=middle>");
out.println("<td bgcolor=maroon><font face='verdana' size=2 color=white> Calling From JSP </font></td>");
out.println("<td bgcolor=maroon><font face='verdana' size=2 color=white> BEAN BEANING CALLED </font></td></tr>");
double takehomeamt_ret;
double totalcost=0;
takehomeamt_ret = mybeanid.findtakehome(5000,"Developer") ;
totalcost=totalcost+takehomeamt_ret;
out.println("<tr align=center valign=middle><td><font face='verdana' size=2>Take Home : James Smith </font></td>");
out.println("<td><font face='verdana' size=2>"+takehomeamt_ret+"</font></td></tr>");

takehomeamt_ret = mybeanid.findtakehome(5000,"Designer") ;
totalcost=totalcost+takehomeamt_ret;
out.println("<tr align=center valign=middle><td><font face='verdana' size=2>Take Home : Andrew </font></td>");
out.println("<td> <font face='verdana' size=2>"+takehomeamt_ret+"</font></td></tr>");

takehomeamt_ret = mybeanid.findtakehome(7000,"Developer") ;
totalcost=totalcost+takehomeamt_ret;
out.println("<tr align=center valign=middle><td><font face='verdana' size=2>Take Home : Peter O Neal </font></td>");
out.println("<td> <font face='verdana' size=2>"+takehomeamt_ret+"</font></td></tr>");
out.println("<tr align=center valign=middle><td><font face='verdana' size=2><strong>TOTAL COST FOR COMPANY </strong> </font></td>");
out.println("<td> <font face='verdana' size=2>"+totalcost+"</font></td></tr>");
out.println("</table>");
String s=mybeanid.sayHello();
out.println("<h1>"+s+"</h1>");
%> </center>

</body>
</html>


The error which i am getting is :
====================

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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!