简单一点,用C写一个Application,由参数或文件得到试题,然后与DLL通讯得到分数,输出到stdout或文件。在JSP里Runtime.getRuntime().exec(...)调用这个Application,是不是就行了?

解决方案 »

  1.   

    简单一点,用C写一个Application,由参数或文件得到试题,然后与DLL通讯得到分数,输出到stdout或文件。在JSP里Runtime.getRuntime().exec(...)调用这个Application,是不是就行了?
    谢谢你给的方案,可是我还是不明白,怎么回事?别人用DELPHI写完了判分程序,已经有一个函数了,在DLL中,我需要调用这个函数,在JSP中
    能不能帮帮忙讲的详细点,先谢谢你了!!
      

  2.   

    假设该DLL输出的函数为double delphiScore(int subject, double test);
    其中subject为试题,test为考试者选择的答案,函数返回得分情况1、在你的C程序中,定义如下函数来调用DLL:
    double getDelphiScore(int subject, double test)
    {
        typedef double (FAR PASCAL *DLL_Interface  )(int subject, double test);//定义接口函数类型
        DLL_Interface   dllInterface;//定义接口函数例程
        double returnValue = -1;//缺省返回值
        HINSTANCE inst  = LoadLibrary("filename.dll");//装载DLL
        if( !inst )     return(returnValue);//装载DLL失败则返回缺省值
        dllInterface    = (DLL_Interface)GetProcAddress(inst,"_delphiScore");//获得待引用的函数地址
        if( dllInterface != NULL )
            returnValue = dllInterface(subject, test);//引用函数
        FreeLibrary(inst);//释放
        return(returnValue);//返回
    }在你的C程序的main函数中,从命令行获得subject及test的值,调用上述函数,将返回值printf出来。2、在JSP中
    String strSubject = request.getParameter("Subject");
    String strTest = request.getParameter("Test");String cmdLine = "c.exe " + strSubject + " " + strText;//将试题及答案作为命令行参数传给c.exe
    Process cmd = Runtime.getRuntime().exec(cmdLine);//运行c.exe
    BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(cmd.getInputStream()), 4096);//获得c.exe的输出流
    String stringLine;
    while((stringLine = bufferedReader.readLine()) != null) {//读c.exe的输出
        out.println(stringLine);//将c.exe的输出打印到页面
    }ok!
      

  3.   

    利用JNI做不过这个工作很多人做过了这个目前做的不错:http://danadler.com/jacob/拿来直接用好了,而且是开源的,你有兴趣可以研究一下代码