用servlet實現jnative調用c++寫的dll的例子

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();
  }
 }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章