Hi!

I have a servlet that calls a native function (written in C++ that
generates sum of first n fibonacci numbers, n being the input
parameter). The servlet is called upon submission of .shtml file. I get
"500 Internal Server Error" when the form is submitted. The code for the
servlet and native function is given below.

------------- Native.java --------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;


public class Native extends HttpServlet implements
javax.servlet.SingleThreadModel
{

    //public native void test();
    public native int fibonacci(int n);


  public void init(ServletConfig config) throws ServletException
 {
    super.init(config);
  }

  public void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException,   ServletException
  {
 doPost(request, response);
  }


  public void doPost(HttpServletRequest request, HttpServletResponse
response) throws IOException,  ServletException
   {
   System.out.println("Before native function");
   System.loadLibrary("test2");
   System.out.println("After loadLibrary"); //--> Till here, it's fine
   int number=5;
   int result=fibonacci(number); //--> Some problem here
   System.out.println("Result: "+result);
   //System.loadLibrary("Test2");

   System.out.println("After native function");
    }
}

------------- Native.java --------------

------------- try1.shtml --------------


<html>
<head>
<script language=JavaScript>
<!--
function btnSubmitOnClick()
{
 //alert("Hello")
 document.frmTest.action="servlet/Native"
 document.frmTest.submit()
}
//-->
</script>
</head>
<body>
<form name=frmTest method=post>
<input type=submit value=Submit OnClick="return btnSubmitOnClick()">
</form>
</body>
</html>

------------- try1.shtml --------------


------------- test2.cpp --------------

// test2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "jni.h"
#include "Native.h"

/* int main(int argc, char* argv[])
{
 printf("Hello World!\n");
 return 0;
} */

int fibo(int n)
{
 if(n <= 1) return 0;
 if(n == 2) return 1;
 return fibo(n - 1) + fibo(n - 2);
}

JNIEXPORT jint JNICALL Java_Native_fibonacci(JNIEnv *env, jobject obj,
jint n)
{
 printf("Inside JNI function");
 return fibo(n);
}

------------- test2.cpp --------------
Can someone track where the problem lies?
Regards,
Manish

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to