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);
}
%>
Full Stack Java developer - Java + JSP + Restful WS + SpringThe import attribute serves the same function as and behaves like, the Java import statement. The value for the import option is the name of the package you want to import. By default, a container automatically imports java. lang.
Built-in Packages The library is divided into packages and classes. Meaning you can either import a single class (along with its methods and attributes), or a whole package that contain all the classes that belong to the specified package.
JSP Scriptlet tag (Scripting elements) In JSP, java code can be written inside the jsp page using the scriptlet tag.
1)import. The import attribute is used to import class,interface or all the members of a package.It is similar to import keyword in java class or interface.
You are almost right, but you need to close the import tag, like this:
<%@ page import="java.io.BufferedReader" %>
To declare multiple imports you can either duplicate that entire tag, like so:
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %>
or use a comma-separated list:
<%@ page import="java.io.BufferedReader,java.io.InputStreamReader" %>
For a multitude of reasons, though, I would not recommend mixing java code into your JSPs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With