Hi! I let my servlet call a C function with JNI. Below is my code:
//////////////////////////////////////////////////////////////////////
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public
class NativeHelloWorldServlet extends HttpServlet
{
public void init(ServletConfig servletConfig) throws
ServletException
{
super.init(servletConfig);
try {
System.loadLibrary("NativeHelloWorld");
} catch(Exception e) {
System.err.println("error1");
return;
} catch(Throwable e) {
System.err.println("error2");
return;
}
System.err.println("Successfully loaded DLL");
}
public native String nativeHelloMethod();
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
System.err.println("Still working");
out.println(nativeHelloMethod()); //call the native method
System.err.println("Finished");
}
}
//////////////////////////////////////////////////////////////////////
In the log file, it can print out:
"Successfully loaded DLL
Still working"
But it cannot print out "Finished" and the servlet be loaded in a
browser.
That means out.println(nativeHelloMethod()) terminate the code
abnormally. Actually, if I use usual java code instead of servlet, to
call the C function, everything works. So can anyone help me?
Thank you!
--
Xizhen
https://www.alladvantage.com/home.asp?refid=ANI887
https://secure.paypal.com/refer/pal=delate%40hotmail.com
___________________________________________________________________________
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