JavaBean调用dll问题
大家好,首先谢谢你能关注该帖子,我现在遇到一个大问题需请求大家
我写了一个C++的dll,名称是Java2Com.dll,包含JavaBridgeCom.h和Java2Com.cpp两个文件,JavaBridgeCom.h是由JavaBridgeCom.java生成的jni头文件
======================================
JavaBridgeCom.h源代码如下:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JavaBridgeCom */
#ifndef _Included_JavaBridgeCom
#define _Included_JavaBridgeCom
#ifdef __cplusplus
extern "C " {
#endif
/*
* Class: JavaBridgeCom
* Method: Encode
* Signature: (Ljava/lang/String;JIZLjava/lang/String;I)I
, jstring, jlong, jint, jboolean, jstring, jint
*/
JNIEXPORT jint JNICALL Java_JavaBridgeCom_Encode
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
=============================================
Java2Com.cpp源代码如下:
#include "JavaBridgeCom.h "
#include <windows.h>
//, jstring, jlong, jint, jboolean, jstring, jint
JNIEXPORT jint JNICALL Java_JavaBridgeCom_Encode
(JNIEnv *, jclass)
{
printf( "inter JavaCOM success!\n ");
MessageBox(NULL, "Method05(INT intPro) Help, 你好xxxxxx ", "提示信息 ", MB_OK);
return 0;
}
=============================================
然后我写了一个java类(名称是JavaBridgeCom.java)调用Java2Com.dll
代码如下:
public class JavaBridgeCom {
static {
System.loadLibrary( "Java2Com ");
}
public native static int Encode();
public static void main(String[] args) {
int c_return_one;
JavaBridgeCom xiang = new JavaBridgeCom();
c_return_one = xiang.Encode();
}
调用成功!!!!
=========================
在JavaBean调用Java2Com.dll就不行,调研方式是Jsp通过JavaBean调用Java2Com.dll
JavaBean名称为:JavaBridgeComBean.java
package bean;
import java.io.*;
import java.lang.String;
public class JavaBridgeComBean
{
public JavaBridgeCom(){}
private static JavaBridgeComBean javabridgecom;
static
{
System.loadLibrary( "Java2Com ");
}
public native static int Encode();
public void InvokeCEncode()
{
int c_return_one;
javabridgecom = new JavaBridgeComBean();
c_return_one = javabridgecom.Encode();
}
}
=============================================
然后我写了一个Jsp页面调用这个JavaBean即JavaBridgeComBean.java
JspInvokeBean.jsp页面源代码如下:
<%@ page contentType= "text/html;charset=UTF-8 " %>
<jsp:useBean id= "bean " scope= "page " class= "bean.JavaBridgeComBean "/>
<html>
<head>
<title> Invoke JavaBridgeComBean </title>
</head>
<table> <tr>
<td>
how do you do!\n oh yeah!\n
<%
bean.InvokeCEncode();
%>
</td>
</tr> </table>
</html>
启动JspInvokeBean.jsp页面,出现大量提示,如下
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Encode
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
......
root cause
javax.servlet.ServletException: Encode
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
at org.apache.jsp.default_on3_jsp._jspService(default_on3_jsp.java:90)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
......
=========================================
哪位大虾能说说原因么,在javabean了通过Jni是不是不能访问C++的dll啊
注: 我用的web Server是Jobss,动态库Java2Com.dll放在系统的system32下
JavaBridgeComBean.java放在WEB-INF\classes下
[解决办法]
路过,帮顶
[解决办法]
帮你看一下
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html