如何在jsp代码中导入java库?
我有以下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);
}
%>
I have the following jsp code. I want to add libraries such as java.io.
How can I do this?
<% @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);
}
%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你几乎是对的,但你需要关闭导入标签,如下所示:
要声明多个导入,你可以复制整个标签,如下所示:
或使用逗号分隔的列表:
不过,出于多种原因,我会不建议将 Java 代码混合到 JSP 中。
You are almost right, but you need to close the import tag, like this:
To declare multiple imports you can either duplicate that entire tag, like so:
or use a comma-separated list:
For a multitude of reasons, though, I would not recommend mixing java code into your JSPs.