gpt4 book ai didi

java - 使用 JSTL 库标签从 JSP 调用 Java 类

转载 作者:行者123 更新时间:2023-12-01 06:13:31 25 4
gpt4 key购买 nike

我有运行良好的 MyCpu java 类,我需要将输出显示到网页中我尝试过仅使用 JSP,但它不起作用,然后我添加了 JSTL 标记库并添加了此代码 -Djava.library .path="./lib"到 MANIFEST.MF我还使用 Sigar API 并将其添加到库中,然后出现以下错误:

java.lang.UnsatisfiedLinkError: org.hyperic.sigar.Sigar.getCpuInfoList()[Lorg/hyperic/sigar/CpuInfo;

请问有什么帮助或建议吗?

package mydata;

import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;

public class MyCpu {
private String cpuInfoList;
public String getCpuInfoList(){
return this.cpuInfoList;
}
public MyCpu() {
Sigar sigar = new Sigar();
String output = " ";
CpuInfo[] cpuInfoList = null;
try {

cpuInfoList = sigar.getCpuInfoList();
} catch (SigarException e) {
e.printStackTrace();
return;
}
for (CpuInfo info : cpuInfoList) {
output += "Vendor: " + info.getVendor() + "\n";
output += "Model: " + info.getModel() + "";
output += "DD:" +info.toString()+ "";
}
System.out.println(output);
}
public static void main(String[] args) {
MyCpu main = new MyCpu();
}
}
----------------------------------------------------------------------------------
<%@page import="mydata.MyCpu"%>
<%@page import ="org.hyperic.sigar.Sigar"%>
<%@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>
<h1>Hello World!</h1>

<%
MyCpu cpu = new MyCpu();
Sigar sigar = new Sigar();

out.println(sigar.getCpuInfoList()[4]);
%>
</body>
</html>

最佳答案

尝试将其添加为 JVM 参数

    -Djava.library.path="./lib"

关于java - 使用 JSTL 库标签从 JSP 调用 Java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30054531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com