Java by API/javax.naming/Binding — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
Binding: getClassName()
import java.io.IOException;
import java.io.PrintWriter;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EnvEntry extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
try {
Context initCtx = new InitialContext();
NamingEnumeration e = initCtx.listBindings("java:comp/env");
while (e.hasMore()) {
Binding binding = (Binding) e.next();
out.println("Name: " + binding.getName());
out.println("Type: " + binding.getClassName());
out.println("Value: " + binding.getObject());
out.println();
}
} catch (NamingException e) {
e.printStackTrace(out);
}
}
}
Binding: getObject()
import java.io.IOException;
import java.io.PrintWriter;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EnvEntry extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
try {
Context initCtx = new InitialContext();
NamingEnumeration e = initCtx.listBindings("java:comp/env");
while (e.hasMore()) {
Binding binding = (Binding) e.next();
out.println("Name: " + binding.getName());
out.println("Type: " + binding.getClassName());
out.println("Value: " + binding.getObject());
out.println();
}
} catch (NamingException e) {
e.printStackTrace(out);
}
}
}