用servlet实现jnative调用c++写的dll的例子

来源:互联网 发布:c trek数据 编辑:程序博客网 时间:2024/06/06 09:06

public void service(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  response.setContentType("text/HTML");
  JNative n = null;
  int result = 0;
  try {
   n = new JNative("dllCall", "add");  //创建并初始化一个jnative对象(dll,方法)
   n.setRetVal(Type.INT);  //设置返回值的类型
   int i=0;
   n.setParameter(i++, 2);//设置参数值
   n.setParameter(i++, 3);
   n.invoke();  //调用dll方法
   result = Integer.parseInt(n.getRetVal());//获取返回值
   System.out.println(result);
   PrintWriter out = response.getWriter();
   out.write("<h1>"+result+"<h1>");//输出到jsp页面
   out.close();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

原创粉丝点击