嘿伙计们,怎么了?我在jsp上有以下代码。我想添加java.io等库。我可以这样做吗?先谢谢
<% @page import=java.io.BufferedReader;
@page import=java.io.IOException;
@page import=java.io.InputStreamReader;
String IP=request.getParameter("IP");
String res="";
Runtime run = Runtime.getRuntime();
Process pr = run.exec("snmpget -v 2c -c public "+IP+" SNMPv2-MIB::sysUpTime.0");
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
//String res="";
while ((line = buf.readLine()) != null)
{
res+=line+"\n";
}
int i=res.indexOf(")");
// System.out.println(i);
res=res.substring(i+1).trim();
//System.out.print(res);
} catch (InterruptedException ex)
{
Logger.getLogger(myMain.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IOException ex) {
Logger.getLogger(myMain.class.getName()).log(Level.SEVERE, null, ex);
}
%>
答案 0 :(得分:19)
你几乎是对的,但你需要关闭导入标签,如下所示:
<%@ page import="java.io.BufferedReader" %>
要声明多个导入,您可以复制整个标记,如下所示:
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %>
或使用以逗号分隔的列表:
<%@ page import="java.io.BufferedReader,java.io.InputStreamReader" %>
出于多种原因,我不建议将Java代码混合到JSP中。