使用JSP

时间:2015-05-02 10:39:03

标签: java jsp

大家好我想在网页(如jsp)中显示MyMem类的输出,我以此错误消息结束

输入例外报告

消息

description服务器遇到内部错误(),导致无法完成此请求。

例外 java.lang.UnsatisfiedLinkError:org.hyperic.sigar.Mem.gather(Lorg / hyperic / sigar / Sigar;)V

注意GlassFish Server Open Source Edition 3。0。1日志中提供了异常的完整堆栈跟踪及其根本原因。

任何帮助?任何想法!

<%@page import="org.hyperic.sigar.Sigar"%>
<%@page import="org.hyperic.sigar.Mem"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
       <%@page import="mydata.*"%>
        <h1>Monitoring CPU</h1>
       
<%
Sigar sigar=new Sigar();
//MyMem mem = new MyMem();
Mem mem = null;
mem = sigar.getMem();
 System.out.println(mem.getFree());
 System.out.println(mem.getUsed());
 System.out.println(mem.getActualFree());
 System.out.println(mem.getActualUsed());
 System.out.println(mem.getTotal());
 System.out.println(mem.getUsed());
%>
    </body>
</html>

package mydata;
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import org.hyperic.sigar.Mem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;

public class MyMem {

    private static Sigar sigar = new Sigar();

    public static void getInformationsAboutMemory() {
        System.out.println("**************************************");
        System.out.println("*** Informations about the Memory: ***");
        System.out.println("**************************************\n");

        Mem mem = null;
        try {
            mem = sigar.getMem();
        } catch (SigarException se) {
            se.printStackTrace();
        }

        System.out.println("Actual total free system memory: "
                + mem.getActualFree() / 1024 / 1024+ " MB");
        System.out.println("Actual total used system memory: "
                + mem.getActualUsed() / 1024 / 1024 + " MB");
        System.out.println("Total free system memory ......: " + mem.getFree()
                / 1024 / 1024+ " MB");
        System.out.println("System Random Access Memory....: " + mem.getRam()
                + " MB");
        System.out.println("Total system memory............: " + mem.getTotal()
                / 1024 / 1024+ " MB");
        System.out.println("Total used system memory.......: " + mem.getUsed()
                / 1024 / 1024+ " MB");

        System.out.println("\n**************************************\n");


    }

    public static void main(String[] args) throws Exception{

                getInformationsAboutMemory();

                }

}

1 个答案:

答案 0 :(得分:0)

AFAIK Sigar API通过JNI工作,您需要将sigar-bin \ lib的内容复制到PATH

如果要在网页中显示输出,则应使用out.println(mem.getFree())或scriptlet <%= mem.getFree() %>代替System.out.pritnln()

System.out.println()写入servlet容器控制台(或服务器日志)。

您要显示的信息应存储在对象的字段中,您的对象应提供getter方法。